-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzabbix-traefik-letsencrypt-docker-swarm.yml
280 lines (258 loc) · 8.76 KB
/
zabbix-traefik-letsencrypt-docker-swarm.yml
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# Zabbix with Let's Encrypt in a Docker Swarm
# Install Docker Swarm by following my guide: https://www.heyvaldemar.com/install-docker-swarm-on-ubuntu-server/
# Configure Traefik and create secrets for storing the passwords on the Docker Swarm manager node before applying the configuration.
# Traefik configuration: https://github.com/heyValdemar/traefik-letsencrypt-docker-swarm
# Create a secret for storing the password for Zabbix database using the command:
# printf "YourPassword" | docker secret create zabbix-postgres-password -
# Clear passwords from bash history using the command:
# history -c && history -w
# Run zabbix-restore-database.sh on the Docker Swarm node where the container for backups is running to restore database if needed.
# Run docker stack ps zabbix | grep zabbix_backups | awk 'NR > 0 {print $4}' on the Docker Swarm manager node to find on which node container for backups is running.
# Deploy Zabbix in a Docker Swarm using the command:
# docker stack deploy -c zabbix-traefik-letsencrypt-docker-swarm.yml zabbix
# Author
# I’m Vladimir Mikhalev, the Docker Captain, but my friends can call me Valdemar.
# https://www.docker.com/captains/vladimir-mikhalev/
# My website with detailed IT guides: https://www.heyvaldemar.com/
# Follow me on YouTube: https://www.youtube.com/channel/UCf85kQ0u1sYTTTyKVpxrlyQ?sub_confirmation=1
# Follow me on Twitter: https://twitter.com/heyValdemar
# Follow me on Instagram: https://www.instagram.com/heyvaldemar/
# Follow me on Threads: https://www.threads.net/@heyvaldemar
# Follow me on Mastodon: https://mastodon.social/@heyvaldemar
# Follow me on Bluesky: https://bsky.app/profile/heyvaldemar.bsky.social
# Follow me on Facebook: https://www.facebook.com/heyValdemarFB/
# Follow me on TikTok: https://www.tiktok.com/@heyvaldemar
# Follow me on LinkedIn: https://www.linkedin.com/in/heyvaldemar/
# Follow me on GitHub: https://github.com/heyvaldemar
# Communication
# Chat with IT pros on Discord: https://discord.gg/AJQGCCBcqf
# Reach me at [email protected]
# Give Thanks
# Support on GitHub: https://github.com/sponsors/heyValdemar
# Support on Patreon: https://www.patreon.com/heyValdemar
# Support on BuyMeaCoffee: https://www.buymeacoffee.com/heyValdemar
# Support on Ko-fi: https://ko-fi.com/heyValdemar
# Support on PayPal: https://www.paypal.com/paypalme/heyValdemarCOM
version: '3.8'
x-default-opts:
&default-opts
logging:
options:
max-size: "10m"
networks:
zabbix-network:
driver: overlay
traefik-network:
external: true
volumes:
zabbix-postgres:
zabbix-postgres-backups:
secrets:
zabbix-postgres-password:
external: true
services:
postgres:
<<: *default-opts
# Image tag (replace with yours)
image: postgres:14
volumes:
- zabbix-postgres:/var/lib/postgresql/data
environment:
# Database name (replace with yours)
POSTGRES_DB: zabbixdb
# Database user (replace with yours)
POSTGRES_USER: zabbixdbuser
POSTGRES_PASSWORD_FILE: /run/secrets/zabbix-postgres-password
networks:
- zabbix-network
secrets:
- zabbix-postgres-password
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -h 127.0.0.1"]
interval: 10s
timeout: 5s
retries: 3
start_period: 60s
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
# Container resources (replace with yours)
resources:
limits:
cpus: '0.55'
memory: 1G
reservations:
cpus: '0.35'
memory: 1G
zabbix:
<<: *default-opts
# Image tag (replace with yours)
image: zabbix/zabbix-server-pgsql:6.2.0-ubuntu
environment:
DB_SERVER_HOST: postgres
DB_SERVER_PORT: 5432
# Database name (replace with yours)
POSTGRES_DB: zabbixdb
# Database user (replace with yours)
POSTGRES_USER: zabbixdbuser
POSTGRES_PASSWORD_FILE: /run/secrets/zabbix-postgres-password
ZBX_VALUECACHESIZE: 64M
ZBX_CACHESIZE: 128M
ZBX_TRENDCACHESIZE: 128M
networks:
- zabbix-network
ports:
- "10051:10051"
secrets:
- zabbix-postgres-password
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
# Container resources (replace with yours)
resources:
limits:
cpus: '1.75'
memory: 8G
reservations:
cpus: '1.35'
memory: 4G
depends_on:
- postgres
web:
<<: *default-opts
# Image tag (replace with yours)
image: zabbix/zabbix-web-nginx-pgsql:6.2.0-ubuntu
environment:
DB_SERVER_HOST: postgres
DB_SERVER_PORT: 5432
# Database name (replace with yours)
POSTGRES_DB: zabbixdb
# Database user (replace with yours)
POSTGRES_USER: zabbixdbuser
POSTGRES_PASSWORD_FILE: /run/secrets/zabbix-postgres-password
ZBX_SERVER_HOST: zabbix
ZBX_SERVER_PORT: 10051
# Timezone (replace with yours) https://www.php.net/manual/en/timezones.php
PHP_TZ: Europe/Prague
networks:
- zabbix-network
- traefik-network
secrets:
- zabbix-postgres-password
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
interval: 10s
timeout: 5s
retries: 3
start_period: 90s
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
# Container resources (replace with yours)
resources:
limits:
cpus: '1.75'
memory: 4G
reservations:
cpus: '0.35'
memory: 1G
labels:
- "traefik.enable=true"
# Zabbix URL (replace with yours)
- "traefik.http.routers.zabbix.rule=Host(`zabbix.heyvaldemar.net`)"
- "traefik.http.routers.zabbix.service=zabbix"
- "traefik.http.routers.zabbix.entrypoints=websecure"
- "traefik.http.services.zabbix.loadbalancer.server.port=8080"
- "traefik.http.routers.zabbix.tls=true"
- "traefik.http.routers.zabbix.tls.certresolver=letsencrypt"
- "traefik.http.services.zabbix.loadbalancer.passhostheader=true"
- "traefik.http.routers.zabbix.middlewares=compresstraefik"
- "traefik.http.middlewares.compresstraefik.compress=true"
depends_on:
- postgres
- zabbix
agent:
<<: *default-opts
# Image tag (replace with yours)
image: zabbix/zabbix-agent2:6.2.0-ubuntu
environment:
# Zabbix Hostname (replace with yours)
# Set as DNS name on Zabbix server host configuration screen to make checks of Zabbix server itself
ZBX_HOSTNAME: zabbix.heyvaldemar.net
ZBX_SERVER_HOST: 0.0.0.0/0
networks:
- zabbix-network
ports:
- "10050:10050"
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
# Container resources (replace with yours)
resources:
limits:
cpus: '0.55'
memory: 1G
reservations:
cpus: '0.35'
memory: 512M
depends_on:
- postgres
- zabbix
backups:
<<: *default-opts
# Image tag (replace with yours)
image: postgres:14
# Database backups prune interval (replace with yours). Default is 7 days.
# find /srv/zabbix-postgres/backups -type f -mtime +7 | xargs rm -f
# Zabbix backups interval (replace with yours). Default is 1 day.
# sleep 24h
# Run zabbix-restore-database.sh on the Docker Swarm node where the container for backups is running to restore database if needed.
# Run docker stack ps zabbix | grep zabbix_backups | awk 'NR > 0 {print $4}' on the Docker Swarm manager node to find on which node container for backups is running.
command: sh -c 'sleep 30m
&& while true; do
PGPASSWORD="$$(cat $$POSTGRES_PASSWORD_FILE)"
pg_dump
-h postgres
-p 5432
-d zabbixdb
-U zabbixdbuser | gzip > /srv/zabbix-postgres/backups/zabbix-postgres-backup-$$(date "+%Y-%m-%d_%H-%M").gz
&& find /srv/zabbix-postgres/backups -type f -mtime +7 | xargs rm -f;
sleep 24h; done'
volumes:
# Database backups location
- zabbix-postgres-backups:/srv/zabbix-postgres/backups
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/zabbix-postgres-password
networks:
- zabbix-network
secrets:
- zabbix-postgres-password
deploy:
mode: replicated
replicas: 1
placement:
constraints:
- node.role == worker
# Container resources (replace with yours)
resources:
limits:
cpus: '0.55'
memory: 1G
reservations:
cpus: '0.35'
memory: 512M
depends_on:
- postgres
- zabbix