Zabbix 5.0 LTS版本的安装小结

 

1:准备Zabbix的服务器。

这里可能需要一台或多台服务器,视需求和资源而定。也可以将Zabbix_Server、MySQL、Zabbix Web等安装在同一台服务器上。

这里我们打算安装在一台测试服务器上。操作系统版本为CentOS Linux release 8.2.2004 (Core)。

环境要求

Zabbix 5.0 版本对基础环境的要求有大的变化,最大的就是对 php 版本的要求,最低要求 7.2.0 版本,对 php 扩展组件版本也有要求,详见官网文档https://www.zabbix.com/documentation/current/manual/installation/requirements。 这里有对硬件资源、操作系统、数据库版本等相关的规范要求。

2:关闭SELINXU

如果想关闭SeLinux,又不想重启服务器,那么使用下面命令。但是该命令只能将SeLinux在enforcing、permissive这两种模式之间切换.服务器重启后,又会恢复到/etc/selinux/config下的设置,也就是说setenforce的修改是不能持久的。

# setenforce 0

# getenforce

所以你想永久关闭SeLinux的话,还是必须调整/etc/selinux/config下的参数。

# vi /etc/selinux/config

将SELINUX=enforcing调整为SELINUX=disabled 或Permissive

你也可以使用shell脚本修改参数

# getenforce

Enforcing

# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

调整完参数后,最好重启一下服务器

3:安装MySQL数据库

Zabbix支持MySQL、PostgreSQL、Oracle 等数据库,另外MySQL数据库可以用MySQL社区版或MariaDB。具体的版本要求为:MySQL.5.62 - 8.0.x ,如果是MariaDB则要求10.0.37或后续版本。

下面我们打算安装MySQL社区版。yum安装方式的简单过程如下:

安装MySQL Repository

#rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

验证MySQL Repository是否安装

#yum repolist all | grep mysql | grep enabled

[root@appliance ~]# yum repolist all | grep mysql | grep enabled

mysql-connectors-community         MySQL Connectors Community           enabled

mysql-tools-community              MySQL Tools Community                enabled

mysql80-community                  MySQL 8.0 Community Server           enabled

Yum方式安装MySQL

#yum --disablerepo=AppStream install -y mysql-community-server

#systemctl enable mysqld  #设置开机启动MySQL

#systemctl start mysqld   #启动MySQL服务

#systemctl status mysqld  #检查MySQL服务状态

获取MySQL root的临时密码

[root@appliance ~]# cat /var/log/mysqld.log | grep -i 'temporary password'

2020-07-02T07:37:04.495297Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: AgI<w+2,hwyW

[root@appliance ~]# 

执行mysql_secure_installation安全配置向导来做一些常规化安全设置

[root@appliance ~]# mysql_secure_installation

 

Securing the MySQL server deployment.

 

Enter password for user root: 

 

The existing password for the user account root has expired. Please set a new password.

 

New password: 

 

Re-enter new password: 

The 'validate_password' component is installed on the server.

The subsequent steps will run with the existing configuration

of the component.

Using existing password for root.

 

Estimated strength of the password: 100 

