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 ;有不懂的可以技术交流

相关推荐
G_whang19 分钟前
centos7下docker 容器实现redis主从同步
redis·docker·容器
认真学习的小雅兰.20 分钟前
如何在Ubuntu上利用Docker和Cpolar实现Excalidraw公网访问高效绘图——“cpolar内网穿透”
linux·ubuntu·docker
the丶only2 小时前
单点登录平台Casdoor搭建与使用,集成gitlab同步创建删除账号
linux·运维·服务器·docker·gitlab
书生-w2 小时前
Docker部署GitLab服务器
服务器·docker·gitlab
塔克拉玛攻城狮2 小时前
私有网盘+在线文档:内网离线搭建NextCloud+OnlyOffice详细指南
docker·在线文档·网盘
ccubee2 小时前
docker 安装 ftp
运维·docker·容器
TsengOnce4 小时前
Docker 安装 禅道-21.2版本-外部数据库模式
运维·docker·容器
无为扫地僧4 小时前
三、ubuntu18.04安装docker
ubuntu·docker
谷莠子9055 小时前
hadoop实验之创业有感
hadoop·docker·团队开发
G丶AEOM5 小时前
Docker快速入门
docker