前言

Consul 是什么

Consul 是用 Go 开发的分布式服务协调管理的工具,它提供了服务发现,健康检查,Key/Value 存储等功能,并且支持跨数据中心的功能。

Consul 基本概念

  • Agent 组成 Consul 集群的每个成员上都要运行一个 Agent,可以通过 Consul Agent 命令来启动。Agent 可以运行在 Server 状态或者 Client 状态。

  • Client 就是客户端模式。是 Consul 节点的一种模式,这种模式下,所有注册到当前节点的服务会被转发到 Server,本身是不持久化这些信息。

  • Server 就是服务端模式,这种模式下,功能和 Client 都一样,唯一不同的是,它会把所有的信息进行持久化。

准备环境

Consul 集群是基于滴滴云虚拟机搭建滴滴云。

滴滴云服务器 (DC2): 安全可靠,拥有极高的性价比高,为开发者的需求而设计。适合大中小型用户购买使用。

弹性公网 IP (EIP): 计费灵活,适配各类应用架构。可以满足用户各类应用场景需求。

安装过程

登录机器

在滴滴云平台上选择三台 Centos7.3 机器,选择 DC2 默认账户 dc2-user,使用 SSH 登录方式分别登录三台云主机:

server1:ssh dc2-user@{ip1}
server2:ssh dc2-user@{ip2}
server3:ssh dc2-user@{ip3}

由于搭建集群时需要 root 权限,切换到 root 账户:

sudo -i

建立 Consul 数据目录

mkdir -p /usr/local/consul/data

下载 Consul

进入 /usr/local/consul 目录,Consule 官网下载地址,选择 Linux 平台:

cd /usr/local/consul
sudo wget https://releases.hashicorp.com/consul/1.4.0/consul_1.4.0_linux_amd64.zip

解压

unzip consul_1.4.0_linux_amd64.zip

验证安装

使用 Consul 命令验证:

./consul
Usage: consul [--version] [--help] <command> [<args>]Available commands are:acl            Interact with Consul's ACLsagent          Runs a Consul agentcatalog        Interact with the catalogconnect        Interact with Consul Connectdebug          Records a debugging archive for operatorsevent          Fire a new eventexec           Executes a command on Consul nodesforce-leave    Forces a member of the cluster to enter the "left" stateinfo           Provides debugging information for operators.intention      Interact with Connect service intentionsjoin           Tell Consul agent to join clusterkeygen         Generates a new encryption keykeyring        Manages gossip layer encryption keyskv             Interact with the key-value storeleave          Gracefully leaves the Consul cluster and shuts downlock           Execute a command holding a lockmaint          Controls node or service maintenance modemembers        Lists the members of a Consul clustermonitor        Stream logs from a Consul agentoperator       Provides cluster-level tools for Consul operatorsreload         Triggers the agent to reload configuration filesrtt            Estimates network round trip time between nodesservices       Interact with servicessnapshot       Saves, restores and inspects snapshots of Consul server statevalidate       Validate config files/directoriesversion        Prints the Consul versionwatch          Watch for changes in Consul

启动 Consul Server

在第一台 Server上启动:

./consul agent -server -ui -bootstrap-expect 2 -data-dir=data -node=n1 -bind={ip1} -client=0.0.0.0 &

启动后,查看 members:

./consul members --http-addr {ip1}:8500
Node  Address             Status  Type    Build  Protocol  DC   Segment
n1    {ip1}:8301  alive   server  1.4.0  2         dc1  <all>

在第二台 Server 上启动:

./consul agent -server -ui -bootstrap-expect 2 -data-dir=data -node=n2 -bind={ip2} -client=0.0.0.0 &

启动后,查看 members:

./consul members --http-addr {ip2}:8500
Node  Address           Status  Type    Build  Protocol  DC   Segment
n2    {ip2}:8301  alive   server  1.4.0  2         dc1  <all>

在第三台 Server 上启动:

./consul agent -server -ui -bootstrap-expect 2 -data-dir=data -node=n3 -bind={ip3} -client=0.0.0.0 &

启动后,查看当前 members:

./consul members --http-addr {ip3}:8500Node  Address             Status  Type    Build  Protocol  DC   Segment
n3    {ip3}:8301  alive   server  1.4.0  2         dc1  <all>

此时,三台 Server 都是独立的机器,下一步就是将三台机器连接成集群。

连接集群

第二台机器上分别连接第一台机器:

./consul join --http-addr {ip1}:8500 {ip2}

第三台机器上连接第一台机器:

./consul join --http-addr {ip1}:8500 {ip2}

查看集群

./consul members --http-addr {ip1}:8500
Node  Address     Status  Type    Build  Protocol  DC   Segment
n1    {ip1}:8301  alive   server  1.4.0  2         dc1  <all>
n2    {ip2}:8301  alive   server  1.4.0  2         dc1  <all>
n3    {ip3}:8301  alive   server  1.4.0  2         dc1  <all>

查看集群 Leader

可在任意一节点上执行:

curl {ip2}:8500/v1/status/leader
结果
"{ip1}:8300"

查看集群 Peers

可在任意一节点上执行:

curl {ip2}:8500/v1/status/peers
结果
["{ip1}:8300","{ip2}:8300","{ip3}:8300"]

附录

Consul 命令行

