首页 > 其他分享 >分布式服务发现与配置之Consul

分布式服务发现与配置之Consul

时间:2022-10-08 19:23:35浏览次数:81  
标签:addr 0.0 Consul 配置 server 分布式服务 data consul

文档: https://www.consul.io/docs/install

 

一、什么是consul

1、Consul 是 HashiCorp 公司推出的开源软件,用于实现分布式系统的服务发现与配置。

Consul 是分布式的、高可用的、 可横向扩展的

2、官方网站:

https://www.consul.io/

3、Consul 集群间使用了 Gossip 协议通信和 raft 一致性算法

 

[安装]

yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum install -y consul

验证是否安装完成

consul   version

三台服务器上都有进行安装

 

创建数据目录

mkdir -p /data/consul-data
chown -R consul:consul  /data/consul-data

 

[配置文件]

vim /etc/consul.d/server.json

第一台:

{
  "data_dir": "/data/consul-data/",
  "log_level": "INFO",
  "node_name": "server-1",
  "server": true,
  "bootstrap_expect": 2,
  "client_addr": "0.0.0.0",
  "bind_addr": "172.18.10.1"
}

第二台:  修改node_name,bind_addr

{
  "data_dir": "/data/consul-data/",
  "log_level": "INFO",
  "node_name": "server-2",
  "server": true,
  "bootstrap_expect": 2,
  "client_addr": "0.0.0.0",
  "bind_addr": "172.18.10.2"
}

第三台:

{
  "data_dir": "/data/consul-data/",
  "log_level": "INFO",
  "node_name": "server-3",
  "server": true,
  "ui": true,
  "bootstrap_expect": 2,
  "client_addr": "0.0.0.0",
  "bind_addr": "172.18.10.3"
}

 

 

 

 

 

 

对应的命令:

nohup /usr/local/soft/consul agent -server -bind=172.17.0.2 -client=0.0.0.0 -bootstrap-expect=2 -data-dir=/data/consul/da -node=server-2 >/dev/null 2>&1 &

-server:以server身份启动

-bootstrap-expect=2:集群要求的最少server数量

-bind:监听的ip

-client:客户端ip,0.0.0.0表示不限制客户端ip

-data-dir:指定存放数据的目录

-node:指定节点id,注意:同一集群内节点id不允许重复
-ui: 允许访问web ui

 

 

 

 

添加systemctl服务管理

vim  /lib/systemd/system/consul.service

如果是使用yum安装的,已经存在该服务

[Unit]
Description="HashiCorp Consul - A service mesh solution"
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul.d/consul.hcl

[Service]
EnvironmentFile=-/etc/consul.d/consul.env
User=consul
Group=consul
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/
ExecReload=/bin/kill --signal HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

 

[启动服务]

systemctl  start consul.service

 [操作]

# 查看版本
consul  verion

# 查看当前节点的信息
consul  info

# 查看consul集群成员数量
consul members

# 退出集群
consul leave

 

标签:addr,0.0,Consul,配置,server,分布式服务,data,consul
From: https://www.cnblogs.com/xingxia/p/consul.html

相关文章

  • Hashicorp Consul Service API远程命令执行漏洞
    Preface简介Consul是HashiCorp公司推出的一款开源工具,用于实现分布式系统的服务发现与配置。与其他分布式服务注册与发现的方案相比,Consul提供的方案更为“一站式”。Con......
  • Allure配置
    1.安装JDK1.8才可运行allure,直接百度2.下载Allure的安装包(版本号:2.13.5)https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/3.解压Allure压......
  • 【机器学习】利用 Python 进行数据分析的 Windows 环境配置(Jupyter,Matplotlib,Pandas)
    环境配置安装python博主使用的版本是3.10.6在Windows系统上使用Virtualenv搭建虚拟环境安装Virtualenv打开cmd输入并执行pipinstallVirtualenv等待......
  • Spring Boot + myBatis-plus + nacos(在nacos配置数据源)
    上一节我们学习了springboot整合nacos,知道了nacos具有动态的服务注册、配置管理和服务发现的作用,现在我以数据库的配置为例来演示一下nacos是如何进行数据的的配置管理的......
  • springboot中mybatis-plus简单配置与使用
    依赖mybatis-plus与mybatis依赖不兼容,同时使用会导致报错<dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>${or......
  • 锐捷交换机配置ssh
      Ruijie#configureterminalRuijie(config)#enableservicessh-server------>开启SSH服务,默认关闭Ruijie(config)#ipsshversion2------>默认1.99版......
  • MySQL(5.7.27)-my.ini文件配置
        MySQL5.7.27my.ini文件位置:MySQL安装目录(比如我的:D:\programing\mysql\mysql-5.7.27-winx64)。如果缺少这个文件,可以自己在安装目录创建一个,修改后保存为ANSI......
  • Linux驱动编写之PWM驱动配置
    简介I.MX6ULL有8路PWM输出,因此对应8个PWM控制器,所有在设备树下就有8个PWM控制器节点。而GPIO1_IO08就是PWM1的输出引脚,所以这里是基于IMX6ULLPWM1......
  • Windows Server 2019远程控制的配置与管理方法
    1、WindowsServer远程桌面功能在企业中服务器一般被寄存在专门的IDC机房中,这些机房在固定的地点,可能距离企业距离很远。但是大部分服务器需要定期维护,如果每次维护时,系统......
  • Consul的HTTP API和使用方法
    Consul支持基础结构的服务注册和发现(称为内部服务),也支持外部服务(第三方SAAS服务以及无法直接运行Consul代理的其它环境,例如redis)。直接使用sudoapt-getinstallc......