Fork me on GitHub

consul 集群搭建

consul 集群搭建

一、三台机器

基本信息

192.168.80.128
192.168.80.129
192.168.80.130

二、下载consul

wget https://releases.hashicorp.com/consul/1.9.5/consul_1.9.5_linux_amd64.zip
# 解压出来就是一个二进制文件

三、三台机器分别创建目录和文件

mkdir /opt/consul/bin/
# 拷贝解压的二进制文件至 /opt/consul/bin/
mkdir /opt/consul/data/
mkdir /opt/consul/logs/
mkdir /opt/consul/conf/

四、配置

192.168.80.128 机器配置 consul.json

{
    "datacenter": "djx-test",           
    "data_dir": "/opt/consul/data",     
    "log_level": "INFO",                
    "node_name": "192.168.80.128",        
    "server": true,                     
    "ui": true,                         
    "bootstrap_expect": 1,              
    "bind_addr": "192.168.80.128",        
    "client_addr": "0.0.0.0",           
    "retry_join": ["192.168.80.129","192.168.80.130"],  
    "retry_interval": "3s",             
    "raft_protocol": 3,                 
    "enable_debug": false,              
    "rejoin_after_leave": true,       
    "enable_syslog": false,
    "telemetry": {
      "statsite_address": "127.0.0.1:9125"
    } 
}

192.168.80.129 配置 consul.json

{
    "datacenter": "djx-test",           
    "data_dir": "/opt/consul/data",     
    "log_level": "INFO",                
    "node_name": "192.168.80.129",        
    "server": true,                     
    "ui": true,                         
    "bootstrap_expect": 1,              
    "bind_addr": "192.168.80.129",        
    "client_addr": "0.0.0.0",           
    "retry_join": ["192.168.80.128","192.168.80.130"],  
    "retry_interval": "3s",             
    "raft_protocol": 3,                 
    "enable_debug": false,              
    "rejoin_after_leave": true,       
    "enable_syslog": false,
    "telemetry": {
      "statsite_address": "127.0.0.1:9125"
    } 
}

192.168.80.130 配置 consul.json

{
    "datacenter": "djx-test",           
    "data_dir": "/opt/consul/data",     
    "log_level": "INFO",                
    "node_name": "192.168.80.130",        
    "server": true,                     
    "ui": true,                         
    "bootstrap_expect": 1,              
    "bind_addr": "192.168.80.130",        
    "client_addr": "0.0.0.0",           
    "retry_join": ["192.168.80.128","192.168.80.129"],  
    "retry_interval": "3s",             
    "raft_protocol": 3,                 
    "enable_debug": false,              
    "rejoin_after_leave": true,       
    "enable_syslog": false,
    "telemetry": {
      "statsite_address": "127.0.0.1:9125"
    } 
}

五、三台机器都配置成系统服务

/usr/lib/systemd/system/consul.service

[Unit]
Description=consul
After=network.target

[Service]
LimitNOFILE=32768
Type=simple
Restart=on-failure
ExecStart=/opt/consul/bin/consul agent -config-dir /opt/consul/conf/ -http-port=8500 -log-file=/opt/consul/logs/consul.log

[Install]
WantedBy=multi-user.target

六、启动服务并添加到系统服务

systemctl start consul
systemctl enable consul

七、查看集群节点

consul  members

/ # consul  members
Node                     Address             Status  Type    Build  Protocol  DC     Segment
192.168.80.130               192.168.80.130:8301     alive   server  1.3.1  2         djx-test  <all>
192.168.80.129                192.168.80.129:8301     alive   server  1.3.1  2         djx-test  <all>
192.168.80.128                192.168.80.128:8301     alive   server  1.3.1  2         djx-test <all>
posted @ 2021-05-31 11:37  自由早晚乱余生  阅读(336)  评论(1编辑  收藏  举报