consul多數據中心搭建 【h】


自建IDC后面簡稱own、阿里雲機房ali、騰訊雲機房tx
own機房:內網10.10.10.0/24,邊界節點,10.10.10.100/101.xxx.80.xxx
ali機房:內網10.10.10.0/24,邊界節點,10.10.10.100/xxx.43.xxx.50
tx機房:內網10.10.10.0/24,邊界節點,10.10.10.100/xxx.159.xxx.35
1、server、client節點部署
所有節點的consul服務均由supervisord守護管理。
idc機房配置3個server模式的節點,其它的均是client模式的節點,server和client配置各舉例一個
server模式:(邊界server節點的配置稍有不同,后面詳細介紹):

1
2
3
4
5
6
7
8
9
10
11
12
[program:consul_server]
command=/usr/local/consul/bin/consul agent -server -bootstrap-expect 3 -data-dir /usr/local/consul/data/ -config-dir /usr/local/consul/config/ -node=own-server02 -bind=10.10.10.105 -dc=xxx-own
process_name=%(process_num)s
numprocs=1
directory=/usr/local/consul/bin/
autostart=true
autorestart=true
startsecs=1
redirect_stderr=true
stdout_logfile=/opt/log/consul/consul_server.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=5

client模式:

1
2
3
4
5
6
7
8
9
10
11
12
[program:consul_client]
command=/usr/local/consul/bin/consul agent -data-dir /usr/local/consul/data/ -node=own-client04 -bind=10.10.10.214 -config-dir=/usr/local/consul/config/ -dc=xxx-own
process_name=%(process_num)s
numprocs=1
directory=/usr/local/consul/bin/
autostart=true
autorestart=true
startsecs=1
redirect_stderr=true
stdout_logfile=/opt/log/consul/consul_client.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=5

ali、tx機房的server、client節點配置類似,有區別的參數就是-dc、-bind、-node即所屬的數據中心、用於集群通信的監聽ip、節點名稱。
每次添加一個新的節點后,consul join加入到本地集群已有的任意一個節點即可加入這個集群(這個動作可以做到批量裝機里面)。

2、集群之間的通信設置
每個集群選取一個處於server模式的節點作為邊界節點,配置與集群內的其它server模式的節點稍有差異:

1
2
3
4
5
6
7
8
9
10
11
12
[program:consul_server]
command=/usr/local/consul/bin/consul agent -server -bootstrap-expect 3 -advertise-wan=101.xxx.80.xxx -data-dir /usr/local/consul/data/ -config-dir /usr/local/consul/config/ -node=own-server03 -dc=xxxx-own
process_name=%(process_num)s
numprocs=1
directory=/usr/local/consul/bin/
autostart=true
autorestart=true
startsecs=1
redirect_stderr=true
stdout_logfile=/opt/log/consul/consul_server.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=5

相比於其它server模式節點,需要指定-advertise-wan參數。如果不指定該參數,consul join -wan加入一個集群的時候,默認使用的是內外ip(節點環境是有內外網兩個以上ip),造成集群之間通信失敗(如果集群之間的內網沒有互通)。
每個邊界節點將-advertise-wan設置成公網ip,用於集群之間的通信。
如果邊界節點開啟了防火牆,需要將對方的ip地址加入白名單,或者將TCP/UDP的8302端口加入彼此的白名單。
最后任意一個邊界節均可以查看到各個邊界節點狀態信息:

1
2
3
4
5
6
$ consul members -wan
Node Address Status Type Build Protocol DC
own-server02.xxxx-own 101.xxx.80.xxx:8302 alive server 0.x.x 2 xxxx-own
ali-server03.xxxx-ali xxx.43.xxx.50:8302 alive server 0.x.x 2 xxxx-ali
tx-server02.xxxx-tx xxx.159.xxx.35:8302 alive server 0.x.x 2 xxxx-tx
$

3、集群UI管理界面設置
將官方提供的ui界面文件部署在任意一個邊界節點上,可以訪問到任何一個集群的節點狀態。客戶端(http、dns、rpc)默認監聽地址是127.0.0.1,訪問ui的端口是http的8500端口,如果不設置客戶端監聽ip,需要一個代理(nginx)將本地的8500端口轉發到外網,也可以直接指定client的監聽ip:

1
2
3
4
5
6
7
8
9
10
11
12
[program:consul_server]
command=/usr/local/consul/bin/consul agent -server -bootstrap-expect 3 -advertise-wan=101.xxx.80.xxx -data-dir /usr/local/consul/data/ -config-dir /usr/local/consul/config/ -node=own-server03 -ui-dir /usr/local/consul/web/ -bind=10.10.10.100 -client=0.0.0.0 -dc=xxxx-own
process_name=%(process_num)s
numprocs=1
directory=/usr/local/consul/bin/
autostart=true
autorestart=true
startsecs=1
redirect_stderr=true
stdout_logfile=/opt/log/consul/consul_server.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=5

參數-client用來指定client監聽ip,處於安全考慮可以監聽在內網10.10.10.100,但是consul命令默認訪問的是127.0.0.1端口,故監聽0.0.0.0。配置成功后可以看到各個集群之間的狀態:
consul02

----------------本文結束   感謝閱讀----------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM