consul下载地址: https://www.consul.io/downloads

traefik下载地址:https://github.com/traefik/traefik/releases

启动traefik的命令

traefik.exe --api.insecure=true  --configFile=traefik-sample.yml

配置文件 traefik-sample.yml

################################################################
#
# Configuration sample for Traefik v2.
#
# For Traefik v1: https://github.com/traefik/traefik/blob/v1.7/traefik.sample.toml
#
################################################################################################################################
# Global configuration
################################################################
global:checkNewVersion: truesendAnonymousUsage: true################################################################
# EntryPoints configuration
################################################################# EntryPoints definition
#
# Optional
#
entryPoints:web:address: :80websecure:address: :443################################################################
# Traefik logs configuration
################################################################# Traefik logs
# Enabled by default and log to stdout
#
# Optional
#
log:# Log level## Optional# Default: "ERROR"#level: DEBUG# Sets the filepath for the traefik log. If not specified, stdout will be used.# Intermediate directories are created if necessary.## Optional# Default: os.Stdout#
#  filePath: log/traefik.log# Format is either "json" or "common".## Optional# Default: "common"#
#  format: json################################################################
# Access logs configuration
################################################################# Enable access logs
# By default it will write to stdout and produce logs in the textual
# Common Log Format (CLF), extended with additional fields.
#
# Optional
#
#accessLog:# Sets the file path for the access log. If not specified, stdout will be used.# Intermediate directories are created if necessary.## Optional# Default: os.Stdout#
#  filePath: /path/to/log/log.txt# Format is either "json" or "common".## Optional# Default: "common"#
#  format: json################################################################
# API and dashboard configuration
################################################################# Enable API and dashboard
#
# Optional
#
api:# Enable the API in insecure mode## Optional# Default: false#insecure: true# Enabled Dashboard## Optional# Default: true#
#  dashboard: false################################################################
# Ping configuration
################################################################# Enable ping
#ping:# Name of the related entry point## Optional# Default: "traefik"#
#  entryPoint: traefik################################################################
# Docker configuration backend
################################################################providers:consul:rootKey: "traefik"endpoints:- "127.0.0.1:8500"# Enable Docker configuration backend
#  docker:# Docker server endpoint. Can be a tcp or a unix socket endpoint.## Required# Default: "unix:///var/run/docker.sock"#
#    endpoint: tcp://10.10.10.10:2375# Default host rule.## Optional# Default: "Host(`{{ normalize .Name }}`)"#
#    defaultRule: Host(`{{ normalize .Name }}.docker.localhost`)# Expose containers by default in traefik## Optional# Default: true#
#    exposedByDefault: false

后台服务

package mainimport ("fmt""net/http"
)var HTTP_PRE = "/server_1"func HelloHandle(w http.ResponseWriter, r *http.Request)  {_, _ = fmt.Fprint(w, " hello! this is go http server 1. port = 8888")
}func main() {http.HandleFunc(HTTP_PRE + "/hello", HelloHandle)if e := http.ListenAndServe(":8888", nil); e!= nil{panic(e.Error())}
}

启动consul服务:

consul.exe agent -dev -ui 

向consul的kv存储中插入以下键值对:

consul kv put traefik/http/routers/myrouter-1/rule PathPrefix(`/server_1`)
consul kv put traefik/http/routers/myrouter-1/entrypoints/0 web
consul kv put traefik/http/routers/myrouter-1/service myservice-1
consul kv put traefik/http/services/myservice-1/loadbalancer/servers/0/url http://127.0.0.1:8888

启动两个go http服务

启动traefik服务,启动命令见文章开始处

