zabbix5.0部署 and 監(jiān)控docker容器狀態(tài) and 配置企業(yè)微信報警機器人
1.系統(tǒng)優(yōu)化
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 前端和相關(guān)環(huán)境
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
安裝mysql8.0.20版本
軟件包下載地址:
先去網(wǎng)站下載
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;
創(chuàng)建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;
導(dǎo)入zabbix數(shù)據(jù)
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
修改 zabbix server 配置文件vi /etc/zabbix/zabbix_server.conf 里的數(shù)據(jù)庫密碼
DBPassword=password
修改 zabbix 的 php 配置文件vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 里的時區(qū),改成 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
加權(quán)
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
測試監(jiān)控數(shù)據(jù)
zabbix_get -s '192.168.124.10' -p 10050 -k 'agent.ping'
zabbix_get -s '192.168.124.10' -p 10050 -k docker.info
更新docker模板中的 監(jiān)控觸發(fā)條件 and 觸發(fā)時間
docker測試 stop任何一個容器 檢查是否報警
ZABBIX告警通知
告警主機:{HOSTNAME1}
主機地址:{HOST.IP}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警項目:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態(tài):{TRIGGER.STATUS}
事件標識:{EVENT.ID}
ZABBIX告警恢復(fù)
告警主機:{HOSTNAME1}
主機地址:{HOST.IP}
告警時間:{EVENT.DATE} {EVENT.TIME}
恢復(fù)時間:{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}
告警等級:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警項目:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
當前狀態(tài):{TRIGGER.STATUS}
事件ID:{EVENT.ID}
3.企業(yè)微信報警機器人
推薦如下干貨文章:
https://www.fxkjnj.com/3157/
yum install python-requests
前端logo要改的話可以參考如下:
https://blog.csdn.net/weixin_43148683/article/details/123007425