一,什么是consul?

1,Consul 是 HashiCorp 公司推出的开源软件,用于实现分布式系统的服务发现与配置。
Consul 是分布式的、高可用的、 可横向扩展的
 
2,官方网站:
https://www.consul.io/
3,Consul 集群间使用了 Gossip 协议通信和 raft 一致性算法
 
4,Consul和Eureka的不同之处:
   Eureka只需要在项目中加入服务端依赖,就可以作为服务端使用;
   Consul需要从官网下载,并单独安装
 
5,本文演示用3台服务器组建一个consul的集群
 

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,下载consul软件

1,下载地址:
https://www.consul.io/downloads
选择64位linux版本下载
 
2,把consul的安装文件解压:
[root@localhost consul]# cd /usr/local/source/consul
[root@localhost consul]# ls
consul_1.8.4_linux_amd64.zip
[root@localhost consul]# unzip consul_1.8.4_linux_amd64.zip
Archive: consul_1.8.4_linux_amd64.zip
inflating: consul
[root@localhost consul]# ls
consul consul_1.8.4_linux_amd64.zip
3,复制到到各服务器的/usr/local/soft目录下
 

三,在第一台consul服务器上运行:

1,生成数据目录:
[root@consul1 /]# mkdir /data/
[root@consul1 /]# mkdir /data/consul/
[root@consul1 /]# mkdir /data/consul/data
[root@consul1 /]# chmod 777 /data/consul/data
 
2,运行consul
-server:以server身份启动
-bootstrap-expect=2:集群要求的最少server数量
-bind:监听的ip
-client:客户端ip,0.0.0.0表示不限制客户端ip
-data-dir:指定存放数据的目录
-node:指定节点id,注意:同一集群内节点id不允许重复
[root@consul1 /]# 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 &
[1] 549
[root@consul1 /]#
查看是否在运行中,这里我们选择查看端口:
[root@consul1 /]# ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 4096 172.17.0.2:8300 0.0.0.0:* users:(("consul",pid=549,fd=6))
LISTEN 0 4096 172.17.0.2:8301 0.0.0.0:* users:(("consul",pid=549,fd=12))
LISTEN 0 4096 172.17.0.2:8302 0.0.0.0:* users:(("consul",pid=549,fd=8))
LISTEN 0 4096 *:8500 *:* users:(("consul",pid=549,fd=16))
LISTEN 0 4096 *:8600 *:* users:(("consul",pid=549,fd=15))

可以看到consul已经在守护端口中,而且consul启用了多个端口

 
3,查看consul的版本:
[root@consul1 /]# /usr/local/soft/consul --version
Consul v1.8.4
Revision 12b16df32
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
4,查看consul的集群成员数量
[root@consul1 /]# /usr/local/soft/consul members
Node Address Status Type Build Protocol DC Segment
server-2 172.17.0.2:8301 alive server 1.8.4 2 dc1 <all>

只有一台机器,正常

 
5,查看当前节点的信息:
[root@consul1 /]# /usr/local/soft/consul info
agent:
check_monitors = 0
check_ttls = 0
checks = 0
services = 0
build:
prerelease =
revision = 12b16df3
version = 1.8.4
consul:
acl = disabled
bootstrap = false
known_datacenters = 1
leader = false
leader_addr =
server = true
raft:
applied_index = 0
commit_index = 0
fsm_pending = 0
last_contact = never
last_log_index = 0
last_log_term = 0
last_snapshot_index = 0
last_snapshot_term = 0
latest_configuration = []
latest_configuration_index = 0
num_peers = 0
protocol_version = 3
protocol_version_max = 3
protocol_version_min = 0
snapshot_version_max = 1
snapshot_version_min = 0
state = Follower
term = 0
runtime:
arch = amd64
cpu_count = 2
goroutines = 79
max_procs = 2
os = linux
version = go1.14.6
serf_lan:
coordinate_resets = 0
encrypted = false
event_queue = 0
event_time = 1
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 1
members = 1
query_queue = 0
query_time = 1
serf_wan:
coordinate_resets = 0
encrypted = false
event_queue = 0
event_time = 1
failed = 0
health_score = 0
intent_queue = 0
left = 0
member_time = 1
members = 1
query_queue = 0
query_time = 1

