traefik使用教程

  1. 下载 https://github.com/containous/traefik/releases

  2. 配置traefik.toml

################################################################
# Global configuration
################################################################
traefikLogsFile = "traefik.log"
accessLogsFile = "access.log"
logLevel = "DEBUG"

################################################################
# Web configuration backend
################################################################
[web]
address = ":7888"

[healthcheck]

# Set the default health check interval. Will only be effective if health check
# paths are defined. Given provider-specific support, the value may be
# overridden on a per-backend basis.
# Can be provided in a format supported by [time.ParseDuration](https://golang.org/pkg/time/#ParseDuration) or as raw
# values (digits). If no units are provided, the value is parsed assuming
# seconds.
#
# Optional
# Default: "30s"
#
interval = "10s"


[retry]

# Number of attempts
#
# Optional
# Default: (number servers in backend) -1
#
#attempts = 3

[file]

# rules
[backends]
  [backends.backend1]
  [backends.backend1.healthcheck]
    path = "/health"
  interval = "10s"
    [backends.backend1.circuitbreaker]
      expression = "NetworkErrorRatio() > 0.5"
    [backends.backend1.servers.server1]
    url = "http://172.17.0.2:80"
    weight = 10
    [backends.backend1.servers.server2]
    url = "http://172.17.0.3:80"
    weight = 1
  [backends.backend2]
    [backends.backend1.maxconn]
      amount = 10
      extractorfunc = "request.host"
    [backends.backend2.LoadBalancer]
      method = "drr"
    [backends.backend2.servers.server1]
    url = "http://172.17.0.4:80"
    weight = 1
    [backends.backend2.servers.server2]
    url = "http://172.17.0.5:80"
    weight = 2

[frontends]
  [frontends.frontend1]
  backend = "backend2"
    [frontends.frontend1.routes.test_1]
    rule = "Host:test.localhost"
  [frontends.frontend2]
  backend = "backend1"
  passHostHeader = true
  priority = 10
  entrypoints = ["https"] # overrides defaultEntryPoints
    [frontends.frontend2.routes.test_1]
    rule = "Host:{subdomain:[a-z]+}.localhost"
  [frontends.frontend3]
  entrypoints = ["http", "https"] # overrides defaultEntryPoints
  backend = "backend2"
    rule = "Path:/test"
  1. api操作

PUT: http://localhost:7888/api/providers/web

{
  "backends": {
    "backend1": {
      "servers": {
        "server1": {
          "url": "http://127.0.0.1:8081",
          "weight": 0
        },
        "server2": {
          "url": "http://127.0.0.1:8080",
          "weight": 0
        }
      },
      "loadBalancer": {
        "method": "wrr"
      },
      "circuitBreaker": {
          "expression": "NetworkErrorRatio() > 0.5"
      },
      "maxConn": {
          "amount": 10,
          "extractorFunc": "request.host"
      },
      "healthCheck": {
        "interval": "10s",
        "path":"/health"
      }
    }
  },
  "frontends": {
    "frontend1": {
      "entryPoints": [
        "http"
      ],
      "backend": "backend1",
      "priority": 0,
      "passHostHeader":true
    }
  }
}
  1. cmd
sudo ./traefik -c traefik.toml

转载于:https://www.cnblogs.com/bergus/articles/traefik-shi-yong-jiao-cheng.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值