容器:Docker
Docker 容器

  1. yum install -y docker
  2. systemctl start docker
  3. systemctl enable docker

镜像准备

拉取镜像

Zabbix 官方镜像

MySQL

  1. docker pull mysql:8.0

Server

Zabbix-Server 镜像分两种:支持 MySQL 数据库的 zabbix-server-mysql 和支持 PostgreSQL 数据库的 zabbix-server-pgsql

  1. docker pull zabbix/zabbix-server-mysql:latest

Web

官方共有五种,习惯性使用 Nginx,所以选择 zabbix-web-nginx-mysql

  1. docker pull zabbix/zabbix-web-nginx-mysql:latest

Java Gateway(选配)

Zabbix 默认不支持 Java,需要安装 zabbix-java-gateway 来监控 JVM/Tomcat 的性能,按需选配

  1. docker pull zabbix/zabbix-java-gateway:latest

构建镜像(进阶)

运行镜像

分批启动

  1. docker network create -d bridge zabbix_net
  2. docker network ls
  1. docker run --name zabbix-mysql -dit \
  2. -p 13306:3306 \
  3. --restart=always \
  4. --network zabbix_net \
  5. -e MYSQL_DATABASE="zabbix" \
  6. -e MYSQL_USER="zabbix" \
  7. -e MYSQL_PASSWORD="zabbix1@#$" \
  8. -e MYSQL_ROOT_PASSWORD="root_1@#$" \
  9. --character-set-server=utf8 --collation-server=utf8_bin
  10. -v /data/zabbix/mysql:/var/lib/mysql \
  11. -v /etc/localtime:/etc/localtime \
  12. mysql:8.0 \
  1. docker run --name zabbix-java-gateway -dit \
  2. --restart always \
  3. --network=zabbix_net \
  4. zabbix/zabbix-java-gateway:latest
  1. docker run --name zabbix-server-mysql -dit \
  2. -p 10051:10051 \
  3. --restart always \
  4. --network=zabbix_net \
  5. -e DB_SERVER_HOST="zabbix-mysql" \
  6. -e MYSQL_DATABASE="zabbix" \
  7. -e MYSQL_USER="zabbix" \
  8. -e MYSQL_PASSWORD="zabbix1@#$" \
  9. -e MYSQL_ROOT_PASSWORD="root_1@#$" \
  10. -e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
  11. zabbix/zabbix-server-mysql:latest
  1. docker run --name zabbix-web-nginx-mysql -dit \
  2. -p 80:8080 \
  3. --restart always \
  4. --network=zabbix_net \
  5. -e ZBX_SERVER_HOST="zabbix-server-mysql" \
  6. -e DB_SERVER_HOST="zabbix-mysql" \
  7. -e MYSQL_DATABASE="zabbix" \
  8. -e MYSQL_USER="zabbix" \
  9. -e MYSQL_PASSWORD="zabbix1@#$" \
  10. -e MYSQL_ROOT_PASSWORD="root_1@#$" \
  11. zabbix/zabbix-web-nginx-mysql:latest

批量启动

  1. yum install -y docker-compose
  2. vim zibbix-docker.yml
  3. docker-compose up -d
  4. docker ps
  1. version: "3"
  2. services:
  3. mysql-server:
  4. image: mysql:8.0
  5. container_name: zabbix-mysql
  6. environment:
  7. - MYSQL_DATABASE=zabbix
  8. - MYSQL_USER=zabbix
  9. - MYSQL_PASSWORD=zabbix1@#$
  10. - MYSQL_ROOT_PASSWORD=roo_1@#$
  11. ports:
  12. - 13306:3306
  13. volumes:
  14. - /data/zabbix/mysql:/var/lib/mysql
  15. command:
  16. --character-set-server=utf8
  17. --collation-server=utf8_bin
  18. zabbix-server-mysql:
  19. image: zabbix/zabbix-server-mysql:latest
  20. container_name: zabbix-server-mysql
  21. environment:
  22. - DB_SERVER_HOST=zabbix-mysql
  23. - MYSQL_USER=zabbix
  24. - MYSQL_PASSWORD=zabbix1@#$
  25. - MYSQL_DATABASE=zabbix
  26. - MYSQL_ROOT_PASSWORD=root_1@#$
  27. ports:
  28. - 10051:10051
  29. links:
  30. - zabbix-mysql:mysql
  31. depends_on:
  32. - zabbix-mysql
  33. volumes:
  34. - /etc/localtime:/etc/localtime
  35. - /data/zabbix/etc/zabbix:/etc/zabbix
  36. - /data/zabbix/alertscripts:/usr/lib/zabbix/alertscripts
  37. zabbix-web:
  38. image: zabbix/zabbix-web-nginx-mysql:latest
  39. environment:
  40. - DB_SERVER_HOST=mysql-server
  41. - MYSQL_USER=zabbix
  42. - MYSQL_PASSWORD=zabbix1@#$
  43. - MYSQL_DATABASE=zabbix
  44. - MYSQL_ROOT_PASSWORD=roo_1@#$
  45. ports:
  46. - 80:80
  47. volumes:
  48. - /etc/localtime:/etc/localtime
  49. links:
  50. - zabbix-mysql:mysql
  51. - zabbix-server-mysql:zabbix-server
  52. depends_on:
  53. - zabbix-mysql
  54. - zabbix-server-mysql

监控实践