# 确保系统是最新版本
yum update -y
# 安装必要工具
yum install -y epel-release vim wget net-tools
hostnamectl set-hostname zabbix-server
echo "192.168.1.100 zabbix-server" >> /etc/hosts
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
# 运行安全配置
mysql_secure_installation
# 设置root密码,移除匿名用户,禁止root远程登录等
mysql -u root -p
# 在MySQL命令行中执行
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'YourPassword123';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
FLUSH PRIVILEGES;
EXIT;
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
yum install -y zabbix-server-mysql zabbix-agent zabbix-web-mysql zabbix-web
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
# 输入之前设置的zabbix用户密码
vim /etc/zabbix/zabbix_server.conf
修改以下关键配置:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=YourPassword123
# 可选:调整其他参数
# ListenPort=10051
# StartPollers=100
# StartPollersUnreachable=50
vim /etc/php.ini
修改以下参数:
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai
vim /etc/httpd/conf.d/zabbix.conf
确保时区配置正确:
php_value date.timezone Asia/Shanghai
# 启动所有服务
systemctl start zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd
# 如果SELinux启用
setsebool -P httpd_can_connect_zabbix on
# 配置防火墙
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --reload
http://服务器IP/zabbix
# 将下载的zabbix.conf.php复制到web目录
cp zabbix.conf.php /etc/zabbix/web/
chown apache:apache /etc/zabbix/web/zabbix.conf.php
vim /etc/zabbix/zabbix_agentd.conf
修改:
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zabbix-server
# 调整MySQL配置
vim /etc/my.cnf.d/mariadb-server.cnf
# 添加优化参数
[mysqld]
innodb_buffer_pool_size=256M
innodb_log_file_size=64M
innodb_log_buffer_size=16M
systemctl status zabbix-server
systemctl status zabbix-agent
systemctl status httpd
netstat -tlnp | grep -E '10050|10051|80'
tail -f /var/log/zabbix/zabbix_server.log
Web界面显示空白
# 检查PHP配置
yum install -y php-gd php-bcmath php-mbstring php-xml
systemctl restart httpd
数据库连接失败
# 验证数据库连接
mysql -uzabbix -p -e "SHOW DATABASES;"
Zabbix Server无法启动
# 查看详细错误
journalctl -xe -u zabbix-server
这样就完成了Zabbix 5.0在CentOS 7上的基本安装和配置。安装完成后建议立即修改默认密码,并根据实际需求配置监控项。