一种可能的方法是使用 Docker 卷来保存 Zabbix 的配置文件,并在运行容器时将这个卷挂载到容器中。这样,你可以在不重新创建整个容器的情况下修改配置文件
用docker-compose部署zabbix,部署完后如果要修改zabbix的配置应该要改docker-compose文件里的环境变量吧?改了环境变量之后只能重建容器才能生效吗?有没有不影响已经配好的那些监控项的情况下让新的环境变量生效?
通过docker compose编排映射环境变量
```docker compose zabbix-server样例
zabbix-server:
build:
context: ./Dockerfiles/server-mysql/centos
cache_from:
- rockylinux:8
args:
BUILD_BASE_IMAGE: zabbix-build-mysql:rocky-6.0-latest
image: zabbix-server-mysql:rocky-6.0-latest
container_name: zbx-server-mysql
restart: always
profiles:
- make5
- make6
- start5
- start6
ports:
- "10051:10051"
volumes:
- /etc/localtime:/etc/localtime:rw
- /etc/timezone:/etc/timezone:rw
- ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:rw
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:rw
- ./zbx_env/var/lib/zabbix/export:/var/lib/zabbix/export:rw
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:rw
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:rw
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:rw
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:rw
- snmptraps:/var/lib/zabbix/snmptraps:rw
- /var/log/loki:/var/log/loki:rw
ulimits:
nproc: 655350
nofile:
soft: 655350
hard: 655350
deploy:
resources:
limits:
cpus: '0.80'
memory: 4G
reservations:
cpus: '0.8'
memory: 4G
env_file:
- ./env_vars/.env_db_mysql
- ./env_vars/.env_srv
secrets:
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_ROOT_USER
- MYSQL_ROOT_PASSWORD
# - client-key.pem
# - client-cert.pem
# - root-ca.pem
depends_on:
- mysql-server
- zabbix-build-mysql
networks:
zbx_net_backend:
aliases:
- zabbix-server
- zabbix-server-mysql
- zabbix-server-rocky-mysql
- zabbix-server-mysql-rocky
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 LLC"
com.zabbix.component: "zabbix-server"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "rocky"
```
```映射文件.env_srv文件样例
ZBX_LISTENIP="0.0.0.0"
# ZBX_LISTENBACKLOG=
# ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5
# ZBX_HISTORYSTORAGETYPES=uint,dbl,str,log,text # Available since 3.4.5
# ZBX_ALLOWUNSUPPORTEDDBVERSIONS=0 # Available since 6.0.0
# ZBX_DBTLSCONNECT=required # Available since 5.0.0
# ZBX_DBTLSCAFILE=/run/secrets/root-ca.pem # Available since 5.0.0
# ZBX_DBTLSCERTFILE=/run/secrets/client-cert.pem # Available since 5.0.0
# ZBX_DBTLSKEYFILE=/run/secrets/client-key.pem # Available since 5.0.0
# ZBX_DBTLSCIPHER= # Available since 5.0.0
# ZBX_DBTLSCIPHER13= # Available since 5.0.0
# ZBX_AUTOHANODENAME=fqdn # Allowed values: fqdn, hostname. Available since 6.0.0
# ZBX_HANODENAME= # Available since 6.0.0
# ZBX_AUTONODEADDRESS=fqdn # Allowed values: fqdn, hostname. Available since 6.0.0
# ZBX_NODEADDRESSPORT=10051 # Allowed to use with ZBX_AUTONODEADDRESS variable only. Available since 6.0.0
# ZBX_NODEADDRESS=localhost:10051 # Available since 6.0.0
# ZBX_DEBUGLEVEL=3
ZBX_STARTPOLLERS=100
ZBX_IPMIPOLLERS=100
ZBX_STARTPREPROCESSORS=100 # Available since 3.4.0
ZBX_STARTPOLLERSUNREACHABLE=100
ZBX_STARTTRAPPERS=100
ZBX_STARTPINGERS=100
ZBX_STARTDISCOVERERS=50
# ZBX_STARTHTTPPOLLERS=1
ZBX_STARTHISTORYPOLLERS=100 # Available since 5.4.0
ZBX_STARTTIMERS=100
# ZBX_STARTESCALATORS=1
# ZBX_STARTALERTERS=3 # Available since 3.4.0
ZBX_STARTLLDPROCESSORS=100
ZBX_JAVAGATEWAY_ENABLE=true
ZBX_JAVAGATEWAY=zabbix-java-gateway
ZBX_JAVAGATEWAYPORT=10052
ZBX_STARTJAVAPOLLERS=5
ZBX_STARTVMWARECOLLECTORS=100
# ZBX_VMWAREFREQUENCY=60
# ZBX_VMWAREPERFFREQUENCY=60
ZBX_VMWARECACHESIZE=2G
# ZBX_VMWARETIMEOUT=10
ZBX_ENABLE_SNMP_TRAPS=true
# ZBX_SOURCEIP=
ZBX_HOUSEKEEPINGFREQUENCY=0
# ZBX_MAXHOUSEKEEPERDELETE=5000
# ZBX_PROBLEMHOUSEKEEPINGFREQUENCY=60
# ZBX_SENDERFREQUENCY=30
ZBX_CACHESIZE=2G
# ZBX_CACHEUPDATEFREQUENCY=60
# ZBX_STARTDBSYNCERS=4
ZBX_HISTORYCACHESIZE=2G
ZBX_HISTORYINDEXCACHESIZE=2G
# ZBX_HISTORYSTORAGEDATEINDEX=0
ZBX_TRENDCACHESIZE=2G
ZBX_TRENDFUNCTIONCACHESIZE=512M
ZBX_VALUECACHESIZE=64G
ZBX_TIMEOUT=30
# ZBX_TRAPPERTIMEOUT=300
ZBX_UNREACHABLEPERIOD=270
ZBX_UNAVAILABLEDELAY=360
ZBX_UNREACHABLEDELAY=90
# ZBX_LOGSLOWQUERIES=3000
# ZBX_EXPORTFILESIZE=
ZBX_STARTPROXYPOLLERS=100
# ZBX_PROXYCONFIGFREQUENCY=3600
# ZBX_PROXYDATAFREQUENCY=1
# ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so"
# ZBX_TLSCAFILE=
# ZBX_TLSCRLFILE=
# ZBX_TLSCERTFILE=
# ZBX_TLSKEYFILE=
# ZBX_VAULTDBPATH=
# ZBX_VAULTURL=https://127.0.0.1:8200
# VAULT_TOKEN=
# ZBX_STARTREPORTWRITERS=0
# ZBX_WEBSERVICEURL=http://zabbix-web-service:10053/report
# ZBX_SERVICEMANAGERSYNCFREQUENCY=60
```
错误信息