CentOS7 搭建 Consul 集群


環境准備:

ssh shell工具: 遠程連接
三個CentOS示例: 部署集群

配置好各個實例之間的網絡訪問,以及ssh免密登錄。

下載&上傳:

1、下載 Consul:
Download Consul - Consul by HashiCorp

2、上傳至虛擬機:

➜  Desktop scp consul_1.1.0_linux_amd64.zip root@192.168.1.11:/opt
➜  Desktop scp consul_1.1.0_linux_amd64.zip root@192.168.1.12:/opt
➜  Desktop scp consul_1.1.0_linux_amd64.zip root@192.168.1.13:/opt

解壓&拷貝

在其他幾台機器上重復此命步驟:

[root@centos-1 ~]# yum install unzip  -y  
[root@centos-1 ~]# cd /opt
[root@centos-1 opt]# ls      
consul_1.1.0_linux_amd64.zip             
[root@centos-1 opt]# unzip consul_1.1.0_linux_amd64.zip  
Archive:  consul_1.1.0_linux_amd64.zip 
  inflating: consul          
[root@centos-1 opt]# ls      
consul  consul_1.1.0_linux_amd64.zip      
[root@centos-1 opt]# mv consul /usr/bin/   
[root@centos-1 bin]# cd /usr/bin/ && ls consul     
consul

啟動

[root@centos-1 ~]# consul agent -server  -data-dir=/tmp/consul -node=server-1 \
-bind=192.168.1.11 -bootstrap-expect 3  -client=0.0.0.0  -ui & 
[root@centos-2 ~]#  consul agent -server  -data-dir=/tmp/consul -node=server-2 \
-bind=192.168.1.12 -join=192.168.1.11  -client=0.0.0.0  -ui &
[root@centos-3 ~]#  consul agent -server  -data-dir=/tmp/consul -node=server-3 \
-bind=192.168.1.13 -join=192.168.1.11  -client=0.0.0.0  -ui &

選項詳解:

選項 說明
consul anent: 該命令會啟動一個consulAnent
-server 表示該 agent是一個 serverAgent,不添加這個選項則表示是一個 clientAgent
-data-dir 表示相關數據存儲的目錄位置,在 serverAgent上該命令所指示的目錄下會存儲一些集群的狀態信息
-node 指定該 agent 節點的名稱,該名稱在集群眾必須是唯一的
-bind 指定 agent 的 Ip
-bootstrap-expect 該命令通知 consul 准備加入集群的節點個數
-client 0.0.0.0 -ui 啟動 consulUI,如不添加該指令,則 UI 只能在當前機器上訪問
-dc 指定該 agent 加入到哪一個數據中心,默認為 dc1
join 將該節點加入集群中

驗證

驗證集群是否搭建成功,執行consul members,在任意的一台機器上:

[root@centos-1 ~]# consul members
Node      Address            Status  Type    Build  Protocol  DC   Segment
server-1  192.168.1.11:8301  alive   server  1.1.0  2         dc1  <all>
server-2  192.168.1.12:8301  alive   server  1.1.0  2         dc1  <all>
server-3  192.168.1.13:8301  alive   server  1.1.0  2         dc1  <all>


免責聲明!

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



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