gitee.com/woood2/luca@v1.0.4/deployments/consul-template.md (about) 1 2 ### 安装 3 ``` 4 [linux] 5 6 wget https://releases.hashicorp.com/consul-template/0.20.0/consul-template_0.20.0_linux_amd64.tgz 7 tar -zxvf consul-template_0.20.0_linux_amd64.tgz 8 sudo mv consul-template /usr/local/bin/ 9 consul-template -v 10 11 [macos] 12 13 wget https://releases.hashicorp.com/consul-template/0.30.0/consul-template_0.30.0_darwin_amd64.zip 14 unzip consul-template_0.30.0_darwin_amd64.zip 15 sudo mv consul-template /usr/local/bin/ 16 consul-template -v 17 ``` 18 19 ### luca_backend.ctmpl 20 ``` 21 upstream luca_backend { 22 23 {{range service "luca_backend.luca_backend@dc1"}} 24 25 server {{.Address}}:{{.Port}} weight=1; 26 27 {{end}} 28 29 } 30 ``` 31 32 ### 执行命令,watch变化 33 ``` 34 consul-template --consul-addr {ip}:8500 --template ./luca_backend.ctmpl:./dst:"cat ./dst" 35 ``` 36 37 ### 输出 38 ``` 39 # 实例1 上线 40 upstream luca_backend { 41 server {ip1}:8080 weight=1; 42 } 43 44 # 实例2 上线 45 upstream luca_backend { 46 server {ip1}:8080 weight=1; 47 server {ip2}:8080 weight=1; 48 } 49 50 # 实例1 下线 51 upstream luca_backend { 52 server {ip2}:8080 weight=1; 53 } 54 55 # 实例2 下线 56 upstream luca_backend { 57 58 } 59 ```