赞
踩
使用Docker Compose安装Zabbix的好处主要体现在以下几个方面:
总之,使用Docker Compose安装Zabbix可以简化部署过程,提高可扩展性和灵活性,同时提供版本控制和跨平台部署的优势。
安装docker请我参考我以往所发布的教程 安装docker教程 http://t.csdnimg.cn/CNcZf
sudo curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
mkdir -p /home/zabbix-server
cd /home/zabbix-server
mkdir -p ./mysql/data
#映射数据库数据目录
mkdir -p ./mysql/conf
#映射数据库配置文件
mkdir -p ./mysql/logs
#映射数据库日志文件
mkdir -p ./font
mkdir -p ./snmptraps
mkdir -p ./mibs
mkdir -p ./alertscripts
mkdir -p ./externalscripts
需进入/home/zabbix-server目录创建docker-compose.yml文件,环境变量可根据实际情况进行修改。
version: '3.8'
services:
mysql:
image: mysql:8.0
container_name: mysql
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/logs:/var/log/mysql
- /etc/localtime:/etc/localtime
restart: always
privileged: true
environment:
- MYSQL_ROOT_PASSWORD=myrootpassword
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=mypassword
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
command: --max_connections=800
expose:
- "3306"
networks:
zabbix-net:
command: --character-set-server=utf8 --collation-server=utf8_bin
zabbix-gateway:
image: zabbix/zabbix-java-gateway:6.0-centos-latest
container_name: zabbix-gateway
volumes:
- /etc/localtime:/etc/localtime
restart: always
privileged: true
ports:
- "10052:10052"
networks:
zabbix-net:
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:6.0-centos-latest
container_name: zabbix-snmptraps
volumes:
- /etc/localtime:/etc/localtime
- ./snmptraps:/var/lib/zabbix/snmptraps
- ./mibs:/var/lib/zabbix/mibs
restart: always
privileged: true
ports:
- "1162:1162/udp"
networks:
zabbix-net:
zabbix-server:
image: zabbix/zabbix-server-mysql:6.0-centos-latest
container_name: zabbix-server
volumes:
- /etc/localtime:/etc/localtime
- ./snmptraps:/var/lib/zabbix/snmptraps
- ./mibs:/var/lib/zabbix/mibs
- ./alertscripts:/usr/lib/zabbix/alertscripts
- ./externalscripts:/usr/lib/zabbix/externalscripts
restart: always
privileged: true
depends_on:
- mysql
environment:
- ZBX_LISTENPORT=10051
- DB_SERVER_HOST=mysql
- DB_SERVER_PORT=3306
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=mypassword
- MYSQL_ROOT_PASSWORD=myrootpassword
- ZBX_STARTPOLLERS=200
- ZBX_STARTPINGERS=32
- ZBX_STARTJAVAPOLLERS=1
- ZBX_STARTPOLLERSUNREACHABLE=20
- ZBX_STARTTRAPPERS=30
- ZBX_STARTHTTPPOLLERS=10
- ZBX_STARTVMWARECOLLECTORS=250
- ZBX_CACHESIZE=4G
- ZBX_HISTORYCACHESIZE=512M
- ZBX_HISTORYINDEXCACHESIZE=32M
- ZBX_TRENDCACHESIZE=256M
- ZBX_VALUECACHESIZE=256M
- ZBX_IPMIPOLLERS=1
- ZBX_ENABLE_SNMP_TRAPS=true
- ZBX_JAVAGATEWAY_ENABLE=true
- ZBX_JAVAGATEWAY=zabbix-gateway
- ZBX_VMWAREFREQUENCY=60
- ZBX_VMWAREPERFFREQUENCY=60
- ZBX_VMWARECACHESIZE=2G
- ZBX_TIMEOUT=30
- ZBX_VMWARETIMEOUT=120
ports:
- "10051:10051"
networks:
zabbix-net:
ipv4_address: 10.10.10.12
links:
- mysql
- zabbix-gateway
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:6.0-centos-latest
container_name: zabbix-web
volumes:
- ./font/simfang.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf
- /etc/localtime:/etc/localtime
restart: always
privileged: true
environment:
- ZBX_SERVER_NAME=Zabbix 6.0
- ZBX_SERVER_HOST=zabbix-server
- ZBX_SERVER_PORT=10051
- DB_SERVER_HOST=mysql
- DB_SERVER_PORT=3306
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=mypassword
- MYSQL_ROOT_PASSWORD=myrootpassword
- PHP_TZ=Asia/Shanghai
ports:
- "80:8080"
networks:
zabbix-net:
links:
- mysql
- zabbix-server
networks:
zabbix-net:
driver: bridge
ipam:
config:
- subnet: 10.10.10.0/24
gateway: 10.10.10.1
需要进入docker-compose.yml文件所在目录进行操作
cd /home/zabbix-server
docker-compose up -d #创建容器并启动服务,如果镜像不存在时,会自动下载镜像
docker-compose down #关闭整个项目并移除容器、移除网络、如果挂载数据卷后不会移除数据卷
docker-compose stop #停止容器服务
docker-compose start #启动容器服务
docker-compose restart #重启整个项目
docker-compose logs #查看容器日志
以上命令可以通过加服务名称管理指定的服务,比如docker-compose stop zabbix-server表示只停止zabbix-server容器
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。