启动时会看到这样的日志(为看的比较清晰,将一些\" 替换成了“)

level=debug msg="Configuration received from provider consul: {"http":{"routers":{"myrouter-1":{"entryPoints":["web"],"service":"myservice-1","rule":"PathPrefix(`/server_1`)"}},"services":{"myservice-1":{"loadBalancer":{"servers":[{"url":"http://127.0.0.1:8888"}],"passHostHeader":true}}}}}" providerName=consul

浏览器访问 http://127.0.0.1/server_1/hello 请求被转发到后端的服务

参考链接:

https://www.consul.io/commands/kv

https://doc.traefik.io/traefik/providers/consul/

https://doc.traefik.io/traefik/reference/dynamic-configuration/kv/

traefik使用 -- consul kv动态配置相关推荐

  1. traefik使用 -- consul catalog动态配置

    consul下载地址: https://www.consul.io/downloads traefik下载地址:https://github.com/traefik/traefik/releases ...

  2. openresty+consul动态配置更新(服务变更发现)

    最近在做数据收集平台,用openresty往kafka里push数据,不管是kafka broker也好,还是一个配置也好,希望做到动态更新,不需要reload openresty.尤其是针对接口调用 ...

  3. ABP动态配置数据库连接字符串 Oracle11g数据库

    ABP动态配置数据库连接 Oracle11g数据库 ABP的仓储关于数据库连接字符串的配置是从web.config(app.config)的connectionStrings读取的. 我想实现的功能是 ...

  4. nginx动态配置及服务发现那些事

    标题,  <闲聊nginx动态配置及服务发现的那些事> - 这次的准备闲聊关于nginx服务发现的话题,  按照我以往写文章的性子,估计会迁移一些主题.  毕竟单纯聊nginx和动态服务发 ...

  5. 微服务-Nacos动态配置中心

    前言 回想之前的项目,尤其是项目分多模块的时候,一般就会有一个公共包大多是相关工具类,因为比较独立使得其他模块调用方便,现在出来个需求为工具类参数进行动态控制,比如Redis工具类动态设定过期时间,除 ...

  6. ConfigBus:Twitter的动态配置实践

    动态配置能够在不重新启动应用程序的情况下更改正在运行的系统的行为和功能.理想的动态配置系统使服务开发人员和管理员能够方便地查看和更新配置,并高效可靠地向应用程序提供配置更新.它使组织能够快速.大胆地迭 ...

  7. 取代ZooKeeper,Twitter 的动态配置实践

    作者 | Twitter Engineering Blog 译者 | 谢丽 ConfigBus 是 Twitter 的动态配置系统,包括存储配置的数据库.将配置分发到 Twitter 数据中心中的机器 ...

  8. springboot整合Quartz实现动态配置定时任务

    版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/liuchuanhong1/article/details/60873295 前言 在我们日常的开发中,很多 ...

  9. Spring Boot 整合 Quartz 实现 Java 定时任务的动态配置

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 首先说下这次主题,动态配置.没接触过定时任务的同学可以先看 ...

最新文章

  1. MATLAB简易验证码识别程序介绍
  2. 软件项目管理面面观之“玩的就是心跳”
  3. 01背包问题:回溯法和限界分支、递归和迭代方式
  4. 素数-试除法和埃式筛选法模板
  5. java B2B2C Springcloud多租户电子商城系统- Gateway 之Predict篇...
  6. 微服务SpringCloud系列
  7. 亮剑:PHP,我的未来不是梦(6)
  8. ToStringBuilder学习总结
  9. win10如何修改鼠标指针样式
  10. 基于阿里语音识别(ASR)C/C++ SDK2.0编写的unimrcp中间件
  11. Windbg及Dump文件分析方法
  12. 计算机ip 地址异常,ip地址错误怎么修复?ip地址错误的修复方法
  13. 微型计算机cpu组成部分是,微型计算机的中央处理器CPU由()和()两部分组成。 - 问答库...
  14. 2017最新淘宝高转化详情页排版技巧(转载)
  15. 黑苹果gtx1050显卡驱动问题
  16. Glide使用详解(一)
  17. 高二会考计算机分数,高二会考多少分才能通过
  18. 局域网内配置服务器方法--p2p技术、端口映射、网络域名
  19. Android-Service自动更换手机壁纸
  20. 2021年初级会计实务会计要素及其确认与计量

热门文章

  1. 黑马程序员------毕老师视频笔记第18-21天------IO输入与输出(4)
  2. 用python画小黄人步骤图-通过python将图片生成字符画
  3. linux入门教程(3)---管理
  4. 应对电商大促峰值的九个方法
  5. java.security.nosucha_java.security.NoSuchProviderException: no such provider: Crypto
  6. 已测试Xshell6石皮解版(解压后可直接使用),舒服!!!
  7. SQLServer学习笔记九:DISTINCT子句和子查询
  8. 「科聪分享」粗谈如何将林德L14改造成叉式搬运AGV
  9. 爱陆通5G4G智慧工厂解决方案-PLC网关MQTT物联网网关
  10. 值得一读的10本人工智能技术书籍!