系统镜像:CentOS-7-x86_64-DVD-2009.iso
Zabbix源码包:zabbix-5.2.2.tar.gz
官方网址:https://www.zabbix.com/cn/download_sources
直接使用迅雷下载:http://192.168.1.9/zabbix-5.2.2.tar.gz?fid=8SzoZHHht0OP1q5RQkkdo87-RQtNSS0BAAAAAIyzXQLokJXECQHtLl0k68rN6Pxe&mid=666&threshold=150&tid=84A8E541DCB05E3575BE9F8D12BBE5CC&srcid=119&verno=1
系统安装完成后,关闭selinux
[root@Zabbix-Server ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
关闭防火墙
[root@Zabbix-Server ~]# systemctl disable --now firewalld
重启
[root@Zabbix-Server ~]# reboot
查看seliunx状态
[root@Zabbix-Server ~]# sestatus
查看防火墙状态
[root@Zabbix-Server ~]# systemctl status firewalld.service
##查看系统是否已经安装了mysql和mariadb数据库,
[root@Zabbix-Server ~]# rpm -qa | grep mysql
[root@Zabbix-Server ~]# rpm -pa | grep mariadb
访问mysql官网查看源下载地址
https://dev.mysql.com/downloads/repo/yum/
[root@Zabbix-Server ~]# wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
安装rpm源
[root@Zabbix-Server ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
安装mysql,等安装完成
[root@Zabbix-Server ~]# yum install -y mysql-community-server
开启mysql服务,并设置开机自动启动
[root@Zabbix-Server ~]# systemctl start mysqld.service && systemctl enable mysqld.service
查看mysql服务状态
[root@Zabbix-Server ~]# systemctl status mysqld.service
查看mysql版本
[root@Zabbix-Server ~]# mysqld -V
[root@Zabbix-Server ~]# mysql -V
重启验证mysql是否开机自动启动
通过rpm安装的MySQL会生成默认登录密码,使用如下命令查询指定路径文件即可获取
[root@Zabbix-Server ~]# grep "A temporary password" /var/log/mysqld.log
复制查询到的临时密码
初始化数据库,输入刚才得到的临时密码登录
[root@Zabbix-Server ~]# mysql_secure_installation
按照提示初始化数据库
使用刚才设置的新密码登录数据库
[root@Zabbix-Server ~]# mysql -uroot -p
创建zabbix数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.02 sec)
创建zabbix用户并设置密码
mysql> create user zabbix@localhost identified by ‘Start123!‘;
Query OK, 0 rows affected (0.01 sec)
给zabbix用户授权
mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER ‘zabbix‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY
-> ‘Start123!‘;
Query OK, 0 rows affected (0.01 sec)
[root@Zabbix-Server ~]# groupadd --system zabbix
groupadd:“zabbix”组已存在
[root@Zabbix-Server ~]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
useradd:用户“zabbix”已存在
添加文件夹
[root@Zabbix-Server ~]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
给zabbix用户授权文件夹权限
[root@Zabbix-Server ~]# chown zabbix:zabbix /usr/lib/zabbix
安装依赖
[root@Zabbix-Server ~]# yum -y install gcc gcc-c++ unixODBC-devel httpd mysql-devel libcurl libcurl-devel libevent libevent-devel fping curl-devel libxml2 libxml2-devel snmpd net-snmp-devel net-snmp
下载zabbix源码包
https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.2.tar.gz
上传zabbix源码包到/tmp文件夹下
[root@Zabbix-Server ~]# rz
[root@Zabbix-Server ~]# cp zabbix-5.2.2.tar.gz /tmp/
解压zabbix文件包
[root@Zabbix-Server ~]# cd /tmp/
[root@Zabbix-Server tmp]# tar zxvf zabbix-5.2.2.tar.gz
进入zabbix文件夹
[root@Zabbix-Server tmp]# cd zabbix-5.2.2/
在zabbix-5.2.2文件夹下编译
[root@Zabbix-Server zabbix-5.2.2]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
没有报错出现no make install时安装
[root@Zabbix-Server zabbix-5.2.2]# make install
退回到根目录
[root@Zabbix-Server zabbix-5.2.2]# cd ~
登录数据库
[root@Zabbix-Server ~]# mysql -uroot -p
进入zabbix数据库
mysql> use zabbix;
导入zabbix的三个数据库
mysql> source /tmp/zabbix-5.2.2/database/mysql/schema.sql;
mysql> source /tmp/zabbix-5.2.2/database/mysql/images.sql;
mysql> source /tmp/zabbix-5.2.2/database/mysql/data.sql;
安装PHP
[root@Zabbix-Server ~]# yum -y install epel-release yum-utils
[root@Zabbix-Server ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@Zabbix-Server ~]# yum-config-manager --enable remi-php72
[root@Zabbix-Server ~]# yum -y install httpd php php-fpm php-json
[root@Zabbix-Server ~]# yum -y install php-gd php-bcmath php-mbstring php-xmlwriter php-xmlreader php-mysqli php-ldap
进入/var/www/html文件夹,创建zabbix文件夹
[root@Zabbix-Server ~]# cd /var/www/html/
[root@Zabbix-Server html]# mkdir zabbix
复制Zabbix前端文件到/var/www/html/zabbix目录下,并授权
[root@Zabbix-Server ~]# cp /tmp/zabbix-5.2.2/ui/* /var/www/html/zabbix/ -R
[root@Zabbix-Server ~]# chown apache:apache /var/www/html/zabbix/ -R
开启httpd和php服务,并设置开机自启
[root@Zabbix-Server ~]# systemctl start httpd php-fpm && systemctl enable httpd php-fpm
通过网页访问 http://ip/zabbix
下一步时有报错,修改php.ini文件中对应参数到要求的值
php.ini文件位于/etc目录下
修改完成后重启一下服务
[root@Zabbix-Server ~]# systemctl restart httpd php-fpm
重启完成后,刷新网页所有必要条件不再报错
填写数据库密码,如果连接报错,查看数据库权限,可以访问数据库授权
[root@Zabbix-Server ~]# systemctl restart httpd php-fpm
[root@Zabbix-Server ~]# mysql -uroot -p
mysql> use zabbix;
Database changed
mysql> ALTER USER ‘zabbix‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘Start123!‘;
使用用户名Admin 密码zabbix登录
登录后发现zabbix服务器端未运行,还需要再做配置
修改zabbix_server.conf配置文件中DBPassword的值为zabbix数据库的密码
[root@Zabbix-Server ~]# find / -name zabbix_server.conf
/tmp/zabbix-5.2.2/conf/zabbix_server.conf
/usr/local/etc/zabbix_server.conf
[root@Zabbix-Server ~]# vi /usr/local/etc/zabbix_server.conf
[root@Zabbix-Server ~]# vim /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service
After=pgbouncer.service
After=postgresql-9.4.service
After=postgresql-9.5.service
After=postgresql-9.6.service
After=postgresql-10.service
After=postgresql-11.service
After=postgresql-12.service
[Service]
Environment="CONFFILE=/usr/local/etc/zabbix_server.conf"
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
[root@Zabbix-Server ~]# vim /usr/lib/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/etc/zabbix_agentd.conf"
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
[root@Zabbix-Server ~]# systemctl start zabbix-server zabbix-agent &&systemctl enable zabbix-server zabbix-agent
重启zabbix服务或者重启系统后再次访问发现一切正常
[root@Zabbix-Server ~]# systemctl restart httpd php-fpm
[root@Zabbix-Server ~]# systemctl restart zabbix-server zabbix-agent
解决中文乱码
到windows系统中拷贝简体中文字体文件并上传到/var/www/html/zabbix/assets/fonts目录下
修改/var/www/html/zabbix/include/defines.inc.php文件中的将ZBX_GRAPH_FONT_NAME的值修改为simhei
[root@Zabbix-Server ~]# vi /var/www/html/zabbix/include/defines.inc.php