天天看點

搭建zabbix5.0

zabbix5.0 版本對基礎環境的要求有⼤的變化,最⼤的就是對 php 版本的要求,最低要求7.2.0 版本,對 php 擴充元件版本也有要求,詳⻅官⽹⽂檔

1. 準備好⼀台linux伺服器,ip位址,設定

[root@tech_linux3 ~]# hostnamectl set-hostname tech_linux3
[root@tech_linux3 ~]# cat /etc/hostname 
tech_linux3
[root@tech_linux3 ~]# ifconfig ens33|awk 'NR==2{print $2}'
192.168.6.13
# 關閉防⽕牆,selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
# 三條鍊也是空的
[root@tech_linux3 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
           

2. 擷取zabbix官⽅源

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
           

更改源頭為阿裡的

sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@tech_linux3 ~]# yum clean all
已加載插件:fastestmirror
正在清理軟體源: base extras updates zabbix zabbix-non-supported
Cleaning up list of fastest mirrors
[root@tech_linux3 ~]# yum makecache 
           

3. yum安裝zabbix前端環境

[root@tech_linux3 ~]# yum -y install zabbix-server-mysql zabbix-agent
           

4. 安裝 Software Collections,便于後續安裝⾼版本的 php,預設 yum安裝的 php 版本為 5.4 過低。

yum install centos-release-scl -y
           

5. 修改zabbix前端源 enabled=0改為1

[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
           

6. 安裝zabbix前端環境,且是是安裝到scl環境下

[root@tech_linux3 ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
[root@tech_linux3 ~]# ls /opt/rh/
rh-php72
           

7. 安裝zabbix所需要的資料庫,并設定為開機自啟動

[root@tech_linux3 ~]# yum install mariadb-server -y
[root@tech_linux3 ~]# systemctl enable --now mariadb
           

8. 初始化資料庫設定密碼123456

[root@tech_linux3 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] n
 ... skipping.

By default, MariaDB 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? [Y/n] 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? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
           

9. 使⽤root⽤戶登入mariadb,建⽴zabbix資料庫,這⾥的編碼設定,⾮常重要,否則zabbix⽆法安裝

[root@tech_linux3 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix character set utf8 collate utf8-bin;
ERROR 1273 (HY000): Unknown collation: 'utf8'
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
           

10. 使⽤以下指令導⼊ zabbix 資料庫,zabbix 資料庫⽤戶為 zabbix,密碼為123456

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

11. 修改 zabbix server 配置⽂件/etc/zabbix/zabbix_server.conf ⾥的資料庫密碼

[root@tech_linux3 ~]# vim /etc/zabbix/zabbix_server.conf
DBPassword=123456
           

12. 修改 zabbix 的 php 配置⽂件 /etc/opt/rh/rh-php72/phpfpm.d/zabbix.conf ⾥的時區

[root@tech_linux3 ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
           

13. 啟動相關服務并設定為開機自啟動

[root@tech_linux3 ~]# systemctl enable --now zabbix-server.service zabbix-agent.service httpd rh-php72-php-fpm.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/rh-php72-php-fpm.service to /usr/lib/systemd/system/rh-php72-php-fpm.service.
           

14. 通路zabbix⼊⼝