[Centos7] 部署Zabbix5.0

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/https:\/\/siteproxy.ruqli.workers.dev:443\/http\/repo.zabbix.com/https:\/\/siteproxy.ruqli.workers.dev:443\/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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值