consul 模板配置内容的参数说明
datacenters
{{datacenters}} 数据中心
file
{{file "/path/to/local/file"}} 读取本地文件的内容。如果不可读的话,会报错
key
{{key "service/redis/maxconns@east-aws"}} 读取consul的键的值。如果key不能转为字符串,则报错。
上面的命令读取的是east-aws这个数据中心的 service/redis/maxconns键的值
{{key "service/redis/maxconns"}} 如果省略数据中心,默认查本地的数据中心
key_or_default
{{key_or_default "service/redis/maxconns@east-aws" "5"}} 如果指定的key不存在,则使用默认值
ls
{{range ls "service/redis@east-aws"}}
{{.Key}} {{.Value}}{{end}}
查询指定前缀的顶层key和value(同上文,key value转换失败,会报错) 结果
minconns 2
maxconns 12
node
{{node "node1"}} 查询单节点
{{node}} 没有参数 返回当前的agent的node
{{node "node1" "@east-aws"}} 指定数据中心的节点
{{with node}}{{.Node.Node}} ({{.Node.Address}}){{range .Services}}
{{.Service}} {{.Port}} ({{.Tags | join ","}}){{end}}
{{end}}
指定的节点存在返回节点的相应信息,如果节点不存在,返回nil
nodes
{{nodes}} 所有的节点
{{nodes "@east-aws"}} 指定数据中心的所有节点
service
{{service "release.web@east-aws"}} 指定数据中心的web服务的健康情况
{{range service "web@datacenter"}}
server {{.Name}} {{.Address}}:{{.Port}}{{end}}
返回结果
server nyc_web_01 123.456.789.10:8080
server nyc_web_02 456.789.101.213:8080
默认情况下 ,只有健康的服务会被返回。
如果想返回全部的服务 可以用这个
{{service "web" "any"}}
下面是查询指定服务状态的服务
{{service "web" "passing, warning"}}
注意条件是或 而不是和。 返回passing或者waring状态的服务。 注意 ,不能和any一起使用。因为any是返回所有的,不用过滤。一起用的话会报错。
如果想自定义过滤,可以这么搞:
{{range service "web" "any"}}
{{if eq .Status "critical"}}
// Critical state!{{end}}
{{if eq .Status "passing"}}
// Ok{{end}}
维护模式
!/bin/sh
set -e
consul maint -enable -service web -reason "Consul Template updated"
service nginx reload
consul maint -disable -service web
执行时,设为维护模式,然后再恢复
如果你没有装consul agent可以用api
!/bin/sh
set -e
curl -X PUT "http://$CONSUL_HTTP_ADDR/v1/agent/service/maintenance/web?enable=true&reason=Consul+Template+Updated"
service nginx reload
curl -X PUT "http://$CONSUL_HTTP_ADDR/v1/agent/service/maintenance/web?enable=false"
services
{{services}} 全部服务
{{services "@east-aws"}}指定中西的服务
{{range services}}
{{.Name}}
{{range .Tags}}
{{.}}{{end}}
{{end}}
取出 所有服务的名称,tags
tree
{{range tree "service/redis@east-aws"}}
{{.Key}} {{.Value}}{{end}}
取出所有指定中心的key和value 。报错的话,看看key和value是否不符合规则。
consul 模板配置内容的参数说明的更多相关文章
- consul模板配置参数值示例
参看https://github.com/hashicorp/consul-template#examples // This is the address of the Consul agent. ...
- node 渲染html模板配置
node 渲染html模板配置 安装swig模块 npm install swig--save - dev 加载swig模块 var swig = require('swig'); 模板配置 //第一 ...
- 手动刷新客户端配置内容(Spring Cloud Config)
手动刷新客户端配置内容 客户端项目增加依赖项 <dependency> <groupId>org.springframework.boot</groupId> &l ...
- smarty模板配置代码详细说明及如何注册自己的smarty函数
下面为smarty模板的配置文件,smarty配置的详细说明以及如何注册自己所需要的smarty函数 config.inc.php <?php /** * Smarty 调用 * www.daf ...
- 修改tnsnames.ora文件中配置内容中的连接别名后,连接超时解决办法
1.tnsnames.ora文件中配置内容中的连接别名:由upaydb修改为IP地址 2.连接超时 定位原因: PLSQL登录界面的数据库列表就是读的tnsname.ora中连接的别名,这个文件中连接 ...
- consul模板的说明2
保证模板的正常执行 使用||true $ consul-template -template "in.ctmpl:out.file:service nginx restart || true ...
- spring 部分配置内容备忘
1.spring定时器简单配置: <bean name="taskJob" class="com.netcloud.mail.util.TaskJob"& ...
- EditPlus自动补全、模板配置
EditPlus真的是一款非常好用的编辑器,虽然小,但是短小精悍,速度快.只要配置好了,功能也是很强大的.下面来总结一下如何配置EditPlus的自动补全,和模板配置. 一.配置自动补全:(以开发CS ...
- 微服务配置内容《网上copy》=========》如何创建一个高可用的服务注册中心
前言:首先要知道什么是一个高可用的服务注册中心,基于spring boot建成的服务注册中心是一个单节点的服务注册中心,这样一旦发生了故障,那么整个服务就会瘫痪,所以我们需要一个高可用的服务注册中心, ...
随机推荐
- [Git] Ubuntu 升级 git 版本
$ sudo add-apt-repository ppa:git-core/ppa $ sudo apt-get update $ sudo apt-get install git
- 【C# 进阶】事件!直接上事件!
http://www.tracefact.net/csharp-programming/delegates-and-events-in-csharp.aspx ZiYang 张,何许人也?看了他写的博 ...
- Centos 7 mysql Buffered warning: Changed limits: max_connections: 214 解决方法
Everytime I restart MySQL I have this warning: [Warning] Buffered warning: Changed limits: max_conne ...
- 移动端rem实现响应布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Flex 布局2
Flex 布局2 你会看到,不管是什么布局,Flex往往都可以几行命令搞定. 我只列出代码,详细的语法解释请查阅<Flex布局教程:语法篇>.我的主要参考资料是Landon Sch ...
- Kolmogorov-Smirnov检验
Kolmogorov-Smirnov检验(K-S检验)基于累积分布函数,用以检验一个经验分布是否符合某种理论分布或比较两个经验分布是否有显著性差异. 两样本K-S检验由于对两样本的经验分布函数的位置和 ...
- 自定义 JSON 对象
针对 IE9 以下不支持 JSON 对象的处理方式,网上大部分自定义的方式无形之中都会将中文转码为 Unicode 编码格式的字符换,但是在浏览器中我们有无法察觉到(浏览器自己解析成 UTF8 了), ...
- 通过cygwin安装openSSH
openSSH的安装是学习hadoop必不可少的一步,如果ssh装不好,hadoop的安装会进行不下去.本人初学hadoop时发现以前安装ssh走了一些弯路,现在又有了一些认识,所以重写了这篇日志,供 ...
- oracle性能优化之表设计
数据库优化的目标无非是避免磁盘I/O瓶颈.减少CPU利用率和减少资源竞争.为了便于读者阅读和理解,笔者参阅了Sybase.Informix和Oracle等大型数据库系统参考资料,基于多年的工程实践经验 ...
- MFC 工具栏隐藏与显示
最近在学MFC,看的是孙鑫的VC++视频,感觉还不错.在看到第九节课的时候,讲到工具栏的时候,做了个小功能:工具栏的隐藏和显示,但是有个bug就是一个悬浮的工具栏隐藏后再显示,就会变成停靠状态.这里我 ...