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 @   自由早晚乱余生  阅读(366)  评论(1编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示