Consul集群部署+Consul-Template(Centos环境)

1、Consul安装

sudo yum install -y yum-utils

sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

sudo yum -y install consul

2、集群配置命令

consul agent -server -bootstrap -data-dir=/root/consul_data -bind=192.168.49.144 -client=0.0.0.0 -node=192.168.49.144 -ui  ###-ui 启动webui

consul agent -client  -join=192.168.49.144 -data-dir=/root/consul_data -bind=192.168.49.145 -client=0.0.0.0 -node=192.168.49.145

consul agent -client  -join=192.168.49.144 -data-dir=/root/consul_data -bind=192.168.49.147 -client=0.0.0.0 -node=192.168.49.147

PS:注意防火墙(嫌麻烦的可以直接关闭防火墙:systemctl stop firewalld

[root@minio-0 ~]# consul members
192.168.49.144 192.168.49.144:8301 alive server 1.10.0 2 dc1 <all>
192.168.49.145 192.168.49.145:8301 alive client 1.10.0 2 dc1 <default>
192.168.49.147 192.168.49.147:8301 alive client 1.10.0 2 dc1 <default>

 

3、Consul-Template安装

wget https://releases.hashicorp.com/consul-template/0.26.0/consul-template_0.26.0_linux_amd64.zip

unzip consul-template_0.26.0_linux_amd64.zip

mv consul-template /usr/bin/

[root@minio-0 ~]# consul-template --version
v0.26.0 (3b7f233a)

 

4、准备配置文件hcl

consul {
  address = "192.168.49.144:8500"   ###consul节点地址
}

template {
  source = "/root/consul_template_conf/template/service.ctmpl"  ###模板文件路径
  destination = "/root/consul/service.json"  ###生成的文件路径
}

template {
  source = "/root/consul_template_conf/template/activeservice.ctmpl"
  destination = "/root/consul/activeservice.json"
}

template {
  source = "/root/consul_template_conf/template/msbconfig.ctmpl"
  destination = "/root/consul/msbconfig.json"
}

 

5、准备模板文件ctmpl 这个可以去官网上找,具体看个人业务,以下是个人例子 service.ctmpl

[{{ range $index, $item := tree "/service/" }}{{if $index}},{{end}}
{{ .Value }}{{ end }}
]

 

6、执行Consul-Template命令

consul-template -config /root/consul_template_conf/config/template.hcl

 

Consul集群部署+Consul-Template(Centos环境)

上一篇:AttributeError: 'str' object has no attribute 'decode'


下一篇:Redis 事务