本文采用Consul1.3.0版本进行集群搭建。下面为详细搭建步骤。
本位的集群结构如下:
IP | type | node name | 配置文件对应目录 |
127.0.0.1 | server | server1 | config1,data1 |
127.0.0.1 | server | server2 | config2,data2 |
127.0.0.1 | server | server3 | config3,data3 |
127.0.0.1 | client | client1 | config4,data4 |
本文是通过在一台机器上安装3个server,一个client的方式来搭建集群,下面介绍详细步骤。
- 下载consul 1.3.0安装包。
- consul 的搭建方式可以通过Command line的方式也可以通过配置文件的方式,本文通过配置文件的方式。
- 创建config1,data1,config2,data2,config3,data3,config4,data4目录,分别对应每个节点的配置文件和数据文件存放目录。
- config1 目录下配置文件名 cluster.json 文件内容如下:
{"data_dir": "C:\\Users\\Downloads\\consul_1.3.0_windows_amd64\\data1","node_name": "server1",
"server": true,
"bootstrap_expect": 3,
"bootstrap": false,
"datacenter": "aws",
"advertise_addr": "127.0.0.1",
"bind_addr": "127.0.0.1",
"log_level": "INFO",
"enable_syslog": false,
"ports": {
"http": 8500 ,
"https": 8501,
"dns": 8600,
"grpc": 8502,
"serf_lan": 8301,
"serf_wan": 8302,
"server": 8300
},
"disable_host_node_id":true,
"retry_join": ["127.0.0.1:8301","127.0.0.1:7302","127.0.0.1:6303"]
} - config2 目录下配置文件名 cluster.json 文件内容如下:
{
"data_dir": "C:\\Users\\Downloads\\consul_1.3.0_windows_amd64\\data2",
"node_name": "server2",
"server": true,
"bootstrap_expect": 3,
"bootstrap": false,
"datacenter": "aws",
"advertise_addr": "127.0.0.1",
"bind_addr": "127.0.0.1",
"log_level": "INFO",
"enable_syslog": false,
"ports": {
"http": 7501 ,
"https": 7502,
"dns": 7601,
"grpc": 7503,
"serf_lan": 7302,
"serf_wan": 7303,
"server": 7301
},
"disable_host_node_id":true,
"retry_join": ["127.0.0.1:8301","127.0.0.1:7302","127.0.0.1:6303"]
} - config3 目录下配置文件名 cluster.json 文件内容如下:
{
"data_dir": "C:\\Users\\Downloads\\consul_1.3.0_windows_amd64\\data3",
"node_name": "server3",
"server": true,
"bootstrap_expect": 3,
"bootstrap": false,
"datacenter": "aws",
"advertise_addr": "127.0.0.1",
"bind_addr": "127.0.0.1",
"log_level": "INFO",
"enable_syslog": false,
"ports": {
"http": 6502 ,
"https": 6503,
"dns": 6602,
"grpc": 6504,
"serf_lan": 6303,
"serf_wan": 6304,
"server": 6302
},
"disable_host_node_id":true,
"retry_join": ["127.0.0.1:8301","127.0.0.1:7302","127.0.0.1:6303"]
} - config4 目录下配置文件名 cluster.json 文件内容如下:
{
"data_dir": "C:\\Users\\Downloads\\consul_1.3.0_windows_amd64\\data4",
"node_name": "client1",
"server": false,
"bootstrap": false,
"datacenter": "aws",
"advertise_addr": "127.0.0.1",
"bind_addr": "127.0.0.1",
"log_level": "INFO",
"enable_syslog": false,
"ui": true,
"ports": {
"http": 5503 ,
"https": 5504,
"dns": 5603,
"grpc": 5505,
"serf_lan": 5304,
"serf_wan": 5305,
"server": 5303
},
"disable_host_node_id":true,
"start_join": ["127.0.0.1:8301","127.0.0.1:7302","127.0.0.1:6303"]
} - 进入到consul 解压后的目录,然后依次启动server1,server2,server3,client1 节点,命令顺序如下:
- 启动完后,通过如下命令查看集群状态。
- 然后通过在浏览器输入http://127.0.0.1:5503/ui 查看Consul UI 界面。
- 以上整个集群就搭建完成了,希望能帮到大家。谢谢。