目 录
[隐藏]

使用 Docker 搭建 Zabbix Server

1.Pull Images

##
#  拉取镜像

docker pull zabbix/zabbix-server-mysql:centos-4.0-latest

docker pull zabbix/zabbix-web-nginx-mysql:centos-4.0-latest

docker pull mysql:5.7

docker pull zabbix/zabbix-agent:centos-4.0-latest

2.Docker-compose

## 
#  zabbix-centos-docker-compose.yml

version: '3.5'
services:
##
# 
 zabbix-server:
  image: zabbix/zabbix-server-mysql:centos-4.0-latest
  container_name: "zabbix-server"
  ports:
   - "10051:10051"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - /etc/timezone:/etc/timezone:ro
   - ./zbx_env/zabbix-server/usr/lib/zabbix:/usr/lib/zabbix:rw
   - ./zbx_env/zabbix-server/var/lib/zabbix:/var/lib/zabbix:rw
  links:
   - mysql-server:mysql-server
   # - zabbix-java-gateway:zabbix-java-gateway
  ulimits:
   nproc: 65535
   nofile:
    soft: 20000
    hard: 40000
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 1G
    reservations:
      cpus: '0.5'
      memory: 512M
  env_file:
   - .env_db_mysql
   - .env_srv
  user: root
  depends_on:
   - mysql-server
   # - zabbix-java-gateway
   # - zabbix-snmptraps
  networks:
   zbx_net_backend:
     aliases:
      - zabbix-server
      - zabbix-server-mysql
      - zabbix-server-centos-mysql
      - zabbix-server-mysql-centos
   zbx_net_frontend:
#  devices:
#   - "/dev/ttyUSB0:/dev/ttyUSB0"
  stop_grace_period: 30s
  sysctls:
   - net.ipv4.ip_local_port_range=1024 65000
   - net.ipv4.conf.all.accept_redirects=0
   - net.ipv4.conf.all.secure_redirects=0
   - net.ipv4.conf.all.send_redirects=0
  labels:
   com.zabbix.description: "Zabbix server with MySQL database support"
   com.zabbix.company: "Zabbix SIA"
   com.zabbix.component: "zabbix-server"
   com.zabbix.dbtype: "mysql"
   com.zabbix.os: "centos"

##
# 
 zabbix-web-nginx-mysql:
  image: zabbix/zabbix-web-nginx-mysql:centos-4.0-latest
  container_name: "zabbix-web-nginx-mysql"
  ports:
   - "8081:80"
   - "8443:443"
  links:
   - mysql-server:mysql-server
   - zabbix-server:zabbix-server
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - /etc/timezone:/etc/timezone:ro
   - ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
  deploy:
   resources:
    limits:
      cpus: '0.70'
      memory: 512M
    reservations:
      cpus: '0.5'
      memory: 256M
  env_file:
   - .env_db_mysql
   - .env_web
  user: root
  depends_on:
   - mysql-server
   - zabbix-server
  healthcheck:
   test: ["CMD", "curl", "-f", "http://localhost"]
   interval: 10s
   timeout: 5s
   retries: 3
   start_period: 30s
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-web-nginx-mysql
     - zabbix-web-nginx-centos-mysql
     - zabbix-web-nginx-mysql-centos
   zbx_net_frontend:
  stop_grace_period: 10s
  sysctls:
   - net.core.somaxconn=65535
  labels:
   com.zabbix.description: "Zabbix frontend on Nginx web-server with MySQL database support"
   com.zabbix.company: "Zabbix SIA"
   com.zabbix.component: "zabbix-frontend"
   com.zabbix.webserver: "nginx"
   com.zabbix.dbtype: "mysql"
   com.zabbix.os: "centos"

##
#  
 zabbix-agent:
  image: zabbix/zabbix-agent:centos-4.0-latest
  container_name: "zabbix-agent"
  ports:
   - "10050:10050"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - /etc/timezone:/etc/timezone:ro
   - ./zbx_env/zabbix-agent/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:rw
   - ./zbx_env/zabbix-agent/var/lib/zabbix:/var/lib/zabbix:rw
  links:
   - zabbix-server:zabbix-server
  deploy:
   resources:
    limits:
      cpus: '0.2'
      memory: 128M
    reservations:
      cpus: '0.1'
      memory: 64M
   mode: global
  env_file:
   - .env_agent
  user: root
  privileged: true
  pid: "host"
  networks:
   zbx_net_backend:
    aliases:
     - zabbix-agent
     - zabbix-agent-passive
     - zabbix-agent-centos
  stop_grace_period: 5s
  labels:
   com.zabbix.description: "Zabbix agent"
   com.zabbix.company: "Zabbix SIA"
   com.zabbix.component: "zabbix-agentd"
   com.zabbix.os: "centos"


##
# 
 mysql-server:
  image: mysql:5.7
  container_name: "mysql-server"
  command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin]
  volumes:
   - ./zbx_env/mysql/var/lib/mysql:/var/lib/mysql:rw
  env_file:
   - .env_db_mysql
  user: root
  stop_grace_period: 1m
  networks:
   zbx_net_backend:
    aliases:
     - mysql-server
     - zabbix-database
     - mysql-database

