当前位置: 首页>编程语言>正文

zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人

zabbix5.0部署 and 监控docker容器状态 and 配置企业微信报警机器人

1.系统优化
hostnamectl set-hostname docker-zabbix-server
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
2.安装阿里源
yum install -y vim wget net-tools telnet
mv /etc/yum.repos.d /etc/yum.repos.d.backup
mkdir -p /etc/yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安装zabbix源
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
清理缓存
yum clean all
yum makecache

yum install zabbix-server-mysql zabbix-agent2 zabbix_get -y
yum install centos-release-scl -y
vim /etc/yum.repos.d/zabbix.repo将[zabbix-frontend]下的 enabled 改为 1
安装 zabbix 前端和相关环境
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
安装mysql8.0.20版本
软件包下载地址:
先去网站下载
https://dev.mysql.com/downloads/mysql/
tar -xvf mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar
yum install mysql-community-{server,client,common,libs}-*
systemctl start mysqld
查询随机密码
cat /var/log/mysqld.log | grep password
mysql -uroot -p
set global validate_password.policy=LOW; 
alter user 'root'@'localhost' identified by 'admin123';
show variables like 'validate_password%';
配置可远程连接
create user 'root'@'%' identified with mysql_native_password by 'admin123'; 
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
创建zabbix用户
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'admin123';
grant all privileges on zabbix.* to zabbix@localhost;
select user,host,plugin from user;
ALTER USER zabbix@localhost IDENTIFIED WITH mysql_native_password BY 'admin123';
flush privileges;
quit;
导入zabbix数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
修改 zabbix server 配置文件vi /etc/zabbix/zabbix_server.conf 里的数据库密码
DBPassword=password
修改 zabbix 的 php 配置文件vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的时区,改成 Asia/Shanghai
php_value[date.timezone] = Asia/Shanghai
开机自启动
systemctl restart zabbix-server zabbix-agent2 httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent2 httpd rh-php72-php-fpm
systemctl status zabbix-server zabbix-agent2 httpd rh-php72-php-fpm

使用浏览器访问http://ip/zabbix 即可访问 zabbix 的 web 页面

更新conf配置
[15:51:55root@zabbix-server-docker /etc/docker]#grep -Ev '^#|^$' /etc/zabbix/zabbix_server.conf 
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=admin123
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
[15:51:59root@zabbix-server-docker /etc/docker]#grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.124.10
ServerActive=127.0.0.1,192.168.124.10
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人,第1张

加权
sudo gpasswd -a ${USER} docker
sudo gpasswd -a zabbix docker
cat /etc/group | grep docker
sudo service docker restart

usermod -a -G root zabbix
usermod -a -G docker zabbix
systemctl restart zabbix-agent2

测试监控数据
zabbix_get -s '192.168.124.10' -p 10050 -k 'agent.ping'
zabbix_get -s '192.168.124.10' -p 10050 -k docker.info


zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人,第2张

更新docker模板中的 监控触发条件 and 触发时间


zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人,第3张

zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人,第4张

zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人,第5张

docker测试 stop任何一个容器 检查是否报警


zabbix5.0部署 and 监控docker容器状态 and 企业微信报警机器人,第6张

ZABBIX告警通知
告警主机:{HOSTNAME1}
主机地址:{HOST.IP}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}
事件标识:{EVENT.ID}

ZABBIX告警恢复
告警主机:{HOSTNAME1}
主机地址:{HOST.IP}
告警时间:{EVENT.DATE} {EVENT.TIME}
恢复时间:{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}
事件ID:{EVENT.ID}

3.企业微信报警机器人
推荐如下干货文章:
https://www.fxkjnj.com/3157/

yum install python-requests

前端logo要改的话可以参考如下:
https://blog.csdn.net/weixin_43148683/article/details/123007425


https://www.xamrdz.com/lan/5kg1994739.html

相关文章: