docker安装zabbix +grafana

安装zabbix +grafana

1、部署

shell 复制代码
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

安装备份工具,开放防火墙

shell 复制代码
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安装插件

plain 复制代码
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 ;有不懂的可以技术交流

相关推荐
xiangshangdemayi1 小时前
Windows环境GeoServer打包Docker极速入门
windows·docker·容器·geoserver·打包·数据挂载
程序员JerrySUN2 小时前
熟悉的 Docker,陌生的 Podman
linux·docker·容器·系统架构·podman
gobeyye2 小时前
Docker 用法详解
运维·docker·容器
小灰灰__3 小时前
Linux离线安装Docker命令,简单镜像操作
linux·docker·eureka
雪碧聊技术4 小时前
Docker3:docker基础1
运维·docker·容器·docker常见命令
wsxlgg7 小时前
docker搭建jpom
docker
FLGB7 小时前
Docker 安装单机版mysql 并持久化数据
mysql·docker·容器
杰哥的技术杂货铺8 小时前
Centos 7 安装 Docker 最新版本
linux·docker·centos
moxiaoran57539 小时前
Centos使用docker搭建Graylog日志平台
docker·centos·graylog