CentOS 7 安装 Zabbix 5.0 详细步骤
一、系统准备(最小化安装的CentOS 7)
# 1. 更新系统
yum update -y
# 2. 安装基础工具
yum install -y wget vim net-tools epel-release
# 3. 关闭防火墙(生产环境请配置规则)
systemctl stop firewalld
systemctl disable firewalld
# 4. 关闭SELinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 5. 设置时区
timedatectl set-timezone Asia/Shanghai
二、安装和配置数据库(MariaDB 10.5)
# 1. 添加MariaDB官方仓库
cat > /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
# 2. 安装MariaDB
yum install -y MariaDB-server MariaDB-client
# 3. 启动并设置开机自启
systemctl start mariadb
systemctl enable mariadb
# 4. 运行安全配置向导
mysql_secure_installation
# 按提示操作,设置root密码并移除测试数据库等
# 5. 创建Zabbix数据库和用户
mysql -uroot -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;
三、安装Zabbix Server
# 1. 安装Zabbix仓库
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 2. 清理yum缓存
yum clean all
# 3. 安装Zabbix Server和Agent
yum install -y zabbix-server-mysql zabbix-agent zabbix-get
# 4. 导入数据库架构和数据
cd /usr/share/doc/zabbix-server-mysql*/
zcat create.sql.gz | mysql -uzabbix -p zabbix
# 输入之前设置的zabbix用户密码
四、配置Zabbix Server
# 1. 编辑Zabbix Server配置文件
vim /etc/zabbix/zabbix_server.conf
修改以下配置:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=YourPassword123
# 其他保持默认
五、安装和配置PHP环境
# 1. 安装PHP及相关模块
yum install -y httpd php php-mysql php-gd php-xml php-bcmath php-mbstring php-ldap
# 2. 配置PHP
vim /etc/php.ini
修改以下参数:
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai
六、安装Zabbix Web界面
# 1. 安装Zabbix Web
yum install -y zabbix-web-mysql zabbix-apache-conf
# 2. 配置时区
sed -i 's/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/' /etc/httpd/conf.d/zabbix.conf
# 3. 启动Apache并设置开机自启
systemctl start httpd
systemctl enable httpd
# 4. 启动Zabbix服务
systemctl start zabbix-server zabbix-agent
systemctl enable zabbix-server zabbix-agent
七、配置Zabbix Agent
# 编辑Agent配置文件
vim /etc/zabbix/zabbix_agentd.conf
确认以下配置:
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zabbix-server
八、完成安装
# 1. 重启所有服务
systemctl restart mariadb httpd zabbix-server zabbix-agent
# 2. 检查服务状态
systemctl status mariadb httpd zabbix-server zabbix-agent
# 3. 查看Zabbix日志
tail -f /var/log/zabbix/zabbix_server.log
九、Web界面安装
打开浏览器访问:http://服务器IP/zabbix
按照向导完成安装:
登录Web界面:
默认用户名:Admin
默认密码:zabbix
十、优化建议
# 1. 调整数据库配置(可选)
vim /etc/my.cnf.d/server.cnf
# 添加以下配置到[mysqld]部分
innodb_buffer_pool_size = 256M
innodb_log_file_size = 64M
query_cache_size = 32M
max_connections = 100
# 2. 重启数据库
systemctl restart mariadb
# 3. 调整Zabbix Server内存(根据实际情况)
vim /etc/zabbix/zabbix_server.conf
# StartPollers=5(根据监控主机数量调整)
# StartDiscoverers=1
# CacheSize=128M
# HistoryCacheSize=128M
# HistoryIndexCacheSize=32M
# 4. 重启Zabbix服务
systemctl restart zabbix-server
十一、安装常见问题解决
# 1. 如果遇到PHP模块缺失
yum install -y php-ctype php-session php-sockets php-simplexml
# 2. 如果无法连接数据库
# 检查数据库服务是否启动
# 检查防火墙是否关闭
# 检查SELinux是否禁用
# 3. 查看错误日志
tail -100 /var/log/zabbix/zabbix_server.log
tail -100 /var/log/httpd/error_log
# 4. 重置管理员密码(如忘记密码)
mysql -uroot -p zabbix
UPDATE users SET passwd=md5('新密码') WHERE alias='Admin';
十二、添加被监控主机
在Zabbix Web界面:
- 配置 → 主机 → 创建主机
- 填写主机名称、可见名称
- 添加模板:Template OS Linux by Zabbix agent
- 配置Agent接口:IP地址和端口10050
在被监控主机安装Agent:
# 在被监控主机执行
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install -y zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf
# 修改Server=Zabbix_Server_IP
systemctl start zabbix-agent
systemctl enable zabbix-agent
按照以上步骤操作,即可成功在CentOS 7上安装Zabbix 5.0监控系统。