环境说明

  • Ubuntu 20.04.3 LTS
  • Consul 1.11.4

步骤说明

安装

下载

Download Consul

wget https://releases.hashicorp.com/consul/1.11.4/consul_1.11.4_linux_amd64.zip

解压

unzip consul_1.11.4_linux_amd64.zip

复制到/usr/local/bin下

sudo mv consul /usr/local/bin/consul

验证

consul -v

# root @ axinblog in ~/software [16:57:08]
$ consul -v
Consul v1.11.4
Revision 944e8ce6
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

配置

Sever 模式,快捷配置,一般用于调试模式,不建议使用

本地运行
consul agent -dev

远程机器
consul agent -dev -client 0.0.0.0
or
consul agent -dev -client 远程机器IP

Sever 模式

consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -ui -config-dir /etc/consul.d -bind=0.0.0.0

配置参数说明

  • server:- Serve 模式(不配置为 Client 模式),数量一般为 3-5 个
  • bootstrap-expect: - Server 数量
  • data-dir: - 数据目录
  • ui-dir: - UI目录
  • node: - Node名称
  • bind: - 集群通讯地址

Server 模式后台访问地址:http://localhost:8500

ctrl + c:停止服务

Client 模式

consul agent -data-dir /tmp/consul -node=ubuntu64 -bind=ip

常用命令

查看集群成员

consul members

查看当前服务器的状况

consul info

退出当前服务集群

consul leave

参考文献

Install Consul