YUM安装部署Zabbix 4.4.7 使用 MySQL 数据库
以下是在 CentOS/RHEL 7/8 系统上使用 YUM 安装 Zabbix 4.4.7 并使用 MySQL 数据库的完整步骤:
1. 环境准备
1.1 系统要求
- CentOS/RHEL 7.x 或 8.x
- MySQL 5.7 或更高版本 / MariaDB 10.2 或更高版本
- PHP 7.2.0 或更高版本
1.2 安装前检查
# 检查系统版本
cat /etc/redhat-release
# 检查 SELinux 状态
getenforce
# 建议设置为 permissive 或 disabled
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
# 检查防火墙
systemctl status firewalld
# 如果需要开放端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --reload
2. 安装 MySQL/MariaDB
2.1 安装 MariaDB
# CentOS/RHEL 7
yum install -y mariadb-server mariadb
# CentOS/RHEL 8
dnf install -y mariadb-server mariadb
# 启动并设置开机自启
systemctl enable --now mariadb
2.2 安全配置 MySQL
mysql_secure_installation
2.3 创建 Zabbix 数据库和用户
-- 登录 MySQL
mysql -u root -p
-- 创建数据库
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
-- 创建用户并授权
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
FLUSH PRIVILEGES;
-- 退出
EXIT;
3. 安装 Zabbix 仓库
3.1 安装 Zabbix 官方仓库
# 下载 Zabbix 仓库
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/$(rpm -E %{rhel})/x86_64/zabbix-release-4.4-2.el$(rpm -E %{rhel}).noarch.rpm
# 清除缓存
yum clean all
4. 安装 Zabbix 组件
4.1 安装 Zabbix Server、前端和 Agent
# 安装 Zabbix Server 和 Web 前端
yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent
# 安装 Zabbix 获取数据的组件
yum install -y zabbix-get
4.2 导入初始数据库架构
# 导入基础架构
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
5. 配置 Zabbix
5.1 配置 Zabbix Server
编辑 /etc/zabbix/zabbix_server.conf:
vim /etc/zabbix/zabbix_server.conf
# 修改以下参数
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=your_password_here # 替换为你的密码
# 可选配置(根据需求调整)
# StartPollers=5
# StartPollersUnreachable=1
# StartTrappers=5
# StartPingers=1
# StartDiscoverers=1
# StartHTTPPollers=1
5.2 配置 PHP(Zabbix Web 前端)
编辑 /etc/php.ini:
vim /etc/php.ini
# 修改以下参数
date.timezone = Asia/Shanghai # 根据你的时区修改
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
5.3 配置 Zabbix Web 前端
编辑 /etc/httpd/conf.d/zabbix.conf:
vim /etc/httpd/conf.d/zabbix.conf
# 确保以下配置存在
php_value date.timezone Asia/Shanghai # 根据你的时区修改
6. 启动服务
6.1 启动并启用服务
# 启动 Apache
systemctl enable --now httpd
# 启动 Zabbix Server
systemctl enable --now zabbix-server
# 启动 Zabbix Agent
systemctl enable --now zabbix-agent
# 查看服务状态
systemctl status zabbix-server
systemctl status zabbix-agent
systemctl status httpd
6.2 检查日志
# 查看 Zabbix Server 日志
tail -f /var/log/zabbix/zabbix_server.log
# 查看 Apache 错误日志
tail -f /var/log/httpd/error_log
7. Web 界面安装
7.1 访问 Zabbix Web 安装向导
http://your_server_ip/zabbix/
7.2 按照向导步骤操作:
欢迎页面 - 点击下一步
检查前提条件 - 确保所有条件都是"OK"
配置数据库连接- 数据库类型: MySQL
- 数据库主机: localhost
- 数据库端口: 3306
- 数据库名称: zabbix
- 用户: zabbix
- 密码: your_password_here
Zabbix服务器详情- 主机: localhost 或 127.0.0.1
- 端口: 10051
- 名称: 可自定义(如 Zabbix Server)
安装前摘要 - 检查配置
安装完成 - 下载配置文件并上传到服务器
7.3 上传配置文件
将下载的 zabbix.conf.php 文件上传到:
# CentOS/RHEL 7/8 默认位置
/usr/share/zabbix/conf/
8. 登录和初始配置
8.1 默认登录凭据
用户名: Admin
密码: zabbix
8.2 首次登录后建议操作
修改 Admin 用户密码
配置邮件通知
添加监控主机
配置监控模板
9. 故障排除
9.1 常见问题
问题1:数据库连接失败
# 检查数据库服务
systemctl status mariadb
# 测试数据库连接
mysql -uzabbix -p -e "SELECT 1"
# 检查数据库权限
mysql -u root -p
SHOW GRANTS FOR 'zabbix'@'localhost';
问题2:PHP 时区错误
# 确认时区设置
vim /etc/php.ini
# 检查 date.timezone
# 重启 Apache
systemctl restart httpd
问题3:Zabbix Server 无法启动
# 检查配置文件语法
zabbix_server -c /etc/zabbix/zabbix_server.conf --test
# 查看详细日志
tail -100 /var/log/zabbix/zabbix_server.log
# 检查端口是否被占用
netstat -tlnp | grep 10051
问题4:Web 界面无法访问
# 检查 Apache 服务
systemctl status httpd
# 检查防火墙
firewall-cmd --list-ports
# 检查 SELinux
getenforce
9.2 性能优化建议
数据库优化:
-- 为常用查询添加索引
-- 定期清理历史数据(可通过 Zabbix 维护任务配置)
-- 调整 MySQL 配置(/etc/my.cnf)
[mysqld]
innodb_buffer_pool_size = 1G # 根据内存大小调整
max_connections = 200
Zabbix Server 优化:
# 调整 /etc/zabbix/zabbix_server.conf
StartPollers=50
StartPollersUnreachable=10
StartTrappers=15
StartPingers=10
CacheSize=256M # 根据内存调整
HistoryCacheSize=128M
TrendCacheSize=128M
10. 验证安装
10.1 验证各组件
# 验证 Zabbix Server
zabbix_server -V
# 验证数据库连接
mysql -uzabbix -p -e "use zabbix; show tables;" | wc -l
# 验证 Web 接口
curl -I http://localhost/zabbix/
10.2 测试监控
# 使用 zabbix_get 测试监控项
zabbix_get -s 127.0.0.1 -k system.uptime
注意事项
版本兼容性:Zabbix 4.4.x 需要 MySQL 5.5+ 或 MariaDB 10.0+
资源需求:生产环境建议至少 4GB RAM 和 4 CPU 核心
备份策略:定期备份数据库和配置文件
安全建议:
- 使用强密码
- 限制数据库用户权限
- 配置 SSL/TLS
- 定期更新系统补丁
这个安装指南涵盖了使用 YUM 安装 Zabbix 4.4.7 与 MySQL 数据库的主要步骤。根据你的具体环境,可能需要进行适当的调整。