09-zabbix安装
以下是根据你提供的内容整理的 Zabbix 5.0 安装与配置笔记,采用 Markdown 格式:
Zabbix 5.0 安装与配置笔记
一、Zabbix 服务端安装
1. 添加 Zabbix 官方源(使用阿里云镜像)
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm2. 替换为阿里云源
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo3. 清理并生成 YUM 缓存
yum clean all
yum makecache4. 安装 Zabbix Server 和 Agent
yum install zabbix-server-mysql zabbix-agent -y5. 安装 SCL(支持多版本软件)
yum install centos-release-scl -y6. 修改前端源(启用前端仓库)
vim /etc/yum.repos.d/zabbix.repo
# 将 enabled=0 改为 enabled=17. 安装 Zabbix 前端环境(SCL 版)
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y8. 安装 MariaDB 数据库
yum install mariadb-server -y
systemctl enable --now mariadb9. 初始化数据库
mysql_secure_installation10. 创建 Zabbix 数据库与用户
mysql -uroot -p
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by '111111';
grant all privileges on zabbix.* to zabbix@localhost;
flush privileges;
quit;11. 导入 Zabbix 初始数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix12. 配置 Zabbix Server 数据库连接
vim /etc/zabbix/zabbix_server.conf
# 设置 DBPassword=111111
grep "^DBP" /etc/zabbix/zabbix_server.conf13. 配置 PHP 时区
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
# 设置 php_value[date.timezone] = Asia/Shanghai14. 启动服务并设置开机自启
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm二、Zabbix 客户端安装(Agent2)
1. 时间同步与时区设置
yum install ntpdate -y
ntpdate -u ntp.aliyun.com
mv /etc/localtime{,.bak}
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime2. 安装 Zabbix Agent2
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install zabbix-agent2 -y3. 配置 Agent2
vim /etc/zabbix/zabbix_agent2.conf设置以下内容:
Server=10.2.20.237
ServerActive=10.2.20.237
Hostname=zz4. 启动 Agent2
systemctl enable --now zabbix-agent25. 验证 Agent 是否正常
在服务端安装 zabbix-get 并测试:
yum install -y zabbix-get
zabbix_get -s '10.2.20.138' -p 10050 -k 'system.hostname'三、Zabbix 网页乱码解决
1. 安装中文字体
yum -y install wqy-microhei-fonts2. 替换默认字体
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf四、Apache + PHP 配置(可选优化)
vim /etc/httpd/conf/httpd.conf添加或确认以下内容:
DocumentRoot "/var/www/html"
TypesConfig /etc/mime.types
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html五、其他说明
- Zabbix 前端访问地址:
http://<server_ip>/zabbix - 默认用户名/密码:
Admin/zabbix - 若前端无法访问,请检查防火墙与 SELinux 设置
如果需要,我可以帮你补充 SELinux、防火墙配置,或提供自动化安装脚本。