简言

zabbix5.0版本已经在2020年5月11日正式发布,是最新的LTS(长期支持)版本,5.0带来很多功能和特性,后面我们会阅读相关资料后介绍,今天总结下5.0版本的安装教程。这里分别介绍通过yum安装的以及编译安装的方法供大家参考。

环境要求

5.0版本对现有的基础环境的要求有很大的变化,最大的就是对PHP版本的要求,最低要求7.2.0版本,对PHP扩展组件版本也有要求,详情可以参考文档

1
https://www.zabbix.com/documentation/current/manual/installation/requirements

YUM安装

基本环境

操作系统 安装方式
CentOS Linux release 7.4.1708 (Core 最小化安装

安装好操作系统后,关闭防火墙和selinux并且重启

1
2
3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
reboot

安装zabbix rpm源,鉴于国内网络情况,使用阿里云源

1
2
3
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
yum clean all

安装zabbix server 和agent

1
yum install zabbix-server-mysql zabbix-agent -y

安装Software Collections,便于后续安装高版本的php,默认yum安装的php版本为5.4过低

1
yum install centos-release-scl -y

启用zabbix前端源,修改/etc/yum.repos.d/zabbix.repo,将【zabbix-frontend】下的enabled改为1

1
enabled=1

安装zabbix前端以及相关环境

1
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

由于使用yum安装zabbix,不自动依赖安装数据库,因此需要手动安装数据库,这里使用yum安装centos7默认的mariadb数据库

1
yum install mariadb-server -y

启动数据库,并配置开机自动启动

1
systemctl enable --now mariadb

使用以下命令初始化mariadb并配置root密码

1
mysql_secure_installation

使用root用户进入mysql,并建立zabbix数据库,注意数据库编码

1
2
3
4
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost;
quit;

使用以下命令导入zabbix数据库,zabbix数据库用户为zabbix,密码为password

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

修改zabbix server配置文件/etc/zabbix/zabbix_server.conf 里的数据库密码

1
DBPassword=password

修改 zabbix 的 php 配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的时区

1
php_value[date.timezone] = Asia/Shanghai

启动相关服务,并配置开机自动启动

1
2
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

使用浏览器访问http://ip/zabbix即可访问zabbix的web页面

编译安装

基础环境配置

鉴于5.0对php等组件版本的要求,编译安装前建议参考版本,使用对应的版本进行安装,lnmp环境采用dnf方式安装,使用编译安装zabbix

安装好操作系统之后,关闭防火墙和selinux并重启

1
2
3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
reboot

使用dnf安装lnmp等基础环境包

1
2
dnf install httpd php php-gd php-ldap php-mysqlnd php-json php-bcmath php-mbstring php-xml mysql mysql-server mysql-devel libevent-devel pcre-devel gcc gcc-c++ make libcurl-devel curl-* net-snmp* libxml2-* wget tar -y
useradd zabbix

启动相关组件并配置开机启动

1
systemctl enable --now httpd mysqld php-fpm

安装配置

安装好启动http,mysql等服务,并使用mysql_secure_installation 命令初始化 mysql

下载zabbix5.0源码,解压并编译

1
2
3
4
5
6
7
8
cd /opt
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz
tar zxvf zabbix-5.0.0.tar.gz
cd zabbix-5.0.0
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent \
--with-mysql --with-net-snmp --with-libcurl --with-libxml2
make
make install

使用mysql的root用户登录mysql数据库,建立zabbix数据库用户等相关信息

1
2
3
4
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost;
quit

按照顺序,依次导入sql

1
2
3
mysql -uzabbix -p zabbix < /opt/zabbix-5.0.0/database/mysql/schema.sql
mysql -uzabbix -p zabbix < /opt/zabbix-5.0.0/database/mysql/images.sql
mysql -uzabbix -p zabbix < /opt/zabbix-5.0.0/database/mysql/data.sql

修改 zabbix server 配置文件/usr/local/zabbix/etc/zabbix_server.conf,修改数据库密码

1
2
3
...
DBPassword=password
...

为 zabibx server 添加 systemd 启动文件

1
vi /lib/systemd/system/zabbix-server.service

内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

为 zabbix agent 添加 systemd 启动文件

1
vi /lib/systemd/system/zabbix-agent.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target

启动zabbix server 和zabbix agent,并配置开机启动

1
2
systemctl enable --now zabbix-server
systemctl enable --now zabbix-agent

前端安装

拷贝zabbix前端文件到apache默认web目录

1
2
cp -r /opt/zabbix-5.0.0/ui/* /var/www/html/
chown -R apache:apache /var/www/html/

配置php参数

1
2
3
4
5
sed -i 's#post_max_size = 8M#post_max_size = 16M#' /etc/php.ini
sed -i 's#max_execution_time = 30#max_execution_time = 300#' /etc/php.ini
sed -i 's#max_input_time = 60#max_input_time = 300#' /etc/php.ini
sed -i 's#;date.timezone =#date.timezone = Asia/Shanghai#' /etc/php.ini
systemctl restart php-fpm

配置后使用浏览器访问http://ip/ 就可以访问 zabbix 页面了

WEB初始化

image-20200820131049068