- bootstrap-expect 集群期望的节点数,只有节点数量达到这个值才会选举leader
- server 运行在server模式
- data-dir 指定数据目录,其他的节点对于这个目录必须有读的权限
- node 指定节点的名称
- bind 为该节点绑定一个地址
- config-dir 指定配置文件,定义服务的,默认所有一.json结尾的文件都会读
- enable-script-checks=true 设置检查服务为可用
- datacenter 数据中心名称,
- join 加入到已有的集群中
- ui 使用自带的ui
- client 指定web ui、的监听地址,默认127.0.0.1只能本机访问,改为0.0.0.0可外网访问

基于滴滴云服务器搭建 Consul 集群相关推荐

  1. 基于阿里云服务器搭建hadoop集群:HDFS的namenode WEB访问9870端口打不开解决方法

    基于阿里云服务器搭建hadoop集群:HDFS的namenode WEB访问9870端口打不开解决方法 以下是基于我所面临问题的解决办法. 1.在本地的c:windows/system32/dirve ...

  2. 利用云服务器搭建hadoop集群

    利用云服务器搭建hadoop集群 测试连接 一. Linux配置 二. 3台服务器免密码登录 1. 三台机器生成公钥与私钥: 2. 拷贝公钥到同一台机器 3. 复制第一台机器的认证到其他机器 4. 通 ...

  3. 使用微软云服务器搭建Hadoop集群

    使用微软云服务器搭建Hadoop集群 环境准备 修改主机名 配置无秘钥登录 下载并安装JDK Java相关命令的讲解 关闭3台机器的防火墙(微软云服务器上的防火墙默认是关闭的,此步可以跳过) 三台机器 ...

  4. 云服务器搭建redis集群

    在搭建redis集群之前需要安装ruby.redis使用ruby来做集群的.用一个叫redis-trib.rb的ruby脚本.redis-trib.rb是redis官方推出的管理redis集群的工具, ...

  5. 使用三台阿里云服务器搭建Hadoop集群(云计算实验踩坑集锦)

    使用阿里云服务器搭建这个hadoop集群,踩得坑人已经傻了,浪费了我快一周的时间. 1.准备环节 准备三台阿里云服务器 Namenode 121.196.224.191 Datanode1 121.1 ...

  6. 云服务器搭建k8s集群的巨坑,node间网络不通问题

    最近用腾讯云服务器搭建了k8s集群,踩到一个巨坑.现象就是服务正常搭建完毕,各个必须的pod也处于ready状态,但是node不能访问别的node的pod.搭建的示例tomcat的demo也不能通过外 ...

  7. 三台云服务器搭建hadoop集群

    hadoop-2.10.1百度云资源链接: 链接:https://pan.baidu.com/s/1agl2Cg8MrBSYyFM2vq_4GA 提取码:lbsm 上传hadoop压缩包至云服务器并解 ...

  8. 华为云 和 阿里云 跨服务器搭建Hadoop集群

    目录 华为云 和 阿里云 跨服务器搭建Hadoop集群 说明 期间遇到的问题 CentOS6 7 8更换阿里yum源 修改服务器名称 安装JDK 安装Hadoop 编写集群分发脚本 xsync scp ...

  9. 阿里云ESC搭建hadoop集群

    阿里云ESC搭建hadoop集群 前置 购买至少三台服务器,为了节约成本借了两个账号买了三台同一区域的服务器,安装的是 centos7:因此设计到不同账号相同地域之间通讯问题,阿里给了解决方案,详情参 ...

最新文章

  1. Arch Linux 安装 Xerox Phaser 3125N 网络打印机备忘录
  2. 田野中科院计算机网络信息中心,中国科学院
  3. 用JS实现人脑和计算机交互,这个厉害了
  4. python sorted下标_全!Python基础之原生数据类型、判断和循环、函数和文件操作合集...
  5. openmv串口数据 串口助手_Qt小项目之串口助手控制LED
  6. Android 网络状态的监控
  7. 【maven3学习之一】window7下maven环境搭建
  8. Geek必备神器 - Google眼镜(Google glass)的十大特色
  9. 运筹学 美国人在计算机上实现的四,运筹学试卷及答案.
  10. 数据分析 时间序列分析 ARMA模型
  11. 纯CSS实现button按钮
  12. 太空工程师-脚本-库存整理
  13. 商务云PHP网络验证系统,易如意PHP网络验证系统1.3【开源】+调用模块源码
  14. 微商大佬爆料:工商部门严查微商和社交电商机构
  15. 使用BeanUtils.populate遇到的bug
  16. python解析xml读取指定属性_python批量修改xml某些内容和属性
  17. Vue React大屏可视化进阶
  18. 华为鸿蒙八月,终于来了!华为鸿蒙系统确认8月发布:革命性产品首发搭载
  19. JRebel安装、使用
  20. DAVINCI DM365-DM368开发攻略—U-boot-2010.12-rc2-psp03.01.01.39及UBL的移植

热门文章

  1. DataFrame数据选取超全攻略
  2. 5G NR PDCP协议(一)
  3. 图片转换为 latex 公式,识别图片中Latex公式,支持数学公式,化学公式,物理公式和生物公式,附Java代码和测试效果
  4. 4个小方法,让你的抖音发出来的视频更清楚
  5. 新浪微博模拟登录分析(含验证码)
  6. 多元线性回归及案例(Python)
  7. unity 手机游戏优化(场景篇)
  8. CCRC信息安全服务资质分类及申请流程
  9. mooc上python课程哪个好_如何爬取中国大学MOOC上的课程信息
  10. uniapp MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 upgrade listeners