consul-template 使用

consul-template

用途:与consul集成,通过监听consul中的k-v 来更新配置模板,并执行命令。

安装

# curl -O https://releases.hashicorp.com/consul-template/0.19.5/consul-template<_version_OS>.tgz
# tar -zxf consul-template<_version_OS>.tgz

将解压后的consul-template 添加到系统路径

实践

Consul-template 配置
consul {
  address = "127.0.0.1:8500"
  token = "xxxxxxxxxxxxxxxxxxxxxxxxx"

  retry {
    enabled = true
    attempts = 12
    backoff = "250ms"
    max_backoff = "1m"
  }
}

reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
max_stale = "5s"
log_level = "ERR"

wait {
  min = "5s"
  max = "10s"
}

template {
  source = "/tmp/consul-template/test.ctmpl"
  destination = "/tmp/consul-template/test.txt"
  create_dest_dirs = true
  command = "cat /tmp/consul-template/test.txt"
  command_timeout = "20s"
  error_on_missing_key = false
  perms = 0644
  backup = true
  left_delimiter  = "{{"
  right_delimiter = "}}"
  wait {
    min = "2s"
    max = "10s"
  }
}

test.ctmpl 模板文件内容:

# cat test.ctmpl
{{ key "walker/test/text" }}
启动consul-template
# consul-template -config ./test.hcl
测试

consul 界面上添加walker/test/text key, 并写入内容 hello consul-template!

终端显示:

# consul-template -config ./test.hcl

hello consul-template!

修改 key walker/test/text, 写入hello consul-template! now i'm changed

终端显示:

# consul-template -config ./test.hcl

hello consul-template!

hello consul-template! now i'm changed

More

如果只需要consul-template 执行一次,可通过-once 参数来设置。

Eg:

consul-template -template="consul-template.tpl:consul-template.file" -once

参考文档

https://learn.hashicorp.com/consul/developer-configuration/consul-template

https://github.com/hashicorp/consul-template

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值