Centos7.x 部署consul集群

今天给各位小伙伴带来一篇consul的集群搭建的教程,废话不多说,直接上干货!!

Consul 集群环境:

192.168.10.136

192.168.10.128

192.168.10.16

三台执行

#切换到/usr/local/bin

cd /usr/local/bin

#下载consul的zip包并将包的名字改为consul.zip

curl -o consul.zip https://releases.hashicorp.com/consul/1.6.0/consul_1.6.0_linux_amd64.zip

#解压consul包

unzip consul.zip

#删除consul包

rm -rf consul.zip

#创建consul配置文件夹

mkdir -p /etc/consul.d/

#创建consul数据文件夹

mkdir /data/consul/

仅在第一台执行,其他两台不用执行

consul keygen

将值复制保存

#添加system服务

136执行

vim /etc/systemd/system/consul.service

[Unit]

Description=Consul Startup process

After=network.target

 

[Service]

Type=simple

ExecStart=/bin/bash -c '/usr/local/bin/consul agent -server -bind 192.168.10.136 -config-dir /etc/consul.d/ -node=server1'

TimeoutStartSec=0

 

[Install]

WantedBy=default.target

128执行

vim /etc/systemd/system/consul.service

[Unit]

Description=Consul Startup process

After=network.target

 

[Service]

Type=simple

ExecStart=/bin/bash -c '/usr/local/bin/consul agent -server -bind 192.168.10.128 -config-dir /etc/consul.d/ -node=server2'

TimeoutStartSec=0

 

[Install]

WantedBy=default.target

16执行

vim /etc/systemd/system/consul.service

[Unit]

Description=Consul Startup process

After=network.target

 

[Service]

Type=simple

ExecStart=/bin/bash -c '/usr/local/bin/consul agent -server -bind 192.168.10.16 -config-dir /etc/consul.d/ -node=server3'

TimeoutStartSec=0

 

[Install]

WantedBy=default.target

三台执行

#重新加载

systemctl daemon-reload

#编辑consul配置文件

vim /etc/consul.d/config.json

{

"bootstrap_expect": 3,

"client_addr": "0.0.0.0",

"datacenter": "walmart-datacenter1",

"data_dir": "/data/consul",

"domain": "consul",

"enable_script_checks": true,

"dns_config": {

"enable_truncate": true,

"only_passing": true

},

"enable_syslog": true,

"encrypt": "dwa+3N9rgVYUsthbk5w/vds/9x3ambw0WgaFculhXmY=",

"leave_on_terminate": true,

"log_level": "INFO",

"rejoin_after_leave": true,

"server": true,

"start_join": [

"192.168.10.136",

"192.168.10.128",

"192.168.10.16"

],

"ui": true

}

注:复制粘贴需要自行对其格式

#添加防火墙

firewall-cmd --zone=public --add-port=8300,8301,8302,8400,8500,8600/tcp --permanent

firewall-cmd --reload

firewall-cmd --list-all

#启动并查看状态

systemctl start consul

systemctl status consul

128/16执行

consul join 192.168.10.136

三台执行

查看集群成员

/usr/local/bin/consul members

查看集群leader信息

consul operator raft list-peers

集群完成!

亲测无坑!!

在此欢迎各位小伙伴提出意见和批评!!大家共勉!

        如果此篇文章对您有一点点帮助,那么此篇文章便有了他的意义!

谢谢!!

你可能感兴趣的:(linux,centos,consul)