最后活跃于 6 months ago

修订 ee6addb75ab21040d41ddb9a0b08f5cd42c60072

deploy_traefik.sh 原始文件
1#!/bin/bash
2DOCKER_BASE=/srv/docker
3
4mkdir -p ${DOCKER_BASE}/traefik/container.conf
5
6cat > ${DOCKER_BASE}/traefik/container.conf/docker-compose.yml <<EOF
7version: '3.7'
8
9services:
10 traefik:
11 image: traefik:1.7-alpine
12 networks:
13 - system_traefik
14 environment:
15 - LC_ALL=C.UTF-8
16 - TZ=Europe/Berlin
17 labels:
18 - traefik.enable=true
19 - traefik.backend=traefik
20 - traefik.port=8080
21 ports:
22 - "80:80"
23 - "443:443"
24 - "8080:8080"
25 restart: always
26 volumes:
27 - "./config/:/etc/traefik/"
28 - "/var/run/docker.sock:/var/run/docker.sock:ro"
29
30networks:
31 system_traefik:
32 external: true
33EOF
34ln -s container.conf/docker-compose.yml ${DOCKER_BASE}/traefik/
35
36cat > ${DOCKER_BASE}/traefik/container.conf/production.yml <<EOF
37version: '3.7'
38
39services:
40
41 traefik:
42 logging:
43 options:
44 max-size: "100M"
45 max-file: "10"
46 labels:
47 - traefik.frontend.rule=Host:host.test.org;PathPrefixStrip:/traefik
48 - com.centurylinklabs.watchtower.enable=true
49EOF
50
51cat > ${DOCKER_BASE}/traefik/container.conf/traefik.service <<EOF
52[Unit]
53Description=Traefik Proxy Service
54After=network.target docker.service
55Requires=docker.service
56
57[Service]
58Type=oneshot
59RemainAfterExit=yes
60
61Environment="WORK_DIR=/srv/docker/traefik/"
62WorkingDirectory=/srv/docker/traefik/
63ExecStartPre=/bin/bash -c "/usr/bin/docker network inspect system_traefik &>/dev/null || /usr/bin/docker network create --driver bridge system_traefik"
64ExecStartPre=-/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
65ExecStart=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" up -d
66ExecStop=/usr/local/bin/docker-compose -f "\${WORK_DIR}/docker-compose.yml" -f "\${WORK_DIR}/container.conf/production.yml" down
67
68[Install]
69WantedBy=docker.service
70EOF
71ln -s ${DOCKER_BASE}/traefik/container.conf/traefik.service /etc/systemd/system/
72
73mkdir -p ${DOCKER_BASE}/traefik/config
74
75cat > ${DOCKER_BASE}/traefik/config/traefik.toml <<EOF
76logLevel = "DEBUG"
77defaultEntryPoints = ["http", "https"]
78
79# WEB interface of Traefik - it will show web page with overview of frontend and backend configurations
80[web]
81address = ":8080"
82 [web.auth.basic]
83 users = ["admin:$apr1$AAbCdQpX$ajolS9mMfKRG.lqcY/uXU/"]
84
85# Connection to docker host system (docker.sock)
86[docker]
87domain = "test.org"
88watch = true
89# This will hide all docker containers that don't have explicitly
90# set label to "enable"
91exposedbydefault = false
92
93# Force HTTPS
94[entryPoints]
95 [entryPoints.http]
96 address = ":80"
97 [entryPoints.http.redirect]
98 entryPoint = "https"
99 [entryPoints.https]
100 address = ":443"
101 [entryPoints.https.tls]
102 minVersion = "VersionTLS12"
103
104# Let's encrypt configuration
105[acme]
106 email="ssladmin@test.org"
107 storage="/etc/traefik/acme.json"
108 entryPoint="https"
109 acmeLogging=true
110 onDemand=false
111 OnHostRule=true
112
113[acme.httpChallenge]
114 entryPoint = "http"
115EOF
116
117systemctl daemon-reload && systemctl enable traefik && systemctl start traefik
118
migrate_system_traefik_network.sh 原始文件
1#!/bin/bash
2sed -i '/^WorkingDirectory/a ExecStartPre=/bin/bash -c "/usr/bin/docker network inspect system_traefik &>/dev/null || /usr/bin/docker network create --driver bridge system_traefik"' /srv/docker/traefik/container.conf/traefik.service && systemctl daemon-reload
3sed -i '/image: traefik/a\ networks:\n - system_traefik' /srv/docker/traefik/container.conf/docker-compose.yml
4sed -i s/traefik_default/system_traefik/g /srv/docker/*/container.conf/*.yml
5sed -i s/traefik_default/system_traefik/g /srv/docker/portainer/data/compose/*/docker-compose.yml
6
migrate_traefik_TLS11.sh 原始文件
1#!/bin/bash
2sed -i '/\[entryPoints.https.tls\]/a \ minVersion = "VersionTLS11"' /srv/docker/traefik/config/traefik.toml && systemctl restart traefik
3
migrate_traefik_TLS12.sh 原始文件
1#!/bin/bash
2sed -i s/VersionTLS11/VersionTLS12/ /srv/docker/traefik/config/traefik.toml && systemctl restart traefik
3