docker-compose部署zabbix-5.0

648次阅读
没有评论
docker-compose 部署 zabbix-5.0

Table of Contents

前言

之前部署 zabbix 都是直接安装前后台,再加上 nginx、php。今天突然想把 zabbix 容器化部署。

官方提供了 docker 镜像,我简单写了一个 docker-compose.yaml,用了一下,没什么问题

代码

version: "3.3"
services:
  zabbix-server:
    image: zabbix/zabbix-server-mysql:5.0-centos-latest
    restart: always
    ports:
      - "10051:10051"
    environment:
      DB_SERVER_HOST: 10.0.0.1
      MYSQL_USER: zabbix
      MYSQL_DATABASE: zabbix
      MYSQL_PASSWORD: Zabbix
    volumes:
      - /usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts
  zabbix-web:
    image: zabbix/zabbix-web-nginx-mysql:5.0-centos-latest
    ports:
      - "80:8080"
    restart: always
    environment:
      DB_SERVER_HOST: 10.0.0.1
      MYSQL_USER: zabbix
      MYSQL_DATABASE: zabbix
      MYSQL_PASSWORD: Zabbix
      ZBX_SERVER_HOST: zabbix-server
    dns:
      - 8.8.8.8
      - 8.8.4.4

解析

解释几个参数

#mysql 的 ip
DB_SERVER_HOST: 10.0.0.1

#mysql 用户
MYSQL_USER: zabbix

#mysql 库名
MYSQL_DATABASE: zabbix

#mysql 密码
MYSQL_PASSWORD: Zabbix

#zabbix-server 的地址
ZBX_SERVER_HOST:zabbix-server

我这里是采用的 mysql 和 zabbix 不在同一服务器上,在 zabbix 官网看了看,官方没有提供容器化的 mysql,有初始化脚本可以自己打一个 mysql 镜像,我这里没需求暂时不打了。

建库脚本

# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;

附上 zabbix-5.0 的 mysql 初始化 sql 脚本

https://fastyw.com/wp-content/uploads/2022/12/zabbix-mysql-5.zip

补一个带 mysql 的

version: "3.3"
services:
  zabbix-server:
    image: zabbix/zabbix-server-mysql:5.0-centos-latest
    restart: always
    depends_on:
      - db
    ports:
      - "10051:10051"
    environment:
      DB_SERVER_HOST: db
      MYSQL_USER: zabbix
      MYSQL_DATABASE: zabbix
      MYSQL_PASSWORD: Zabbix
    volumes:
      - /usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts
  zabbix-web:
    image: zabbix/zabbix-web-nginx-mysql:5.0-centos-latest
    ports:
      - "80:8080"
    depends_on:
      - db
    restart: always
    environment:
      DB_SERVER_HOST: db
      MYSQL_USER: zabbix
      MYSQL_DATABASE: zabbix
      MYSQL_PASSWORD: Zabbix
      ZBX_SERVER_HOST: zabbix-server
    dns:
      - 8.8.8.8
      - 8.8.4.4
  db:
    image: mysql
    restart: always
    privileged: true
    volumes:
      - /root/sql:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: zabbix
      MYSQL_DATABASE: zabbix
      MYSQL_USER: zabbix
      MYSQL_PASSWORD: zabbix
正文完
 
评论(没有评论)