搭建zookeeper集群 親測有效 避免走坑

2021-10-07 20:56:46 字數 4136 閱讀 2105

一.準備工作:

## 開啟指定埠

firewall-cmd --zone=public --add-port=12181/tcp --permanent

firewall-cmd --zone=public --add-port=12888/tcp --permanent

firewall-cmd --zone=public --add-port=13888/tcp --permanent

systemctl restart firewalld.service

## 重啟防火牆

systemctl restart firewalld.service

## 檢視埠是否成功開啟

firewall-cmd --list-ports

開啟頁面

zookeeper-3.4.6.tar.gz

cd /home/test/

tar -zxvf zookeeper-3.4.6.tar.gz

mv zookeeper-3.4.6.tar.gz zookeeper

cd/home/test/zookeeper

mkdir  /home/test/zookeeper/zkdata -p

mkdir /home/test/zookeeper/zkdatalog -p

cd /home/test/zookeeper/zkdata

echo  "1" > myid  另外兩台機器分別echo  "2" > myid       echo  "3" > myid

1對應zoo.cfg配置中server.1中的1

cd /home/test/zookeeper/conf

cp zoo_sample.cfg zoo.cfg

三個zoo.cfg配置本機用節點用  0.0.0.0  ip代替主機名其餘部分配置一樣

vim zoo.cfg

# the number of milliseconds of each tick

ticktime=2000

# the number of ticks that the initial

# synchronization phase can take

initlimit=10

# the number of ticks that can pass between

# sending a request and getting an acknowledgement

synclimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

datadir=/home/test/zookeeper/zkdata

datalogdir=/home/test/zookeeper/zkdatalog

# the port at which the clients will connect

clientport=12181

# the maximum number of client connections.

# increase this if you need to handle more clients

#maxclientcnxns=60

#

# be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

#

#

# the number of snapshots to retain in datadir

#autopurge.snapretaincount=3

# purge task interval in hours

# set to "0" to disable auto purge feature

#autopurge.purgeinterval=1

#第一台:

server.1=0.0.0.0:12888:13888

server.2=第二台外網ip:12888:13888

server.3=第三台外網ip:12888:13888

第二台:

server.1=第一台外網ip:12888:13888

server.2=0.0.0.0:12888:13888

server.3=第三台外網ip:12888:13888

第三台:

server.1=第一台外網ip:12888:13888

server.2=第二台外網ip:12888:13888

server.3=0.0.0.0:12888:13888

cd /home/test/zookeeper/bin

sh zkserver.sh start

sh zkserver.sh status  看到mode: leader  或者 mode: follower  表示集群搭建成功

jps

此時

telnet 機器ip 12181

telnet 機器ip 12888

telnet 機器ip 13888

發現都通了

zookeeper集群搭建

接觸zookeeper集群已有很長很長一段時間了,zookeeper在專案中的使用相當的頻繁,如dubb服務 amq集群 大資料領域hadoop等。zookeeper的集群建立非常簡單,一直想寫一篇文章來對集群使用的介紹,但一直沒能抽出空,今天正好閒來無事,就重新實踐一遍來整理記錄,下文是基本的集群...

zookeeper集群搭建

zookeeper環境搭建需要保證奇數臺機器,以保證演算法能選舉出乙個leader。一 環境準備 datadir dir ticktime 2000 initlimit 5 synclimit 2 clientport 2181 server.0 192.168.1.100 2888 3888 se...

zookeeper集群搭建

1.準備工作 tomcat zookeeper 最少三個結點搭乙個集群,所以複製三份 2.搭建並配置三個zookeeper例項 cd usr local solr cloud zookeeper01 進zookeeper01目錄,mkdir data 該目錄下建立data資料夾,放置zookeepe...