目录
- 0 卸载 Zabbix
- 1 准备工作
- 1.1 关闭防火墙
- 1.2 关闭SELinux
- 1.3 重启服务器
- 1.4 安装MySQL
- 2 配置 Zabbix yum 源
- 2.1 安装zabbix的软件仓库配置包
- 2.2 安装 Software Collections 仓库
- 2.3 修改 Zabbix 仓库配置文件
- 3 安装 Zabbix
- 3.1 遇到报错Requires: libmysqlclient.so.18
- 3.2 遇到报错 Requires: rh-php72
- 4 配置 Zabbix
- 4.1 创建 zbbix 数据库
- 4.2 导入 zabbix 建表语句
- 4.3 配置 zabbix-server
- 4.4 配置 zabbix-agent
- 4.5 配置zabbix-web时区
- 5 启动、停止 Zabbix
- 5.1 zabbix-agent
- 5.1.1 启动报错 Can't open PID file
- 5.2 zabbix-agent
- 5.3 连接 Zabbix_Web数据库
- 5.3.1 浏览器访问 http://centos702/zabbix/
- 5.3.2 检查配置
- 5.3.3 配置数据库
- 5.3.4 配置 zabbix-server
- 5.4 登录 Zabbix front
https://www.zabbix.com/documentation
https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=centos&os_version=7
0 卸载 Zabbix
yum remove -y $(yum list installed | grep zabbix | awk '{print $1}')
1 准备工作
1.1 关闭防火墙
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
1.2 关闭SELinux
sudo vim /etc/selinux/config
SELINUX = disabled
1.3 重启服务器
sudo reboot
1.4 安装MySQL
https://blog.csdn.net/weixin_43724577/article/details/129896129
2 配置 Zabbix yum 源
阿里云镜像
https://mirrors.aliyun.com/zabbix/zabbix
2.1 安装zabbix的软件仓库配置包
sudo rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sudo yum clean all
2.2 安装 Software Collections 仓库
sudo yum install -y centos-release-scl
/etc/yum.repo.d/CentOS-SCLo-scl-rh.repo
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
#baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
2.3 修改 Zabbix 仓库配置文件
查看原始zabbix.repo文件
sudo cat /etc/yum.repos.d/zabbix.repo
全改为阿里云的镜像
sudo sed -i 's/http:\/\/repo.zabbix.com/https:\/\/mirrors.aliyun.com\/zabbix/g' /etc/yum.repos.d/zabbix.repo
打开 /etc/yum.repos.d/zabbix.repo 文件,启用zabbix-web仓库
vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend] 中的 enabled=0改为 enabled = 1
最终的zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
3 安装 Zabbix
sudo yum install -y zabbix-server-mysql zabbix-agent zabbix-web-mysql-scl zabbix-apache-conf-scl
3.1 遇到报错Requires: libmysqlclient.so.18
Error: Package: zabbix6.0-server-mysql-6.0.29-1.el7.x86_64 (epel)
Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
Error: Package: zabbix6.0-server-mysql-6.0.29-1.el7.x86_64 (epel)
Requires: libmysqlclient.so.18()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
原因可能是安装MySQL时没有安装mysql-community-embedded-compat-8.0.36-1.el7.x86_64.rpm
,这个软件包提供了 MySQL 8.0 与早期版本的 MySQL 和 MariaDB 之间的兼容性库。
解决办法:
rpm -ivh mysql-community-libs-compat-8.0.36-1.el7.x86_64.rpm
3.2 遇到报错 Requires: rh-php72
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-gd
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-ldap
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-xml
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-bcmath
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-fpm
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-mbstring
Error: Package: zabbix-web-deps-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72
Error: Package: zabbix-web-mysql-scl-5.0.6-1.el7.noarch (zabbix-frontend)
Requires: rh-php72-php-mysqlnd
解决办法
# 1. 卸载旧PHP
yum remove php* -y
# 2. 安装rh
yum install centos-release-scl-rh
# 3. 查询php
yum search php
# 4.安装
yum -y install rh-php72
scl enable rh-php72 bash
# 5.查看版本
php -v
4 配置 Zabbix
4.1 创建 zbbix 数据库
mysql -uroot -p123456
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by '123456';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
4.2 导入 zabbix 建表语句
zcat /usr/share/doc/zabbix-server-mysql-5.0.42/create.sql.gz | mysql -uroot -p123456 zabbix
导入数据库架构后禁用log_bin_trust_function_creators选项。
mysql -uroot -p123456 -e"set global log_bin_trust_function_creators = 0;"
4.3 配置 zabbix-server
sudo vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
4.4 配置 zabbix-agent
sudo vim /etc/zabbix/zabbix_agentd.conf
Server=centos702
# ServerActive=127.0.0.1
# Hostname=Zabbix server
4.5 配置zabbix-web时区
sudo vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
5 启动、停止 Zabbix
5.1 zabbix-agent
开机自启
systemctl enable zabbix-server httpd rh-php72-php-fpm
启动
systemctl restart zabbix-server httpd rh-php72-php-fpm
停止
systemctl stop zabbix-server httpd rh-php72-php-fpm
5.1.1 启动报错 Can’t open PID file
Can't open PID file /run/zabbix/zabbix_server.pid (yet?) after start: No such file or directory
查看日志
tail -n 100 /var/log/zabbix/zabbix_server.log
2091:20240621:133938.283 [Z3001] connection to database 'zabbix' failed: [2059] Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
2091:20240621:133938.283 Cannot connect to the database. Exiting...
这个错误通常发生在尝试连接MySQL数据库时,特别是当数据库服务器使用的是MySQL 8.0及以上版本,因为从MySQL 8.0开始,默认的用户密码认证插件变成了'caching_sha2_password'。而你尝试使用的客户端或连接库可能还没有更新来支持这个新的认证插件。
解决办法
mysql -uroot -p123456 -e"ALTER USER 'zabbix'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';"
mysql -uroot -p123456 -e"FLUSH PRIVILEGES;"
5.2 zabbix-agent
设置开启自启动
systemctl enable zabbix-agent
启动
systemctl start zabbix-agent
停止
systemctl stop zabbix-agent
5.3 连接 Zabbix_Web数据库
5.3.1 浏览器访问 http://centos702/zabbix/
Next step
5.3.2 检查配置
Next step
5.3.3 配置数据库
Next step
5.3.4 配置 zabbix-server
Next step
Next step
Finish
5.4 登录 Zabbix front
用户名 Admin
密码 zabbix