Consul安装与部署

网络配置

server1server1server1client
192.168.1.11192.168.1.22192.168.1.33192.168.1.44

实验环境

  • 关闭防火墙
  • 都需要有maven环境
  • 首先开启4台服务器,分别下载consul安装包到/root目录

实验步骤

在四台服务器都需要进行此操作

[root@localhost ~]# unzip consul_1.4.0_linux_amd64.zip -d /usr/bin/
[root@localhost ~]# mkdir -p /opt/consul/{data,config}

第一台服务器(server)

[root@localhost ~]# consul agent -server -node=consul1 -data-dir /opt/consul/data -config-dir /opt/consul/config/ -bind 192.168.1.11 -client 0.0.0.0 -enable-script-checks=true -bootstrap-expect 2 -datacenter=kgc01
  • enable-script-check=true    开启心跳检测,设置检查服务为可用
  • -bootstrap-expect:集群期望的节点数,只有节点数量达到这个值才会选举leader。
  • -server: 运行在server模式
  • -data-dir:指定数据目录,其他的节点对于这个目录必须有读的权限
  • -node:指定节点的名称
  • -bind:为该节点绑定一个地址
  • -config-dir:指定配置文件,定义服务的,默认所有以.json结尾的文件都会读
  • -datacenter: 数据中心名称,
  • -join:加入到已有的集群中

第二台服务器(server)

[root@localhost ~]# consul agent -server -node=consul2 -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.1.22 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc01 -join 192.168.1.11

第三台服务器(server)

[root@localhost ~]# consul agent -server -ui -node=consul3 -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.1.33 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc01 -join 192.168.1.11

第四台服务器(client)

[root@localhost ~]# consul agent -node=client -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.1.44 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc01 -join 192.168.1.11
  •  -ui:使用自带的ui
  • -ui-dir:指定ui的目录,使用自己定义的ui
  • -client:指定web  ui、的监听地址,默认127.0.0.1只能本机访问。

克隆Spring Cloud到本地(三台服务器)

[root@localhost ~]# git clone https://github.com/luojunyong/spring-cloud-examples.git

第一台服务器

[root@localhost ~]# cd /root/spring-cloud-examples/spring-cloud-consul/spring-cloud-consul-producer
[root@localhost spring-cloud-consul-producer]# vim src/main/resources/application.properties 
[root@localhost spring-cloud-consul-producer]# 
[root@localhost spring-cloud-consul-producer]# mvn spring-boot:run

第二台服务器

[root@localhost ~]# cd /root/spring-cloud-examples/spring-cloud-consul/spring-cloud-consul-producer
[root@localhost spring-cloud-consul-producer]# vim src/main/resources/application.properties 
[root@localhost spring-cloud-consul-producer]# 
[root@localhost spring-cloud-consul-producer]# mvn spring-boot:run
Last modification:July 23rd, 2020 at 10:52 pm
如果觉得我的文章对你有用,请随意赞赏