使用Docker部署Zabbix
使用docker-compose部署zabbix监控平台
官方仓库:
https://github.com/zabbix/zabbix-docker
本次部署使用docker镜像为Ubuntu-6.0-latest
这里我对官方仓库的yaml做了一些修改,去掉了我不需要的proxy以及其他功能
参考:
https://juejin.cn/post/7085020149761179661
https://cloud.tencent.com/developer/article/1857679
安装或升级docker-compose
系统 debian11.7
系统官方源中还是docker-compose v1.25.0
执行zabbix-docker官方的yaml会有报错
1 | ERROR: The Compose file './docker-compose.yaml' is invalid because: |
安装docker-compose
卸载旧版本docker-compose
安装现在最新版本docker-compose
1 | wget https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-x86_64 |
执行docker-compose -v
查看版本
编辑docker-compose.yaml来部署服务
下载zabbix-docker配置文件
1 | wget https://github.com/zabbix/zabbix-docker/archive/refs/tags/6.0.21.zip |
编辑yaml文件
进入解压后的文件夹
建议先做好备份
1 | mv docker-compose_v3_ubuntu_mysql_latest.yaml docker-compose.yaml |
- 修改
docker-compose.yaml
yaml中很多环境配置在1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237version: '3.5'
services:
zabbix-server:
image: zabbix/zabbix-server-mysql:ubuntu-6.0-latest
ports:
- "10051:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
# - dbsocket:/var/run/mysqld/
- /data/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
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_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
networks:
zbx_net_backend:
aliases:
- zabbix-server
- zabbix-server-mysql
- zabbix-server-ubuntu-mysql
- zabbix-server-mysql-ubuntu
zbx_net_frontend:
# devices:
# - "/dev/ttyUSB0:/dev/ttyUSB0"
stop_grace_period: 30s
sysctls:
- net.ipv4.ip_local_port_range=1024 64999
- 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: "ubuntu"
zabbix-web-nginx-mysql:
image: zabbix/zabbix-web-nginx-mysql:ubuntu-6.0-latest
ports:
- "8081:8080"
- "8443:8443"
volumes:
- /etc/localtime:/etc/localtime:ro
# - dbsocket:/var/run/mysqld/
- ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
- ./zbx_env/usr/share/zabbix/modules/:/usr/share/zabbix/modules/:ro
deploy:
resources:
limits:
cpus: '0.70'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
env_file:
- ./env_vars/.env_db_mysql
- ./env_vars/.env_web
secrets:
- MYSQL_USER
- MYSQL_PASSWORD
# - client-key.pem
# - client-cert.pem
# - root-ca.pem
depends_on:
- mysql-server
- zabbix-server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/ping"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
zbx_net_backend:
aliases:
- zabbix-web-nginx-mysql
- zabbix-web-nginx-ubuntu-mysql
- zabbix-web-nginx-mysql-ubuntu
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 LLC"
com.zabbix.component: "zabbix-frontend"
com.zabbix.webserver: "nginx"
com.zabbix.dbtype: "mysql"
com.zabbix.os: "ubuntu"
zabbix-web-service:
image: zabbix/zabbix-web-service:ubuntu-6.0-latest
profiles:
- full
- all
ports:
- "10053:10053"
volumes:
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
security_opt:
- seccomp:./env_vars/chrome_dp.json
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
env_file:
- ./env_vars/.env_web_service
networks:
zbx_net_backend:
aliases:
- zabbix-web-service
- zabbix-web-service-ubuntu
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix web service"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "web-service"
com.zabbix.os: "ubuntu"
mysql-server:
image: mysql:8.0.23
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
command:
- mysqld
- --character-set-server=utf8
- --collation-server=utf8_bin
- --default-authentication-plugin=mysql_native_password
# - --require-secure-transport
# - --ssl-ca=/run/secrets/root-ca.pem
# - --ssl-cert=/run/secrets/server-cert.pem
# - --ssl-key=/run/secrets/server-key.pem
volumes:
- /etc/localtime:/etc/localtime:ro
- /data/docker/zabbix/mysql/db:/var/lib/mysql:rw
# - dbsocket:/var/run/mysqld/
env_file:
- ./env_vars/.env_db_mysql
secrets:
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_ROOT_PASSWORD
# - server-key.pem
# - server-cert.pem
# - root-ca.pem
stop_grace_period: 1m
networks:
zbx_net_backend:
aliases:
- mysql-server
- zabbix-database
- mysql-database
# elasticsearch:
# image: elasticsearch
# profiles:
# - full
# - all
# environment:
# - transport.host=0.0.0.0
# - discovery.zen.minimum_master_nodes=1
# networks:
# zbx_net_backend:
# aliases:
# - elasticsearch
networks:
zbx_net_frontend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.16.248.0/24
zbx_net_backend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
internal: true
ipam:
driver: default
config:
- subnet: 172.16.249.0/24
volumes:
snmptraps:
# dbsocket:
secrets:
MYSQL_USER:
file: ./env_vars/.MYSQL_USER
MYSQL_PASSWORD:
file: ./env_vars/.MYSQL_PASSWORD
MYSQL_ROOT_USER:
file: ./env_vars/.MYSQL_ROOT_USER
MYSQL_ROOT_PASSWORD:
file: ./env_vars/.MYSQL_ROOT_PASSWORD
# client-key.pem:
# file: ./env_vars/.ZBX_DB_KEY_FILE
# client-cert.pem:
# file: ./env_vars/.ZBX_DB_CERT_FILE
# root-ca.pem:
# file: ./env_vars/.ZBX_DB_CA_FILE
# server-cert.pem:
# file: ./env_vars/.DB_CERT_FILE
# server-key.pem:
# file: ./env_vars/.DB_KEY_FILEenv_vars
下
比如
1 | MYSQL用户密码以及ROOT用户密码设置 .MYSQL_PASSWORD .MYSQL_ROOT_PASSWORD .MYSQL_ROOT_USER .MYSQL_USER |
- 根据
docker-compose.yaml
中的映射目录来创建目录zabbix图形定义的字体不支持中文,所以需要上传中文字体代替1
2cd /data/docker/zabbix
mkdir alertscripts fonts mysql/db -p
方法很多,网上随便找一个即可
1 | sudo apt install ttf-wqy-microhei |
- 运行docker-compose.yaml
在docker-compose.yaml
目录下执行1
sudo docker-compose up -d
部署完成
数据库启动可能较慢,刚部署完访问zabbix可能会提示数据库出错,等待一会刷新页面即可进入登陆页面。