四,在第二台consul服务器上运行相同的操作,

      启动的命令需要修改ip和节点名:
[root@consul2 /]# nohup /usr/local/soft/consul agent -server -bind=172.17.0.3 -client=0.0.0.0 -bootstrap-expect=2 -data-dir=/data/consul/da -node=server-3 >/dev/null 2>&1 &
[1] 371
查看集群成员:
[root@consul2 /]# /usr/local/soft/consul members
Node Address Status Type Build Protocol DC Segment
server-3 172.17.0.3:8301 alive server 1.8.4 2 dc1 <all>
把当前节点加入到第一台consul服务器的ip:
[root@consul2 /]# /usr/local/soft/consul join 172.17.0.2
Successfully joined cluster by contacting 1 nodes.
加入成功后再次查看节点:
[root@consul2 /]# /usr/local/soft/consul members
Node Address Status Type Build Protocol DC Segment
server-2 172.17.0.2:8301 alive server 1.8.4 2 dc1 <all>
server-3 172.17.0.3:8301 alive server 1.8.4 2 dc1 <all>

五,在第三台consul服务器上运行相同的操作:

命令修改ip和节点名:并允许访问ui
-ui:允许访问web ui
[root@consul3 /]# nohup /usr/local/soft/consul agent -server -bind=172.17.0.4 -client=0.0.0.0 -bootstrap-expect=2 -data-dir=/data/consul/da -node=server-4 -ui >/dev/null 2>&1 &
[1] 229
[root@consul3 /]#
查看成员
[root@consul3 /]# /usr/local/soft/consul members
Node Address Status Type Build Protocol DC Segment
server-4 172.17.0.4:8301 alive server 1.8.4 2 dc1 <all>
加入集群
[root@consul3 /]# /usr/local/soft/consul join 172.17.0.2
Successfully joined cluster by contacting 1 nodes.
成功后再次查看成员
[root@consul3 /]# /usr/local/soft/consul members
Node Address Status Type Build Protocol DC Segment
server-2 172.17.0.2:8301 alive server 1.8.4 2 dc1 <all>
server-3 172.17.0.3:8301 alive server 1.8.4 2 dc1 <all>
server-4 172.17.0.4:8301 alive server 1.8.4 2 dc1 <all>

六,访问在第三台consul服务器上启用的web ui:

访问:

 http://172.17.0.4:8500/

返回:

点击后可以查看集群内3个实例:
如图:
点击每台机器可查看其状态:

七,consul的退出:

leave指令触发一个优雅的离开动作并关闭agent,节点离开后不会尝试重新加入集群中
在第二台consul服务器上执行:
[root@consul2 /]# /usr/local/soft/consul leave
Graceful leave complete
查看端口:
[root@consul2 /]# ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
可以看到守护进程已退出
在其他节点查看成员:
[root@consul3 /]# /usr/local/soft/consul members
Node Address Status Type Build Protocol DC Segment
server-2 172.17.0.2:8301 alive server 1.8.4 2 dc1 <all>
server-3 172.17.0.3:8301 left server 1.8.4 2 dc1 <all>
server-4 172.17.0.4:8301 alive server 1.8.4 2 dc1 <all>
可以看到server-3的状态已变更为left
 
从web ui查看:
已看不到 server-3
 

八,查看linux的版本:

[root@localhost liuhongdi]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

