安装zabbix +grafana
1、部署
mkdir -p /opt/zabbix/{data,backups}mkdir -p /opt/grafanasudo chown -R 472:472 /opt/grafanasudo chmod -R 755 /opt/grafanacat > docker-compose.yml <<-'EOF'
version: '3.3'services:mysql-server:image: mysql:8.1container_name: mysql-serverrestart: unless-stoppedenvironment:MYSQL_DATABASE: zabbixMYSQL_USER: zabbixMYSQL_PASSWORD: zabbix_pwdMYSQL_ROOT_PASSWORD: root_pwdTZ: Asia/Shanghaivolumes:- /opt/zabbix/data:/var/lib/mysqlnetworks:zabbix-net:ipv4_address: 172.20.0.2command: --character-set-server=utf8 --collation-server=utf8_bin --default-authentication-plugin=mysql_native_passwordzabbix-java-gateway:image: zabbix/zabbix-java-gateway:latestcontainer_name: zabbix-java-gatewayrestart: alwaysports:- "10052:10052"environment:TZ: Asia/Shanghainetworks:zabbix-net:ipv4_address: 172.20.0.3zabbix-server-mysql:image: zabbix/zabbix-server-mysql:latestcontainer_name: zabbix-server-mysqlrestart: unless-stoppedenvironment:DB_SERVER_HOST: mysql-serverMYSQL_DATABASE: zabbixMYSQL_USER: zabbixMYSQL_PASSWORD: zabbix_pwdMYSQL_ROOT_PASSWORD: root_pwdZBX_JAVAGATEWAY: zabbix-java-gatewayTZ: Asia/Shanghaiports:- "10051:10051"networks:zabbix-net:ipv4_address: 172.20.0.4zabbix-web-nginx-mysql:image: zabbix/zabbix-web-nginx-mysql:latestcontainer_name: zabbix-web-nginx-mysqlrestart: unless-stoppedenvironment:ZBX_SERVER_HOST: zabbix-server-mysqlDB_SERVER_HOST: mysql-serverMYSQL_DATABASE: zabbixMYSQL_USER: zabbixMYSQL_PASSWORD: zabbix_pwdMYSQL_ROOT_PASSWORD: root_pwdTZ: Asia/Shanghaiports:- "80:8080"networks:zabbix-net:ipv4_address: 172.20.0.5grafana:image: grafana/grafana:latestcontainer_name: grafanarestart: alwaysenvironment:TZ: Asia/Shanghaiports:- "3000:3000"volumes:- /opt/grafana:/var/lib/grafananetworks:zabbix-net:ipv4_address: 172.20.0.6networks:zabbix-net:driver: bridgeipam:config:- subnet: 172.20.0.0/24
EOF#备份mysql脚本
cat > /opt/zabbix/backups/backup_mysql.sh <<-'EOF'
#!/bin/bash# 获取当前日期
current_date=$(date +%Y%m%d_%H%M%S)# 获取容器的 IP 地址
ipname=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql-server)# 设置 MySQL 密码环境变量
export MYSQL_PWD=root_pwd# 执行备份命令
mysqldump -h $ipname -u root zabbix > /opt/zabbix/backups/zabbix_$current_date.sql# 检查备份是否成功
if [ $? -eq 0 ]; thenecho "Backup successful!"
elseecho "Backup failed!"
fi# 清理超过15天的备份文件
find /opt/zabbix/backups/ -type f -name 'zabbix_*.sql' -mtime +15 -exec rm {} \;
EOFchmod +x /opt/zabbix/backups/backup_mysql.sh# 定义要添加的任务
TASK="0 0 * * * /opt/zabbix/backups/backup_mysql.sh"# 添加新任务
(crontab -l; echo "$TASK") | crontab -crontab -l#部署
docker-compose up -d
安装备份工具,开放防火墙
yum install -y mariadb mariadb-server && yum clean allfirewall-cmd --zone=public --add-port=10052/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent#--重载
firewall-cmd --reload#--查询已经开放的端口
firewall-cmd --list-port#清除zabbix
docker stop mysql-server zabbix-server-mysql zabbix-web-nginx-mysql zabbix_agent zabbix-java-gateway grafanadocker rm mysql-server zabbix-server-mysql zabbix-web-nginx-mysql zabbix_agent zabbix-java-gateway grafana# 本机的agent 访问zabbix-server ,需要写 容器ip
# docker inspect zabbix-server-mysql |grep IPAdd
2、grafana安装插件
docker exec -it grafana bashgrafana-cli plugins install alexanderzobnin-zabbix-app# grafana-cli plugins install grafana-image-rendererdocker restart grafana
http://192.168.2.225:3000
admin/admin
添加zabbix服务端信息
开启zabbix模板
添加zabbix监控数据
下载喜欢的版本
https://grafana.com/grafana/dashboards/8677-servidores-linux/
修改为中文
xm:ren597634528 ;有不懂的可以技术交流