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 过低。

SCL(Software Collections)可以让你在同⼀个操作系统上安装和使⽤多个版本的软件,⽽不会影响整个系统的安装包。 软件包会安装在/opt/rh⽬录下 为了避免系统⼴泛冲突,/opt/rh包安装在⽬录中,例如,这允许你在CentOS7机器上安装Python 3.5,⽽不会删除或⼲扰Python 2.7. /etc/opt/rh/软件包的所有配置⽂件都存储在⽬录中相应的⽬录中,SCL包提供了定义使⽤所包含应⽤程序所需的环境变量的shell脚本,例如,PATH,LD_LIBRARY_PATH和MANPATH ,这些脚本存储在⽂件系统中,作为/opt/rh/package-name/enable 。

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⼊⼝

浏览器访问http://192.168.6.13/zabbix/setup.php

安装成功后登录:登录账号为 Admin,密码:zabbix,注意⼤⼩写!