-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collectd + Graphite + Grafana + Zabbix + nginx/certbot with SSL cert …
…autorenewal on docker
- Loading branch information
Den
committed
May 20, 2021
1 parent
ad50943
commit 3aa8c4c
Showing
11 changed files
with
321 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
monitoring_grafana_public_root_url: http://192.168.10.101/ | ||
monitoring_graphite_host: 192.168.10.101 | ||
|
||
# extract subdir name from environment name (e.g. environments/test -> vpnkeys/test) | ||
vpnkeys_dir: "../.vpnkeys/{{ inventory_dir.split('/')[-1] }}/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
roles/monitoring_hub/files/monitoring_hub/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
version: '2' | ||
services: | ||
|
||
nginx: | ||
restart: unless-stopped | ||
image: nginx:1.20 | ||
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & /docker-entrypoint.sh nginx -g \"daemon off;\" '" | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
volumes: | ||
- ./nginx/conf.d:/etc/nginx/conf.d | ||
- ./nginx/nginx-auth.htpasswd:/etc/nginx/nginx-auth.htpasswd | ||
# certbox | ||
- ./nginx/certbot/conf:/etc/letsencrypt | ||
- ./nginx/certbot/www:/var/www/certbot | ||
|
||
certbot: | ||
image: certbot/certbot | ||
restart: unless-stopped | ||
volumes: | ||
- ./nginx/certbot/conf:/etc/letsencrypt | ||
- ./nginx/certbot/www:/var/www/certbot | ||
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" | ||
|
||
grafana: | ||
restart: unless-stopped | ||
image: grafana/grafana:7.4.5 | ||
ports: | ||
- 83:3000 | ||
volumes: | ||
- ./grafana:/var/lib/grafana | ||
#- ./custom.ini:/opt/grafana/conf/custom.ini | ||
# chown -R 472:472 ./grafana | ||
user: "root" | ||
environment: | ||
GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-simple-json-datasource,alexanderzobnin-zabbix-app,vonage-status-panel | ||
GF_SECURITY_ADMIN_USER: ${ADMIN_USER:-admin} | ||
GF_SECURITY_ADMIN_PASSWORD: ${ADMIN_PASSWORD:-admin} | ||
GF_USERS_ALLOW_SIGN_UP: "false" | ||
GF_SERVER_ROOT_URL: https://grafana.orgbackbone.org | ||
# if behind nginx with basicauth with different passwords | ||
GF_AUTH_BASIC_ENABLED: "false" | ||
GF_RENDERING_SERVER_URL: http://renderer:8081/render | ||
GF_RENDERING_CALLBACK_URL: http://grafana:3000/ | ||
GF_LOG_FILTERS: rendering:debug | ||
|
||
renderer: | ||
image: grafana/grafana-image-renderer:2.0.1 | ||
ports: | ||
- 8081 | ||
environment: | ||
ENABLE_METRICS: 'true' | ||
|
||
graphite: | ||
image: graphiteapp/graphite-statsd:1.1.8-1 | ||
hostname: graphite | ||
ports: | ||
- 81:80 # nginx-gunicorn-graphite | ||
#- 8080:8080 # gunicorn graphite | ||
- 2003-2004:2003-2004 | ||
- 2023-2024:2023-2024 | ||
- 8125:8125/udp | ||
- 8126:8126 | ||
volumes: | ||
- ./graphite/storage:/opt/graphite/storage | ||
environment: | ||
- COLLECTD=1 | ||
- REDIS_TAGDB=1 | ||
|
||
postgresql: | ||
image: postgres:12 | ||
restart: unless-stopped | ||
environment: | ||
POSTGRES_USER: zabbix | ||
POSTGRES_PASSWORD: zabbix | ||
POSTGRES_DB: zabbixdb | ||
volumes: | ||
- ./postgresql/data:/var/lib/postgresql/data | ||
|
||
zabbix-server: | ||
image: zabbix/zabbix-server-pgsql:ubuntu-5.2-latest | ||
restart: unless-stopped | ||
hostname: zabbix-server-container | ||
environment: | ||
DB_SERVER_HOST: postgresql | ||
POSTGRES_USER: zabbix | ||
POSTGRES_PASSWORD: zabbix | ||
POSTGRES_DB: zabbixdb | ||
ZBX_HISTORYSTORAGETYPES: log,text | ||
ZBX_DEBUGLEVEL: 1 | ||
ZBX_HOUSEKEEPINGFREQUENCY: 1 | ||
ZBX_MAXHOUSEKEEPERDELETE: 5000 | ||
ZBX_TRAPPERIMEOUT: 300 | ||
depends_on: | ||
- postgresql | ||
volumes: | ||
- ./zabbix/alertscripts:/usr/lib/zabbix/alertscripts | ||
- ./zabbix/externalscripts:/usr/lib/zabbix/externalscripts:z | ||
- ./zabbix/modules:/var/lib/zabbix/modules:z | ||
- ./zabbix/enc:/var/lib/zabbix/enc:z | ||
- ./zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:z | ||
- ./zabbix/ssl/certs:/var/lib/zabbix/ssl/certs:z | ||
- ./zabbix/ssl/keys:/var/lib/zabbix/ssl/keys:z | ||
- ./zabbix/ssl/ssl_ca:/var/lib/zabbix/ssl/ssl_ca:z | ||
- ./zabbix/snmptraps:/var/lib/zabbix/snmptraps:z | ||
- ./zabbix/mibs:/var/lib/zabbix/mibs:z | ||
- ./zabbix/export:/var/lib/zabbix/export:z | ||
ports: | ||
- 10051:10051 | ||
|
||
zabbix-web: | ||
image: zabbix/zabbix-web-nginx-pgsql:ubuntu-5.2-latest | ||
restart: unless-stopped | ||
environment: | ||
DB_SERVER_HOST: postgresql | ||
POSTGRES_USER: zabbix | ||
POSTGRES_PASSWORD: zabbix | ||
POSTGRES_DB: zabbixdb | ||
ZBX_SERVER_HOST: zabbix-server # Zabbix related and Php variables | ||
ZBX_POSTMAXSIZE: 64M | ||
ZBX_MAXEXECUTIONTIME: 500 | ||
depends_on: | ||
- postgresql | ||
- zabbix-server | ||
|
||
zabbix-agent: | ||
image: zabbix/zabbix-agent:ubuntu-5.2-latest | ||
# privileged: true # access mode for allowing resource access | ||
hostname: zabbix-agent-container | ||
restart: unless-stopped | ||
environment: | ||
- ZBX_SERVER_HOST=zabbix-server | ||
ports: | ||
- 10050:10050 |
87 changes: 87 additions & 0 deletions
87
roles/monitoring_hub/files/monitoring_hub/init-letsencrypt.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/bin/bash | ||
# | ||
# based on https://github.com/wmnnd/nginx-certbot | ||
# see https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71 | ||
# | ||
set -xe | ||
|
||
|
||
if ! [ -x "$(command -v docker-compose)" ]; then | ||
echo 'Error: docker-compose is not installed.' >&2 | ||
exit 1 | ||
fi | ||
|
||
domains=(grafana.orgbackbone.org zabbix.orgbackbone.org) | ||
rsa_key_size=4096 | ||
data_path="./nginx/certbot" | ||
email="[email protected]" # Adding a valid address is strongly recommended | ||
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits | ||
|
||
if [ -d "$data_path" ]; then | ||
read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision | ||
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then | ||
exit | ||
fi | ||
fi | ||
|
||
|
||
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then | ||
echo "### Downloading recommended TLS parameters ..." | ||
mkdir -p "$data_path/conf" | ||
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf" | ||
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem" | ||
echo | ||
fi | ||
|
||
echo "### Creating dummy certificate for $domains ..." | ||
path="/etc/letsencrypt/live/$domains" | ||
mkdir -p "$data_path/conf/live/$domains" | ||
docker-compose run --rm --entrypoint "\ | ||
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\ | ||
-keyout '$path/privkey.pem' \ | ||
-out '$path/fullchain.pem' \ | ||
-subj '/CN=localhost'" certbot | ||
echo | ||
|
||
|
||
echo "### Starting nginx ..." | ||
docker-compose up --force-recreate -d nginx | ||
echo | ||
|
||
echo "### Deleting dummy certificate for $domains ..." | ||
docker-compose run --rm --entrypoint "\ | ||
rm -Rf /etc/letsencrypt/live/$domains && \ | ||
rm -Rf /etc/letsencrypt/archive/$domains && \ | ||
rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot | ||
echo | ||
|
||
|
||
echo "### Requesting Let's Encrypt certificate for $domains ..." | ||
#Join $domains to -d args | ||
domain_args="" | ||
for domain in "${domains[@]}"; do | ||
domain_args="$domain_args -d $domain" | ||
done | ||
|
||
# Select appropriate email arg | ||
case "$email" in | ||
"") email_arg="--register-unsafely-without-email" ;; | ||
*) email_arg="--email $email" ;; | ||
esac | ||
|
||
# Enable staging mode if needed | ||
if [ $staging != "0" ]; then staging_arg="--staging"; fi | ||
|
||
docker-compose run --rm --entrypoint "\ | ||
certbot certonly --webroot -w /var/www/certbot \ | ||
$staging_arg \ | ||
$email_arg \ | ||
$domain_args \ | ||
--rsa-key-size $rsa_key_size \ | ||
--agree-tos \ | ||
--no-eff-email \ | ||
--force-renewal" certbot | ||
echo | ||
|
||
echo "### Reloading nginx ..." | ||
docker-compose exec nginx nginx -s reload |
10 changes: 10 additions & 0 deletions
10
roles/monitoring_hub/files/monitoring_hub/nginx/conf.d/certbot-challenge.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
server { | ||
listen 80 default_server; | ||
listen [::]:80 default_server; | ||
|
||
location /.well-known/acme-challenge/ { root /var/www/certbot; } | ||
location / { return 301 https://$host$request_uri; } | ||
} | ||
|
||
# add docker's embedded DNS 127.0.0.11 to route docker services with container name | ||
resolver 127.0.0.11 127.0.0.1 [::1]:5353 valid=5s; |
26 changes: 26 additions & 0 deletions
26
roles/monitoring_hub/files/monitoring_hub/nginx/conf.d/grafana.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
server { | ||
listen 443 ssl; | ||
server_name grafana.orgbackbone.org; | ||
|
||
ssl_certificate /etc/letsencrypt/live/grafana.orgbackbone.org/fullchain.pem; | ||
ssl_certificate_key /etc/letsencrypt/live/grafana.orgbackbone.org/privkey.pem; | ||
|
||
include /etc/letsencrypt/options-ssl-nginx.conf; | ||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | ||
|
||
auth_basic ""; | ||
auth_basic_user_file /etc/nginx/nginx-auth.htpasswd; | ||
|
||
location / { | ||
proxy_pass http://grafana:3000; | ||
proxy_set_header Host $host; | ||
proxy_set_header Referer ""; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_http_version 1.1; | ||
} | ||
} | ||
|
||
|
26 changes: 26 additions & 0 deletions
26
roles/monitoring_hub/files/monitoring_hub/nginx/conf.d/zabbix.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
server { | ||
listen 443 ssl; | ||
server_name zabbix.orgbackbone.org; | ||
|
||
ssl_certificate /etc/letsencrypt/live/grafana.orgbackbone.org/fullchain.pem; | ||
ssl_certificate_key /etc/letsencrypt/live/grafana.orgbackbone.org/privkey.pem; | ||
|
||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
ssl_ciphers HIGH:!aNULL:!MD5; | ||
|
||
auth_basic ""; | ||
auth_basic_user_file /etc/nginx/nginx-auth.htpasswd; | ||
|
||
location / { | ||
proxy_pass http://zabbix-web:8080/; | ||
proxy_set_header Host $host; | ||
proxy_set_header Referer ""; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_http_version 1.1; | ||
} | ||
} | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
roles/monitoring_hub/files/monitoring_hub/nginx/nginx-auth.htpasswd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
USER:um2j1VlJgPYvw | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters