背景
此次项目的的特殊性:
1、项目需部署在B服务器上
2、请求入口为 A 服务器绑定的域名目录(weixin.domain.com/spring)
3、B 服务器要部署3个应用
- H5 活动应用
- 活动管理系
B 服务器资源配置如下
编号 | 类别 | 名称 | 路径 | 用途 | 开放端口 | 请求地址 | 运行方式 |
---|---|---|---|---|---|---|---|
1 | 软件 | Docker | /usr/bin/docker/etc/docker | 应用容器引擎 | —— | weixin.chinauff.com/spring | 系统启动 |
2 | Docker Image | traefik | /usr/local/spring-service | 容器及应用反向代理 | 80 | weixin.chinauff.com/spring | docker |
3 | Docker Image | spring/qrcode | /usr/local/spring-qrcode-server | 二维码生成服务 | —— | spring.chinauff.com/qrcode | docker-compose |
4 | Application | H5 春节活动应用 | /usr/local/spring-h5 | 春节活动前端应用 | —— | weixin.chinauff.com/spring | pm2 |
5 | Application | Admin Server | /usr/local/spring-server | 管理系统 、API服务 | —— | sping.chinauff.com | pm2 |
6 | Docker image | 静态文件服务 | /usr/local/spring.static | 前后端所用到的静态文件资源服务 | —— | spring.chinauff.com/static | docker-compose |
Traefik 的 docker-compose
version: '3'
services:
reverse-proxy:
image: traefik
restart: always
container_name: traefik
ports:
- 80:80
- 8360:8360
- 127.0.0.1:4399:4399
- 127.0.0.1:4398:4398
networks:
- traefik
command: traefik -c /etc/traefik.toml
volumes:
# 仅限标准的 Linux 环境
- /etc/localtime:/etc/localtime
- /etc/timezone:/etc/timezone
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/etc/traefik.toml
- ./logs:/data/logs
networks:
traefik:
external: true
Treafik 拓扑逻辑图
image.pngTreafik.toml
# 激活调试模式 (默认关闭)
debug = false
# 日志等级 (默认 ERROR)
logLevel = "INFO"
# 全局入口点类型 (默认 http)
defaultEntryPoints = ["http"]
# 不上报统计信息
sendAnonymousUsage = false
################################################################
# 入口点设置
################################################################
[entryPoints]
# 默认前端
[entryPoints.http]
address = ":80"
compress = true
[entryPoints.spring]
address = ":8360"
# 控制台端口
[entryPoints.traefik-api]
address = ":4399"
# 如果不想公开控制台,可以参考下面的配置生成你自己的 BA 账号密码
[entryPoints.traefik-api.auth]
[entryPoints.traefik-api.auth.basic]
#htpasswd -nb soulteary soulteary
users = ["baisheng:$apr1$jfu00Ykt$ZXZwEGbTn8Gq1ND33SloF/","admin:$apr1$uSjZJvnR$tsJxOce5ibB2PdkhV8Hub/"]
# Ping端口
[entryPoints.traefik-ping]
address = ":4398"
################################################################
# Traefik File configuration
################################################################
[file]
[backends]
[backends.dashboard]
[backends.dashboard.servers.server1]
url = "http://127.0.0.1:4399"
[backends.ping]
[backends.ping.servers.server1]
url = "http://127.0.0.1:4398"
[backends.chinauff]
[backends.chinauff.servers.server1]
url = "http://127.0.0.1:4399"
[backends.springH5]
[backends.springH5.servers.server1]
#url = "http://192.168.25.88:8360"
url = "http://192.168.25.88:3000"
[backends.springServer]
[backends.springServer.servers.server1]
url = "http://192.168.25.88:5000"
[backends.sre]
[backends.sre.servers.server1]
url = "http://192.168.25.88:9988"
[frontends]
[frontends.springH5]
entryPoints = ["spring","http"]
priority = 5
backend = "springH5"
[frontends.springH5.routes.route01]
#rule = "PathPrefixStrip:/spring"
rule = "PathPrefix:/spring"
[frontends.springApiServer]
entryPoints = ["spring"]
priority = 10
backend = "springServer"
[frontends.springApiServer.routes.route01]
rule = "PathPrefixStrip:/spring/server"
[frontends.springAdminServer]
entryPoints = ["http"]
backend = "springServer"
[frontends.springAdminServer.routes.route01]
rule = "Host:spring.chinauff.com"
### 服务管理面板
[frontends.dashboard]
entryPoints = ["http"]
priority = 100
backend = "dashboard"
[frontends.dashboard.routes.route01]
rule = "PathPrefixStrip:/control"
### 运维部署服务
[frontends.sre]
entryPoints = ["http"]
backend = "sre"
[frontends.sre.routes.route01]
rule = "PathPrefixStrip:/sre"
[frontends.ping]
backend = "ping"
[frontends.ping.routes.route01]
rule = "Host:ping.lab.com"
[frontends.ping.routes.route02]
rule = "ReplacePathRegex: ^/ /ping"
################################################################
# Traefik logs configuration
################################################################
# Traefik logs
# Enabled by default and log to stdout
#
# Optional
#
# Default: os.Stdout
[traefikLog]
filePath = "/data/logs/traefik.log"
[accessLog]
filePath = "/data/logs/access.log"
################################################################
# API 及 控制台 配置
################################################################
# 启用API以及控制台
[api]
# 入口点名称
entryPoint = "traefik-api"
# 开启控制台(默认开启)
dashboard = true
# 默认协议
defaultEntryPoints = ["http"]
################################################################
# Ping 配置
################################################################
# 启用 ping
[ping]
# 入口点名称
entryPoint = "traefik-ping"
################################################################
# Docker 后端配置
################################################################
# 启用Docker后端
[docker]
# Docker服务后端
endpoint = "unix:///var/run/docker.sock"
# 默认域名
domain = "spring.chinauff.com"
# 监控docker变化
watch = true
# 使用自定义模板(可选)
# filename = "docker.tmpl"
# 对容器默认进行暴露(默认开启)
# 如果关闭选项,则容器不包含 `traefik.enable=true` 标签,就不会被暴露
# 没有设置`traefik.enable=true`的容器就不会被发现
exposedbydefault = false
# 使用绑定端口的IP地址取代内部私有网络(默认关闭)
usebindportip = false
# 使用 Swarm Mode (默认关闭)
swarmmode = false
网友评论