CentOS7 下安装 Zabbix
1.关闭防火墙
2. 安装Zabbix
3. 安装MySQL
4. 导入zabbix表
5. 启动
缺少libmysqlclient.so.18解决
SELinux 解决
MySQL8.0解决
其他
6. 验证
7.web页面
环境要求(执行下面红色代码即可查看本机信息):
rpm -q centos-release
centos-release-7-9.2009.0.el7.centos.x86_64
uname -r
3.10.0-1127.el7.x86_64
zabbix官网:https://www.zabbix.com/
1.关闭防火墙
如果是虚拟机直接关闭防火墙即可
如果是线上的建议开启端口:
https://blog.csdn.net/WeiHao0240/article/details/99674024
# 1:查看防火状态
systemctl status firewalld
# 2:暂时关闭防火墙
systemctl stop firewalld
# 3:永久关闭防火墙
systemctl disable firewalld
# 4:重启防火墙
systemctl enable firewalld
2. 安装Zabbix
# 1. 下载yum源
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.安装server, agent, get, sender, web
yum -y install zabbix-server-mysql zabbix-agent zabbix-get zabbix-sender zabbix-web zabbix-web-mysql
# 4.启用红帽软件集合
yum-config-manager –enable rhel-server-rhscl-7-rpms
# 5.查看前端仓库是否支持
vim /etc/yum.repos.d/zabbix.repo
# 修改[zabbix-frontend] 下面 enabled=1
# 6.安装前端包 apache
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
有可能会报错:
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
说明没有安装rh-php
参考网站:https://blog.csdn.net/supergao222/article/details/78308197?utm_medium=distribute.pc_relevant.none-task-blog-searchFromBaidu-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-searchFromBaidu-2.control
# 1. 卸载旧PHP
yum remove php* -y
# 2. 安装rh
yum install centos-release-scl-rh
# 3. 查询php
yum search php
# 4.安装
yum install rh-php73
scl enable rh-php73 bash
# 5.查看版本
php -v
# 然后再安装前端包
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
3. 安装MySQL
这里安装的MySQL5.7
如果已经安装了请跳过这步
安装连接:https://blog.csdn.net/WeiHao0240/article/details/99644197
4. 导入zabbix表
# 1.登录MySQL, 必须要用root用户
mysql -uroot -p
# 2.创建zabbix数据库
create database zabbix character set utf8 collate utf8_bin;
# 3.创建zabbix用户 并制定验证密码
create user zabbix@localhost identified by ‘Zabbix2020..’;
# 4.给zabbix用户赋予zabbix数据库权限
grant all privileges on zabbix.* to zabbix@localhost;
# 退出
quit;
# 导入数据库表
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
# 修改数据库配置
vim /etc/zabbix/zabbix_server.conf
# DBName 就是新建数据库的名称
# DBUser 就是新建的用户
#DBpassword 登录密码
# 设置php时区
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
# 设置上海时区如下:
# php_value[date.timezone] = Asia/Shanghai
5. 启动
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
有可能会出错
Job for zabbix-server.service failed because the control process exited with error code. See “systemctl status zabbix-server.service” and “journalctl -xe” for details.
# 查看详细错误信息
journalctl -xe
缺少libmysqlclient.so.18
zabbix_server: /lib64/libmysqlclient.so.18: no version information available (required by zabbix_server)
zabbix_server: /lib64/libmysqlclient.so.18: version `libmysqlclient_18’ not found (required by zabbix_server)
说明zabbix_server需要libmysqlclient.so.18
但是本地没有, 我的本地是libmysqlclient.so.21 高版本不能用
缺少libmysqlclient.so.18解决
迅雷云盘链接:https://pan.xunlei.com/s/VMNzti7L0ZhOWK1uJx7zvHKiA1
提取码:widh
# 从上面的连接下载放到 /usr/lib/ 下面
# 也拷贝到lib64下面
cp /usr/lib/libmysqlclient.so.18 /usr/lib64/
继续报错:
=error msg=“agent: session failed” backoff=8s error=”rpc error: code = Unavailable desc = all SubConns are in Transien
SELinux 解决
Enforcing:强制模式。代表SELinux在运行中,且已经开始限制domain/type之间的验证关系
Permissive:宽容模式。代表SELinux在运行中,不过不会限制domain/type之间的验证关系,即使验证不正确,进程仍可以对文件进行操作。不过如果验证不正确会发出警告
Disabled:关闭模式。SELinux并没有实际运行
getenforce
setenforce 0
getenforce
在这里插入图片描述
MySQL8.0解决
Operation CREATE USER failed for ‘zabbix’@’%’
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by
密码验证必须都要用with mysql_native_password by
# 查看用户
select host,user from user;
# 删除
delete from mysql.user where user = ‘zabbix’;
# 这一步也要执行
drop user zabbix@localhost;
# 刷新权限
flush privileges;
# 创建用户
create user ‘zabbix’@’localhost’ IDENTIFIED with mysql_native_password by ‘Zabbix2020..’;
# 修改为%
update user set host = ‘%’ where user = ‘zabbix’;
# 刷新权限
flush privileges;
ALTER user ‘zabbix’@’%’ IDENTIFIED with mysql_native_password by ‘Zabbix2020..’;
flush privileges;
其他
查看
/var/log/zabbix/zabbix_server.log
错误日志
6. 验证
ps -ef | grep zabbix
7.web页面
下面换成你的ip即可
http://xxx.xxx.x.x/zabbix/
原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/272267.html