安装zabbix +grafana

1、部署


mkdir -p /opt/zabbix/{data,backups}

mkdir -p /opt/grafana

sudo chown -R 472:472 /opt/grafana

sudo chmod -R 755 /opt/grafana


cat > docker-compose.yml <<-'EOF'
version: '3.3'

services:
  mysql-server:
    image: mysql:8.1
    container_name: mysql-server
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: zabbix
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix_pwd
      MYSQL_ROOT_PASSWORD: root_pwd
      TZ: Asia/Shanghai
    volumes:
      - /opt/zabbix/data:/var/lib/mysql
    networks:
      zabbix-net:
        ipv4_address: 172.20.0.2
    command: --character-set-server=utf8 --collation-server=utf8_bin --default-authentication-plugin=mysql_native_password

  zabbix-java-gateway:
    image: zabbix/zabbix-java-gateway:latest
    container_name: zabbix-java-gateway
    restart: always
    ports:
      - "10052:10052"
    environment:
      TZ: Asia/Shanghai
    networks:
      zabbix-net:
        ipv4_address: 172.20.0.3

  zabbix-server-mysql:
    image: zabbix/zabbix-server-mysql:latest
    container_name: zabbix-server-mysql
    restart: unless-stopped
    environment:
      DB_SERVER_HOST: mysql-server
      MYSQL_DATABASE: zabbix
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix_pwd
      MYSQL_ROOT_PASSWORD: root_pwd
      ZBX_JAVAGATEWAY: zabbix-java-gateway
      TZ: Asia/Shanghai
    ports:
      - "10051:10051"
    networks:
      zabbix-net:
        ipv4_address: 172.20.0.4

  zabbix-web-nginx-mysql:
    image: zabbix/zabbix-web-nginx-mysql:latest
    container_name: zabbix-web-nginx-mysql
    restart: unless-stopped
    environment:
      ZBX_SERVER_HOST: zabbix-server-mysql
      DB_SERVER_HOST: mysql-server
      MYSQL_DATABASE: zabbix
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix_pwd
      MYSQL_ROOT_PASSWORD: root_pwd
      TZ: Asia/Shanghai
    ports:
      - "80:8080"
    networks:
      zabbix-net:
        ipv4_address: 172.20.0.5

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: always
    environment:
      TZ: Asia/Shanghai
    ports:
      - "3000:3000"
    volumes:
      - /opt/grafana:/var/lib/grafana
    networks:
      zabbix-net:
        ipv4_address: 172.20.0.6

networks:
  zabbix-net:
    driver: bridge
    ipam:
      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 ]; then
    echo "Backup successful!"
else
    echo "Backup failed!"
fi

# 清理超过15天的备份文件
find /opt/zabbix/backups/ -type f -name 'zabbix_*.sql' -mtime +15 -exec rm {} \;
EOF



chmod +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 all


firewall-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 grafana

docker 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 bash

grafana-cli plugins install alexanderzobnin-zabbix-app


# grafana-cli plugins install grafana-image-renderer

docker restart grafana

http://192.168.2.225:3000

admin/admin

添加zabbix服务端信息

开启zabbix模板

添加zabbix监控数据

下载喜欢的版本

https://grafana.com/grafana/dashboards/8677-servidores-linux/

在这里插入图片描述

修改为中文

在这里插入图片描述

xm:ren597634528 ;有不懂的可以技术交流

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部