consul集群搭建及使用

下载consul: www.consul.io

1、解压,设置环境变量,创建文件夹consul1、consul2、consul3,分别在其目录下创建basic.json配置文件:

basic.json:

{
 
    "ports": {
 
    "http": 8500,
 
    "dns": 8600,
 
    "rpc": 8400,
 
    "serf_lan": 8301,
    
    "serf_wan": 8302,
 
    "server": 8300
 
    }
 
}

{
 
    "ports": {
 
    "http": 8501,
 
    "dns": 8601,
 
    "rpc": 8401,
 
    "serf_lan": 8311,
    
    "serf_wan": 8312,
 
    "server": 8301
 
    }
 
}

{
 
    "ports": {
 
    "http": 8502,
 
    "dns": 8602,
 
    "rpc": 8402,
 
    "serf_lan": 8321,
    
    "serf_wan": 8322,
 
    "server": 8302
 
    }
 
}

2、启动consul server

nohup consul agent -server -node=server-1 -bind=192.168.20.201 -bootstrap-expect 1 -client 0.0.0.0 -ui -dc=zxdc  -config-dir=/Users/zhongxing/JavaTools/consul-new/consul1  -data-dir=/tmp/consul1  >  /Users/zhongxing/JavaTools/consul-new/consul1/consul1.log  2>&1 & 

3、启动consul client

nohup consul agent -node=server2 -bind=192.168.20.201 -dc=zxdc  -retry-join 192.168.20.201:8301 -config-dir=/Users/zhongxing/JavaTools/consul-new/consul2  -data-dir=/tmp/consul2  >  /Users/zhongxing/JavaTools/consul-new/consul2/consul2.log  2>&1 & 

nohup consul agent -node=server3 -bind=192.168.20.201  -dc=zxdc  -retry-join 192.168.20.201:8301 -config-dir=/Users/zhongxing/JavaTools/consul-new/consul3  -data-dir=/tmp/consul3  >  /Users/zhongxing/JavaTools/consul-new/consul3/consul3.log  2>&1 & 

4、访问http://localhost:8500

5、创建项目:https://github.com/ZXingg/demo-ms

https://blog.csdn.net/qq_35119422/article/details/82152438

 

你可能感兴趣的:(Consul)