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. Nginx WebUI管理

    简介 NginxWebUI是一款方便实用的nginx 网页配置工具,可以使用 WebUI 配置 Nginx 的各项功能,包括端口转发,反向代理,ssl 证书配置,负载均衡等,最终生成「nginx.co ...

  2. 盘点 35 个 Apache 顶级项目,我拜服了…

    Apache 软件基金会 Apache 软件基金会,全称:Apache Software Foundation,简称:ASF,成立于 1999 年 7 月,是目前世界上最大的最受欢迎的开源软件基金会, ...

  3. Elasticsearch第一篇:在 Windows 上的环境搭建

    本文介绍如何在 windows 10 ,64位操作系统上安装最新版本 Elasticsearch.以及相关插件.之前看了不少园友的文章,用到的版本都比较低,尤其是插件的版本要和ES的版本相对应等这些问 ...

  4. C#图解教程(第四版)—02—类的基本概念

    类  是一种能 存储数据  并且  执行代码  的数据结构,他包含数据成员和函数成员 .成员可以是9种可能的成员类型的任意组合 字段 属性 方法 常量 构造函数 析构函数 运算符 索引器 事件 1 字 ...

  5. 后端排序时去掉element表格排序的null状态

    经常会遇到远程排序,需要去掉null状态的排序,当设置sortable='custom'时,设置sort-orders为['ascending', 'descending']是不生效的.然后查到了一种 ...

  6. 【面经】超硬核面经,已拿蚂蚁金服Offer!!

    写在前面 很多小伙伴都反馈说,现在的工作不好找呀,也不敢跳槽,在原来的岗位上也是战战兢兢!其实,究其根本原因,还是自己技术不过关,如果你技术真的很硬核,怕啥?想去哪去哪呗!这不,我的一个读者去面试了蚂 ...

  7. angular schametics 使用记录

    什么是 schametics Schematics是Angular团队发布的一个代码生成工具.它提供了API,可以操作文件并在Angular项目中添加新的依赖项,ng cli 创建模板就是用它. 它也 ...

  8. 微信小程序-人脸识别

    wx.checkIsSupportFacialRecognition({success:res=>{ wx.startFacialRecognitionVerifyAndUploadVideo( ...

  9. Jmeter 常用函数(4)- 详解 __setProperty

    如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦 https://www.cnblogs.com/poloyy/p/13291704.html 前言 有看我之前写的 Jmeter 文章的童 ...

  10. SparkSQL DSL开发(Old)

    import org.apache.spark.sql.SQLContextimport org.apache.spark.sql.expressions.Windowimport org.apach ...