linux(centos8):安装配置consul集群(consul 1.8.4 | centos 8.2.2004)的更多相关文章

  1. Linux中安装配置spark集群

    一. Spark简介 Spark是一个通用的并行计算框架,由UCBerkeley的AMP实验室开发.Spark基于map reduce 算法模式实现的分布式计算,拥有Hadoop MapReduce所 ...

  2. Linux中安装配置hadoop集群

    一. 简介 参考了网上许多教程,最终把hadoop在ubuntu14.04中安装配置成功.下面就把详细的安装步骤叙述一下.我所使用的环境:两台ubuntu 14.04 64位的台式机,hadoop选择 ...

  3. centos8安装fastdfs6.06集群方式三之:storage的安装/配置/运行

    一,查看本地centos的版本 [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) 说 ...

  4. centos8安装fastdfs6.06集群方式二之:tracker的安装/配置/运行

    一,查看本地centos的版本 [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) 说 ...

  5. centos8安装fastdfs6.06集群方式一之:软件下载与安装

    一,查看本地centos的版本 [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) 说 ...

  6. 架构(三)MongoDB安装配置以及集群搭建

    一 安装 1.1 下载MongoDB 我个人不太喜欢用wget url, 之前出现过wget下载的包有问题的情况 https://fastdl.mongodb.org/linux/mongodb-li ...

  7. 离线环境下使用二进制方式安装配置Kubernetes集群

    本文环境 Redhat Linux 7.3,操作系统采用的最小安装方式. Kubernetes的版本为 V1.10. Docker版本为18.03.1-ce. etcd 版本为 V3.3.8. 1. ...

  8. Nginx 在 Linux 下安装与搭建集群

    搭建集群图例 集群搭建图如下,为了简单一点,使用一个Nginx服务器+两个Tomcat服务器,省略数据库部分: 环境说明 Linux 为 CentOS 7.2 发行版 + Java jdk 1.8 + ...

  9. hadoop集群环境搭建之安装配置hadoop集群

    在安装hadoop集群之前,需要先进行zookeeper的安装,请参照hadoop集群环境搭建之zookeeper集群的安装部署 1 将hadoop安装包解压到 /itcast/  (如果没有这个目录 ...

随机推荐

  1. oracle之三目录库和辅助库

    目录库和辅助库 10.1 创建目录库(Catalog database)的必要性 如果没有catalog,RMAN的存储库(元数据)保存在目标库的控制文件里,这样可能存在如下隐患 1)目标库上的控制文 ...

  2. Mybatis和Mybatis-Plus时间范围查询,亲测有效

    一.mysql 1.传入时间范围参数类型是字符串 <if test="startTime!=null and startTime.trim() neq ''"> and ...

  3. 图灵机器人api的使用方法含微信版本和网页版

    访问图灵机器人官网http://www.tuling123.com/ 注册一个新的机器人账号 注册成功后转到主页 点击我的机器人>创建机器人>微信机器人 填写基本信息 点击微信介入> ...

  4. yum管理——搭建iso镜像私有yum源仓库(1)

    在服务器上一般是没有光驱的,那么我们怎么制作iso本地repo镜像源仓库? 通过本地iso镜像,copy到linux系统中一个目录中,进行伪文件系统挂载,执行如下命令: 挂载:mount -o loo ...

  5. 【域控日志分析篇】CVE-2020-1472-微软NetLogon权限提升-执行Exp后域控日志分析与事件ID抓取

    前言:漏洞复现篇见:https://www.cnblogs.com/huaflwr/p/13697044.html 本文承接上一篇,简单过滤NetLogon漏洞被利用后,域控上的安全及系统日志上可能需 ...

  6. JVM-概述和内存区域

    目录 JVM的优势 Java的跨平台性 JVM跨语言 举个例子 JVM整体结构 运行时数据区 方法区(Method Area) 1. 什么是方法区(Method Area)? 2.方法区(Method ...

  7. 3.Channel详解

  8. Ubuntu16环境安装和使用NFS

    通过NFS服务我们可以方便的读写服务器上的文件,一起来实战Ubuntu16环境安装和使用NFS: 文章概要 本次实战由以下步骤组成: 列举环境信息: 在192.168.119.128安装NFS服务,将 ...

  9. python爬取酷狗音乐

    url:https://www.kugou.com/yy/html/rank.html 我们随便访问一个歌曲可以看到url有个hash https://www.kugou.com/song/#hash ...

  10. 图形渲染的大致过程和关于OpenGL渲染管线的一些零碎知识,openglpipeline,vao,vbo,ebo.

    重要!!! OpenGL新人一枚,希望可以再此和大家分享有用的知识,少走弯路 文章会定期更新,把前面几段已经整理过的知识更完后,接下来每周至少会更两次. 文章如果有不对的,理解错误的地方,也非常希望在 ...