赞
踩
- traefik是一个http反向代理、负载均衡工具.
-
- traefik支持较多的后端协议(http[s]、Websocket、TCP)
-
- traefik支持多种容器框架(docker compose、Swarm、k8s、Mesos), 能识别API后台热更新配置.
安装docker,自行百度
- # traefik配置文件 traefik.toml
-
- [global]
- checkNewVersion = false
- sendAnonymousUsage = false
-
- [log]
- level = "WARN"
- format = "common"
-
- [api]
- dashboard = true
- insecure = true
-
- [ping]
-
- [accessLog]
-
- [providers]
- [providers.docker]
- watch = true
- exposedByDefault = false
- endpoint = "unix:///var/run/docker.sock"
- swarmMode = false
- useBindPortIP = false
- network = "traefik"
- [providers.file]
- watch = true
- directory = "/etc/traefik/config"
- debugLogGeneratedTemplate = true
-
- [entryPoints]
- [entryPoints.http]
- address = ":80"
- [entryPoints.https]
- address = ":443"
FALLBACK
- #docker-compose.yml
-
- version: '3.7'
-
- services:
-
- traefik:
- container_name: traefik
- image: traefik:v2.1.3
- restart: always
- ports:
- - 80:80
- - 443:443
- - 8080:8080
- networks:
- - traefik
- command: traefik --configFile /etc/traefik.toml
- volumes:
- - /var/run/docker.sock:/var/run/docker.sock:ro
- - ./traefik.toml:/etc/traefik.toml:ro
- - ./config/:/etc/traefik/config/:ro
- healthcheck:
- test: ["CMD-SHELL", "wget -q --spider --proxy off localhost:8080/ping || exit 1"]
-
- # 先创建外部网卡
- # docker network create traefik
- networks:
- traefik:
- external: true
-
FALLBACK
1.1 操作顺序
- 1,创建 traefik 文件目录
-
- 2,分别创建并保存(配置内容看上方),docker-compose.yml,traefik.toml
-
- 3,启动 docker-compose down && docker-compose up -d
-
- 4, 验证 浏览器输入ip 地址看到 404 即可成功;
-
- 5,访问8080 端口可看到 traefik dashboard 界面(下图);
- # docker-compose.yml
- version: "3.6"
-
- services:
-
- web_nginx:
- image: nginx:1.17.1-alpine
- restart: always
- expose:
- - 80
- networks:
- - traefik
- labels:
- - "traefik.enable=true"
- - "traefik.docker.network=traefik"
- - "traefik.http.routers.web_nginx.entrypoints=http"
- - "traefik.http.routers.web_nginx.rule=Host(`web_nginx.halobug.cn`)"
- - "traefik.http.services.web_nginx-backend.loadbalancer.server.scheme=http"
- - "traefik.http.services.web_nginx-backend.loadbalancer.server.port=80"
- logging:
- driver: "json-file"
- options:
- max-size: "1m"
- networks:
- traefik:
- external: true
FALLBACK
2.1 操作顺序
- 1,创建 web_nginx 文件目录
-
- 2,分别创建并保存(配置内容看上方),docker-compose.yml
-
- 3,启动命令稍有不同,docker-compose down && docker-compose up --scale web_nginx=10 -d
-
- 4,绑定hosts,127.0.0.1 web_nginx.halobug.cn
-
- 5,浏览器访问,http://web_nginx.halobug.cn
-
- 6,查看 traefik dashboard,http://127.0.0.1:8080/dashboard
-
- 7 ,查看日志 ,docker-compose logs -f
2.1.3,nginx容器启动成功后如下图
2.1.5,访问浏览器刷新多次,后查看日志
2.1.6,看到启动的web服务
2.1.7,log日志显示,已经负载到了每个容器
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。