Ubuntu install consul cluster

本文详细介绍Consul的下载、安装及配置流程,包括启动服务器代理和服务客户端代理的方法,并提供了查看节点状态和访问Consul UI的方式。

Go to downloads page to download the correct version:
https://www.consul.io/downloads.html

I downloaded below version:
https://releases.hashicorp.com/consul/1.2.2/consul_1.2.2_linux_386.zip

unzip the package

unzip consul_1.2.2_linux_386.zip

Copied the unziped file consul* to /usr/bin/

mv consul /usr/bin/consul

Start the consul server agent

mkdir -p /tmp/consul
nohup consul agent -server -data-dir=/tmp/consul -node=server1 -bind=192.168.1.103 -bootstrap-expect 1 -client 0.0.0.0 -ui &
ParameterComments
consul agentit will start a consul agent
-servermeans the agent is a server agent,it is client agent it we do not define this parameter
-data-dirclient agent:service info,healthy info,server agent:cluster info
-nodethe agent name, must unique, it will default to host if not defined
-bindthe ip for the agent
-bootstrap-expect 1to inform consul that how many server agent will be joined, it aims to lazy start replication
-client 0.0.0.0 -uistart consul UI and all IPs can access the UI

Start the consul client agent

mkdir -p /tmp/consul
nohup consul agent -data-dir=/tmp/consul -node=client-11 -bind=192.168.1.102 -join=192.168.1.103 &
ParameterComments
-joinadd this client agent to agent server cluster

We can use below command to view all the nodes

consul members

We can access consul UI use below address

http://192.168.1.103:8500

spring-boot integrate with service register and discover

https://blog.youkuaiyun.com/yaominhua/article/details/82317368

### 安装和配置 Consul on UbuntuUbuntu 系统上安装和配置 Consul 的步骤如下: #### 1. 添加 HashiCorp APT 源 首先,需要添加 HashiCorp 的官方 APT 源以确保获取最新的软件包版本。运行以下命令来导入 GPG 密钥并添加源: ```bash curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" ``` 这一步是必要的,因为它确保了从可信的来源安装 Consul 软件包[^1]。 #### 2. 更新软件包列表并安装 Consul 接下来,更新本地的 APT 包索引,并安装 Consul: ```bash sudo apt-get update && sudo apt-get install consul ``` 这条命令会下载并安装最新版本的 Consul,同时确保所有依赖项都被正确处理[^1]。 #### 3. 配置 Consul Service Consul 默认作为系统服务运行。可以检查其状态以确认是否正常启动: ```bash systemctl status consul ``` 如果需要修改 Consul 的启动配置,可以编辑服务文件或创建一个自定义的配置文件。例如,将 Consul 配置为开发模式(`-dev`),并允许客户端连接到 `0.0.0.0` 地址: ```bash sudo nano /etc/systemd/system/consul.service ``` 在服务文件中,将 `ExecStart` 修改为以下内容: ```ini ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/ -dev -client=0.0.0.0 ``` 保存后,重新加载 systemd 配置并重启 Consul 服务: ```bash sudo systemctl daemon-reload sudo systemctl restart consul ``` #### 4. 验证 Consul 安装 可以通过以下命令验证 Consul 是否正常运行: ```bash consul members ``` 如果一切正常,应该能看到当前节点的信息,表明 Consul 已成功启动并处于开发模式下运行。 #### 5. 配置 Consul Server(可选) 如果需要将 Consul 配置为服务器模式(用于生产环境中的微服务集群),可以使用以下命令启动 Consul Agent: ```bash consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -ui-dir=./dist -config-dir /etc/consul.d -bind=<服务器IP> ``` 此命令适用于单节点集群配置。对于多节点集群,请根据实际需求调整 `-bootstrap-expect` 参数的值[^2]。 --- ### 注意事项 - 开发模式(`-dev`)仅适用于测试和学习目的,在生产环境中不推荐使用。 - 如果需要持久化存储 Terraform 状态数据,可以考虑使用 Consul 作为后端存储解决方案[^5]。 - 在生产环境中,建议通过配置文件(JSON 或 HCL 格式)管理 Consul 的配置,而不是直接通过命令行参数。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值