##
# 
networks:
  zbx_net_frontend:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
  zbx_net_backend:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"
    internal: true
    ipam:
      driver: default
      config:
      - subnet: 172.16.239.0/24

3.Environment File

##
#  .env_srv

# ZBX_LISTENIP=
# ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5
# ZBX_HISTORYSTORAGETYPES=uint,dbl,str,log,text # Available since 3.4.5
# ZBX_HISTORYSTORAGEDATEINDEX=0 # Available since 4.0.0
# ZBX_DEBUGLEVEL=3
# ZBX_STARTPOLLERS=5
# ZBX_IPMIPOLLERS=0
# ZBX_STARTPREPROCESSORS=3 # Available since 3.4.0
# ZBX_STARTPOLLERSUNREACHABLE=1
# ZBX_STARTTRAPPERS=5
# ZBX_STARTPINGERS=1
# ZBX_STARTDISCOVERERS=1
# ZBX_STARTHTTPPOLLERS=1
# ZBX_STARTTIMERS=1
# ZBX_STARTESCALATORS=1
# ZBX_STARTALERTERS=3 # Available since 3.4.0
# ZBX_JAVAGATEWAY_ENABLE=true
# ZBX_JAVAGATEWAY=zabbix-java-gateway
# ZBX_JAVAGATEWAYPORT=10052
# ZBX_STARTJAVAPOLLERS=5
# ZBX_STARTVMWARECOLLECTORS=0
# ZBX_VMWAREFREQUENCY=60
# ZBX_VMWAREPERFFREQUENCY=60
# ZBX_VMWARECACHESIZE=8M
# ZBX_VMWARETIMEOUT=10
# ZBX_ENABLE_SNMP_TRAPS=true
# ZBX_SOURCEIP=
# ZBX_HOUSEKEEPINGFREQUENCY=1
# ZBX_MAXHOUSEKEEPERDELETE=5000
# ZBX_SENDERFREQUENCY=30
# ZBX_CACHESIZE=8M
# ZBX_CACHEUPDATEFREQUENCY=60
# ZBX_STARTDBSYNCERS=4
# ZBX_HISTORYCACHESIZE=16M
# ZBX_HISTORYINDEXCACHESIZE=4M
# ZBX_TRENDCACHESIZE=4M
# ZBX_VALUECACHESIZE=8M
# ZBX_TIMEOUT=4
# ZBX_TRAPPERIMEOUT=300
# ZBX_UNREACHABLEPERIOD=45
# ZBX_UNAVAILABLEDELAY=60
# ZBX_UNREACHABLEDELAY=15
# ZBX_LOGSLOWQUERIES=3000
# ZBX_STARTPROXYPOLLERS=1
# ZBX_PROXYCONFIGFREQUENCY=3600
# ZBX_PROXYDATAFREQUENCY=1
# ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so"
# ZBX_TLSCAFILE=
# ZBX_TLSCRLFILE=
# ZBX_TLSCERTFILE=
# ZBX_TLSKEYFILE=


[为隐藏内容,请登录(login)以显示!]

4.Docker-compose Up

[root@ec-a zabbix]# docker-compose -f zabbix-centos-docker-compose.yml up -d
WARNING: Some services (zabbix-agent, zabbix-server, zabbix-web-nginx-mysql) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Creating mysql-server ... done
Creating zabbix-server ... done
Creating zabbix-agent           ... done
Creating zabbix-web-nginx-mysql ... done
[root@ec-a zabbix]# docker ps
CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS                   PORTS                                         NAMES
8697ce20460e        zabbix/zabbix-web-nginx-mysql:centos-4.0-latest   "docker-entrypoint.sh"   2 minutes ago       Up 2 minutes (healthy)   0.0.0.0:8081->80/tcp, 0.0.0.0:8443->443/tcp   zabbix-web-nginx-mysql
acd1ff52d86d        zabbix/zabbix-agent:centos-4.0-latest             "docker-entrypoint.sh"   2 minutes ago       Up 2 minutes                                                           zabbix-agent
303b709c046a        zabbix/zabbix-server-mysql:centos-4.0-latest      "docker-entrypoint.sh"   2 minutes ago       Up 2 minutes             0.0.0.0:10051->10051/tcp                      zabbix-server
465e8317fad1        mysql:5.7                                         "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes                                                           mysql-serve

5.Zabbix-Web

在浏览器中打开 http://localhost:8081/

localhost 为 Zabbix-server 宿主机 IP

Sign in

默认账号的用户名、密码是:
Admin 和 zabbix,输入用户名密码登录,即可看到主界面。

添加本机到Hosts

Configuration – Hosts
DNS name
ZBX
Monitoring – Dashboard

6.Tips


[为隐藏内容,请登录(login)以显示!]

参考资料:
https://github.com/zabbix/zabbix-docker
https://www.zabbix.com/documentation/4.0