Change the password for root ? ((Press y|Y for Yes, any other key for No) : YES

 

New password: 

 

Re-enter new password: 

 

Estimated strength of the password: 100 

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

 

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.

 

 

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

 

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Success.

 

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

 

 

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

 - Dropping test database...

Success.

 

 - Removing privileges on test database...

Success.

 

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

 

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

 

All done!

因为规划将MySQL的数据库放在/mysql下面,所以我们还需要移动MySQL的datadir到/mysql下,关于如何移动MySQL数据库存储目录,参考我这篇博客CentOS 7上更改MySQL数据库存储目录浅析。 这里就不展开介绍细节信息了。

如果要安装MariaDB也非常简单。使用下面命令即可快捷方便的安装MariaDB

yum install mariadb-server -y

4:安装Zabbix Repository

#rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm

#dnf clean all

[root@appliance mysql]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm

Retrieving https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm

warning: /var/tmp/rpm-tmp.Am4Zqr: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY

Verifying...                          ################################# [100%]

Preparing...                          ################################# [100%]

Updating / installing...

   1:zabbix-release-5.0-1.el8         ################################# [100%]

[root@appliance mysql]# dnf clean all

28 files removed

5:安装Zabbix Server、Zabbix Agent、Zabbix Web

Nginx

dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-agent

Apache

# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent

6:初始化Zabbix的数据库

 

 

# mysql -uroot -p

password #输入具体的账号密码

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> create user zabbix@localhost identified by 'xxxxx'; #实际情况中,输入具体的账号密码(这里在某些数据库版本有个坑,后面讲述这个坑)

mysql> grant all privileges on zabbix.* to zabbix@localhost;

mysql> quit;

导入Zabbix数据库结构和数据

# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

7:配置Zabbix Server连接数据库设置

 

 

/etc/zabbix/zabbix_server.conf

一般情况执行配置DBPassword,但是如果你修改了一些默认配置,那么还需设置一些其他参数。例如DBSocket、DBPort等等。

### Option: DBHost

#       Database host name.

#       If set to localhost, socket is used for MySQL.

#       If set to empty string, socket is used for PostgreSQL.

#

# Mandatory: no

# Default:

# DBHost=localhost

DBHost=localhost

 

 

### Option: DBName

#       Database name.

#

# Mandatory: yes

# Default:

# DBName=

 

DBName=zabbix

 

### Option: DBPassword

#       Database password.

#       Comment this line if no password is used.

#

# Mandatory: no

# Default:

# DBPassword=

DBPassword=xxxxxx

 

 

### Option: DBSocket

#       Path to MySQL socket.

#

# Mandatory: no

# Default:

# DBSocket=

DBSocket=/mysql_data/mysql/mysql.sock

这里要根据实际情况进行配置,有些参数也可以不配置。有些参数,例如DBSocket,我修改过MySQL数据库的数据文件目录,所以这里必须修改。否则后面会遇到一些错误。

8:Zabbix前端的PHP配置

 

 

/etc/php-fpm.d/zabbix.conf

 

参数date.timezone的默认配置如下,一般我们必须取消注释,将时区修改为Asia/Shanghai

 

; php_value[date.timezone] = Europe/Riga

 

9: 修改nginx或Apache的配置

 

/etc/nginx/conf.d/zabbix.conf 配置端口和指定server_name的IP地址

listen          80;

server_name     xxx.xxx.xxx.xx;

如果是Apache暂时不用设置任何配置。

 

10:设置防火墙端口

#firewall-cmd --permanent --add-port=10050/tcp

 

 

#firewall-cmd --permanent --add-port=10051/tcp

 

 

#firewall-cmd --permanent --add-port=80/tcp

 

 

#firewall-cmd --reload

10: 启动服务并将其设置为开机自启动

Nginx

# systemctl restart zabbix-server zabbix-agent nginx php-fpm

# systemctl enable zabbix-server zabbix-agent nginx php-fpm

Apache

 

#systemctl restart zabbix-server zabbix-agent httpd php-fpm

#systemctl enable zabbix-server zabbix-agent httpd php-fpm

11:http://xxx.xxx.xxx.xxx/ 进入设置界面。

Nginx

 

http://192.168.xxx.xxx/setup.php

Apache

 

http://192.168.xxx.xxx/zabbix/setup.php

配置完成后,登录系统修改账号密码,禁用一些账号。然后就可以开始使用Zabbix了。

 

 

问题小结

1:导入Zabbix数据库结构和数据时遇到告警:“No database selected”

安装测试过两次,有一次遇到下面错误“No database selected”,解决办法是,在create.sql.gz中加入一行SQL:

[root@appliance ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p

 

Enter password: 

 

ERROR 1046 (3D000) at line 1: No database selected

可以先解压gz文件,加入use zabbix;这一句SQL,或者直接使用vim编辑gz文件文件

# vim create.sql.gz

其实出现上面错误,是因为脚本没有指定数据库,如下书写即可避免这个问题。你也可以通过参数 -D指定数据库。

# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

2:配置DB Connection过程遇到“Cannot Connect to the Database"错误

检查Zabbix Server的日志,发现如下错误信息。

19690:20200702:184818.882 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

19690:20200702:184818.882 database is down: reconnecting in 10 seconds

19690:20200702:184828.883 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

19690:20200702:184828.883 database is down: reconnecting in 10 seconds

19690:20200702:184838.883 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

19690:20200702:184838.883 database is down: reconnecting in 10 seconds

19690:20200702:184848.884 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

19690:20200702:184848.884 database is down: reconnecting in 10 seconds

19690:20200702:184858.884 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

19690:20200702:184858.884 database is down: reconnecting in 10 seconds

这个是Zabbix Server连接MySQL有问题。因为我移动过MySQL的数据目录,所以需要修改/etc/zabbix/zabbix_server.conf文件下的参数DBScoket,如下所示

然后Zabbix Server的错误日志中上述错误消失,但是依然报这个错误,如下截图所示, 此时必须将Database Host从localhost改为127.0.0.1

问题解决后,登录系统,修改Zabbix用户密码。

3:配置DB Connection过程遇到“Cannot Connect to the Database"错误,如下截图所示:

检查Zabbix Server的日志,tail -80f /var/log/zabbix/zabbix_server.log 如下所示,提示下面错误

63446:20200707:141746.072 Starting Zabbix Server. Zabbix 5.0.1 (revision c2a0b03480).

63446:20200707:141746.073 ****** Enabled features ******

63446:20200707:141746.073 SNMP monitoring:           YES

63446:20200707:141746.073 IPMI monitoring:           YES

63446:20200707:141746.073 Web monitoring:            YES

63446:20200707:141746.073 VMware monitoring:         YES

63446:20200707:141746.073 SMTP authentication:       YES

63446:20200707:141746.073 ODBC:                      YES

63446:20200707:141746.073 SSH support:               YES

63446:20200707:141746.073 IPv6 support:              YES

63446:20200707:141746.073 TLS support:               YES

63446:20200707:141746.073 ******************************

63446:20200707:141746.073 using configuration file: /etc/zabbix/zabbix_server.conf

63446:20200707:141746.080 [Z3001] connection to database 'zabbix' failed: [2059] Plugin caching_sha2_password could not be loaded: lib64/mariadb/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

63446:20200707:141746.080 Cannot connect to the database. Exiting

这个是因为MySQL 8数据库的加密方式改变了,可以设置参数default_authentication_plugin='mysql_native_password',使用旧版本中的认证方式。当然也可以使用下面方式修改一下账号

mysql> select version();

+-----------+

| version() |

+-----------+

| 8.0.20    |

+-----------+

1 row in set (0.00 sec)

 

mysql> show variables like 'default_authentication_plugin';

+-------------------------------+-----------------------+

| Variable_name                 | Value                 |

+-------------------------------+-----------------------+

| default_authentication_plugin | caching_sha2_password |

+-------------------------------+-----------------------+

1 row in set (0.01 sec)

 

mysql> select host,user,plugin from mysql.user;

+-----------+------------------+-----------------------+

| host      | user             | plugin                |

+-----------+------------------+-----------------------+

| localhost | mysql.infoschema | caching_sha2_password |

| localhost | mysql.session    | caching_sha2_password |

| localhost | mysql.sys        | caching_sha2_password |

| localhost | root             | caching_sha2_password |

| localhost | zabbix           | caching_sha2_password |

+-----------+------------------+-----------------------+

5 rows in set (0.00 sec)

 

mysql> alter user 'zabbix'@'localhost' identified with mysql_native_password by 'xxxxxx';

Query OK, 0 rows affected (0.02 sec)

 

mysql> 

之所以遇到这种问题,是因为上面创建账号时,使用的是下面这个SQL引起

mysql> create user zabbix@localhost identified by 'xxxxx';

 

 

参考资料

 

https://www.zabbix.com/documentation/current/manual/installation/install#installing_frontend

https://www.itzgeek.com/how-tos/linux/centos-how-tos/how-to-install-zabbix-server-on-centos-8-rhel-8.html

https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=8&db=mysql&ws=apache

https://www.itzgeek.com/how-tos/linux/centos-how-tos/how-to-install-mysql-8-0-on-rhel-8.html

https://bobcares.com/blog/zabbix-cannot-connect-to-the-database/

http://www.zsythink.net/archives/500

Zabbix 5.0 LTS版本的安装小结的更多相关文章

  1. 部署Zabbix 6.0 LTS

    Blog:博客园 个人 本部署文档适用于CentOS 8.X/RHEL 8.X/Anolis OS 8.X/AlmaLinux 8.X. Zabbix 6.0 LTS于2022年2月15日发布,本次大 ...

  2. MySql-8.0.16版本部分安装问题修正

    本帖参考网站<https://blog.csdn.net/lx318/article/details/82686925>的安装步骤,并对8.0.16版本的部分安装问题进行修正 在MySQL ...

  3. Zabbix 3.0 LTS安装配置

    关于Zabbix监控项类型的官网介绍: https://www.zabbix.com/documentation/3.4/zh/manual/config/items/itemtypes zabbix ...

  4. CentOS 7.2安装zabbix 3.0 LTS

    1.zabbix简介 zabbix(音同 zæbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供 ...

  5. ZABBIX 4.0 LTS 部署

    1. 环境说明 关于zabbix的详细使用可以参考之前的3.0 版本,该文档仅记录zabbix 4.0 编译安装过程!ZABBIX 3.0 从入门到精通(zabbix使用详解) : https://w ...

  6. Mysql 8.0.* zip版本 windows安装

    一,MySQL8.0.*zip版本安装步骤. 1,下载 https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.15-winx64.zip 注现 ...

  7. Zabbix系列-REHL6.10离线方式安装Zabbix 4.0 LTS

    环境 第零步:关闭系统默认防火墙 setenforce 0 sed -i -r "/^SELINUX=/c SELINUX=disabled" /etc/selinux/confi ...

  8. linux(centos7.0以上版本)安装 mysql-5.7.24-linux-glibc2.12-x86_64.tar 版本的mysql

      1:查看 linux下是否有老版本的mysql(有删除) 查找old mysql:rpm -qa | grep mysql 卸载:卸载命令:rpm –ev {包名}——:rpm -ev mysql ...

  9. Mysql 8.0.11版本,安装成功,使用Navicat连接失败。

    Note:本文只针对mac!! 问题 安装mysql成功之后,想自己弄个数据库试试,但是报错.并不是错误代号,而是一段代码: Authentication plugin 'caching_sha2_p ...

随机推荐

  1. 15、Facade 外观模式

    什么是Facade模式 随着系统越来越复杂,我们需要把细节隐藏起来,给客户端提供一个统一的接口.在这种需求下facade模式诞生了.该模式比较简单,我们只需要在系统变得复杂把它运用上来,这样底层跟客户 ...

  2. Java—构造方法及this/super/final/static关键字

    构造方法 构建创造时用的方法,即就是对象创建时要执行的方法. //构造方法的格式: 修饰符 构造方法名(参数列表) { } 构造方法的体现: 构造方法没有返回值类型.也不需要写返回值.因为它是为构建对 ...

  3. 2020-04-13:怎么在日志里排查错误,该用哪些Linux命令

    能通过less命令打开文件,通过Shift+G到达文件底部,再通过?+关键字的方式来根据关键来搜索信息. 能通过grep的方式查关键字,具体用法是, grep 关键字 文件名,如果要两次在结果里查找的 ...

  4. JavaScript 跨站伪造请求-CSRF

    CSRF: Cross-Site Request Forgery CSRF 概念 `定义`: 是一种对网站的而已利用,也被称之为one-click-attack 或者 session riding, ...

  5. 安装Ubuntu 出现ubi partman crashed,ubi-partman failed with exit code 10

    出现这个问题好像是因为硬盘中有遗留的raid信息导致. 在安装选项中添加 nodmraid参数,再启动进行安装就好了 如果不会添加参数可以参考这篇文章:安装ubuntu时黑屏三种解决办法 就和添加 n ...

  6. 金题大战Vol.0 A、凉宫春日的叹息

    金题大战Vol.0 A.凉宫春日的叹息 题目描述 给定一个数组,将其所有子区间的和从小到大排序,求第 \(k\) 小的是多少. 输入格式 第一行两个数\(n\),$ k\(,表示数组的长度和\)k$: ...

  7. 数据库之Oracle优化技巧(一)

    数据库之Oracle优化技巧(一) 1.where子句中的连接顺序 在Oracle数据库中,where子句的执行顺序是自下而上进行解析,根据这个原理,表之间的连接必须写在其他where条件之前,那些可 ...

  8. 【AHOI2009】 维护序列 - 线段树

    题目描述 老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成. 有长为N的数列,不妨设为a1,a2,…,aN .有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一 ...

  9. Spring配置文件中bean标签中init-method和destroy-method和用注解方式配置

    Person类: public class Person {       private int i = 0;          public Person(){           System.o ...

  10. 进阶6:连接查询 一、sql92标准

    #进阶6:连接查询/*含义:又称多表查询,当查询的字段来自于多个表时,就会用到连接查询 笛卡尔乘积现象:表1 有m行,表2有n行,结果=m*n行 发生原因:没有有效的连接条件如何避免:添加有效的连接条 ...