描述:本章節主要單服務器搭建集羣,在一個服務器上啓動多個不一樣端口的zookeeper服務,非真實環境。html
真實環境下zookeeper集羣會搭建在多個物理服務器上,並不是單一的服務器,但搭建方式同樣。vim
教程參考:http://www.javashuo.com/article/p-hkwckvtb-es.html服務器
本章節採用三個服務作集羣因此複製兩份,官方建議集羣數量爲奇數(由於主選舉半數+)。測試
cd /usr/local/ spa
cp -r zookeeper zookeeper23d
cp -r zookeeper zookeeper3code
vim /usr/local/zookeeper/zookeeper-3.4.12/dataDir/myidserver
輸入內容1,並保存htm
vim /usr/local/zookeeper2/zookeeper-3.4.12/dataDir/myidblog
輸入內容2,並保存
vim /usr/local/zookeeper3/zookeeper-3.4.12/dataDir/myid
輸入內容3,並保存
注:myid是zookeeper服務下的標識,單機有多個zookeeper服務或多個zookeeper服務關聯他們的myid內容不能重複
vim /usr/local/zookeeper/zookeeper-3.4.12/conf/zoo.cfg
修改端口 2181
修改dataDir路徑 /usr/local/zookeeper/zookeeper-3.4.12/dataDir
修改dataLogDir路徑 /usr/local/zookeeper/zookeeper-3.4.12/dataLogDir
在尾部添加以下集羣節點信息
server.1=192.168.159.129:2888:3888 server.2=192.168.159.129:2889:3889 server.3=192.168.159.129:2890:3890
vim /usr/local/zookeeper2/zookeeper-3.4.12/conf/zoo.cfg
修改端口 2182
修改dataDir路徑 /usr/local/zookeeper2/zookeeper-3.4.12/dataDir
修改dataLogDir路徑 /usr/local/zookeeper2/zookeeper-3.4.12/dataLogDir
在尾部添加以下集羣節點信息
server.1=192.168.159.129:2888:3888
server.2=192.168.159.129:2889:3889
server.3=192.168.159.129:2890:3890
vim /usr/local/zookeeper3/zookeeper-3.4.12/conf/zoo.cfg
修改端口 2183
修改dataDir路徑 /usr/local/zookeeper3/zookeeper-3.4.12/dataDir
修改dataLogDir路徑 /usr/local/zookeeper3/zookeeper-3.4.12/dataLogDir
在尾部添加以下集羣節點信息
server.1=192.168.159.129:2888:3888
server.2=192.168.159.129:2889:3889
server.3=192.168.159.129:2890:3890
注:
/usr/local/zookeeper/zookeeper-3.4.12/bin/zkServer.sh start
/usr/local/zookeeper2/zookeeper-3.4.12/bin/zkServer.sh start
/usr/local/zookeeper3/zookeeper-3.4.12/bin/zkServer.sh start
/usr/local/zookeeper/zookeeper-3.4.12/bin/zkServer.sh status
/usr/local/zookeeper2/zookeeper-3.4.12/bin/zkServer.sh status
/usr/local/zookeeper3/zookeeper-3.4.12/bin/zkServer.sh status
3.測試
鏈接主zk
/usr/local/zookeeper/zookeeper-3.4.12/bin/zkCli.sh -server 192.168.159.129:2182
建立節點數據
create /zk-cluster-test cluster-data
在兩個從zk獲取
/usr/local/zookeeper/zookeeper-3.4.12/bin/zkCli.sh -server 192.168.159.129:2181
get /zk-cluster-test