Zabbix 5.0 LTS版本的安裝小結


Zabbix 5.0 LTS版本的安裝小結

 

1:准備Zabbix的服務器。

 

這里可能需要一台或多台服務器,視需求和資源而定。也可以將Zabbix_ServerMySQLZabbix 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,又不想重啟服務器,那么使用下面命令。但是該命令只能將SeLinuxenforcingpermissive這兩種模式之間切換.服務器重啟后,又會恢復到/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支持MySQLPostgreSQLOracle 等數據庫,另外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

 

clip_image001

 

#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下面,所以我們還需要移動MySQLdatadir/mysql下,關於如何移動MySQL數據庫存儲目錄,參考我這篇博客CentOS 7上更改MySQL數據庫存儲目錄淺析。 這里就不展開介紹細節信息了。

 

clip_image002

 

如果要安裝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 ServerZabbix AgentZabbix 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,但是如果你修改了一些默認配置,那么還需設置一些其他參數。例如DBSocketDBPort等等。 

### 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數據庫的數據文件目錄,所以這里必須修改。否則后面會遇到一些錯誤。

 

 

 

 

8Zabbix前端的PHP配置

 

 

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

 

參數date.timezone的默認配置如下,一般我們必須取消注釋,將時區修改為Asia/Shanghai

 

; php_value[date.timezone] = Europe/Riga

 

 

clip_image003

 

 

9: 修改nginxApache的配置

 

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

 

        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

 

 

 

 

11http://xxx.xxx.xxx.xxx/ 進入設置界面。

 

Nginx

 

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

 

Apache

 

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

 

 

clip_image004

 

 

配置完成后,登錄系統修改賬號密碼,禁用一些賬號。然后就可以開始使用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

 

clip_image005

 

 

其實出現上面錯誤,是因為腳本沒有指定數據庫,如下書寫即可避免這個問題。你也可以通過參數 -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,如下所示

 

clip_image006

 

然后Zabbix Server的錯誤日志中上述錯誤消失,但是依然報這個錯誤,如下截圖所示, 此時必須將Database Hostlocalhost改為127.0.0.1

 

clip_image007

 

問題解決后,登錄系統,修改Zabbix用戶密碼。

 

 

3配置DB Connection過程遇到Cannot Connect to the Database"錯誤,如下截圖所示:

 

clip_image008

 

檢查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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM