«

2021年12月2日 Linux安装Consul

时间:2021-12-2 10:28     作者:Mahalalel     分类: 运行环境


背景

最近在写SpringCloud+SpringBoot+MyBatis+Vue+ElementUI的相关的项目;
项目中有使用到consul;
本地Windows系统运行Consul,每次都要命令行启动,太不方便,最近只好部署到云服务器上。

下载

首先下载安装包,下载地址:consul下载地址
可以手动下载,也可以在服务器上直接下载
命令如下:

wget https://releases.hashicorp.com/consul/1.10.4/consul_1.10.4_linux_amd64.zip

解压缩

unzip consul_1.10.4_linux_amd64.zip -d /usr/local/bin

设置环境变量

将/usr/local/bin/consul设置到环境变量中

vi /etc/profile
# 进入vim编辑模式后,按“i”进行编辑
# 最后一行输入
export CONSUL_HOME = /usr/local/bin/consul
export PATH=$PATH:CONSUL_HOME

使用环境变量配置生效

source /etc/profile

验证

查看consul版本,验证是否安装成功

[root@VM-16-8-centos bin]# consul version
Consul v1.10.4
Revision 7bbad6fe
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

运行

运行一个开发模式的单节点consul

consul agent -dev -ui -client 0.0.0.0

云服务器控制台添加consul出站访问规则,不输入日志后台执行如下命令:

consul agent -server -data-dir=/usr/local/consul-data/  -node=agent-one -bind=0.0.0.0 -bootstrap-expect=1 -client=0.0.0.0 -ui > /usr/local/consul-data/logs/consul.log 2>&1 &

服务器显示如下:

[root@VM-16-8-centos local]# consul agent -server -data-dir=/usr/local/consul-data/  -node=agent-one -bind=0.0.0.0 -bootstrap-expect=1 -client=0.0.0.0 -ui > /usr/local/consul-data/logs/consul.log 2>&1 &
[1] 627003
[root@VM-16-8-centos local]# 

查看启动结果

命令如下:

consul members

[root@VM-16-8-centos local]# consul members
Node       Address         Status  Type    Build   Protocol  DC   Segment
agent-one  10.0.16.8:8301  alive   server  1.10.4  2         dc1  <all>
[root@VM-16-8-centos local]# 

命令输出显示了节点名称、IP端口、健康状态、启动模式、所在数据中心和版本信息。

访问Consul的WebUI控制台

访问Consul的WebUI控制台,WEB控制台默认端口为:8500
consul-WebUI界面
接下来就可以在项目中使用了

停止agent服务

通过consul leave命令优雅停止服务,我们再打开一个从节点机器终端,运行该命令

[root@VM-16-8-centos local]# consul leave
Graceful leave complete

标签: Linux Consul安装 Consul启动