搭建zookeeper集群 亲测有效 避免走坑

一.准备工作:

## 开启指定端口

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

 

 

打开页面

https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/

下载

https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/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

 

  • 搭建zookeeper集群

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.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# 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

发现都通了

你可能感兴趣的:(Java)