Zabbix是一个基于WEB界面的提供分布式系统监控的企业级的开源解决方案,Zabbix能监视各种网络参数,系统硬件参数,保证服务器系统的安全稳定的运行,并提供灵活的通知机制以让管理员快速定位并解决存在的各种问题。
部署系统环境:Nginx1.18,MariaDB10.4.13,PHP7.4.7
https://www.zabbix.com/cn/download?zabbix=4.4&os_distribution=centos&os_version=7&db=mysql&ws=nginx
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
yum clean all
https://developer.aliyun.com/mirror/
[zabbix]
name=Zabbix Official Repository - $basearch
#baseurl=http://repo.zabbix.com/zabbix/4.4/rhel/7/$basearch/
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
yum clean all
yum install zabbix-server-mysql zabbix-agent
yum install epel-release
yum install zabbix-web-mysql zabbix-nginx-conf
安装过程中报错:缺失php-mysql组件,原因为新版本的PHP7.4中无php-mysql组件。原先PHP5.4版本中的php-mysql组件被新版的php-mysqlnd代替,安装依赖找不到。
好在PHP7.4安装包中有php-pecl-mysql组件,尝试手动安装
yum install php-pecl-mysql
重新安装Zabbix frontend
yum install zabbix-web-mysql zabbix-nginx-conf
终于不再报错,安装成功!
mysql -uroot -p[password]
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
mysql> flush privileges;
mysql> quit;
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=zabbix
DBSocket=/data/mariadb/mysql.sock
# 如果是源码编译安装的MySQL数据库,需要指定mysql.sock文件路径
编辑配置文件 /etc/nginx/conf.d/zabbix.conf, 去除 ‘listen’和 ‘server_name’ 的注释
指定server_name zabbix.com
在/etc/nginx/nginx.conf中添加以下include语句,包含虚拟主机配置文件,并注释掉配置文件中原先存在的默认虚拟主机配置
include /etc/nginx/conf.d/*.conf;
编辑配置文件 /etc/php-fpm.d/zabbix.conf, 修改用户和组至nginx,并设置本地timezone=Asia/Shanghai
[zabbix]
user = nginx
group = nginx
listen = /run/php-fpm/zabbix.sock
listen.owner = nginx
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
php_value[date.timezone] = Asia/Shanghai
修改/etc/php-fpm.d/www.conf 设置user和group至nginx
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
将/etc/zabbix/web目录的组和拥有者设置为nginx(nginx服务的启动用户)
chown nginx. -R /etc/zabbix/web/
修改/var/lib/php/session目录的组和拥有者设置为nginx(nginx服务的启动用户)
chown nginx. -R /var/lib/php/session
# 配置文件/etc/php-fpm.d/zabbix.conf中有此目录设置
systemctl restart zabbix-server zabbix-agent nginx php-fpm
systemctl enable zabbix-server zabbix-agent nginx php-fpm
查看端口
客户端配置hosts
# 添加虚拟主机server_name zabbix.com
192.168.161.89 zabbix.com
确保全绿OK
web前端默认账户为:Admin / zabbix (A大写)
# 配置Zabbix源,方法与Zabbix服务端相同
yum install -y zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf
server=192.168.161.89
# Zabbix Server IP或Hostname
hostname=192.168.161.92
# 被监控IP或Hostname
systemctl restart zabbix-agent
确认端口已启动