Zookeeper单机伪集群搭建
1、下载ZooKeeper
官网地址https://zookeeper.apache.org/
[root@vmlocalhost data]# https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
2、解压到指定文件夹
[root@vmlocalhost data]# mkdir -p /usr/local/zookeeper/zk1
[root@vmlocalhost data]# tar -xvzf apache-zookeeper-3.6.2-bin.tar.gz /usr/local/zookeeper/zk1/
3、修改Zk配置
[root@vmlocalhost data]# cd
[root@vmlocalhost data]# tar -xvzf apache-zookeeper-3.6.2-bin.tar.gz /usr/local/zookeeper/zk1/
[root@vmlocalhost apache-zookeeper-3.6.2-bin]# cd /usr/local/zookeeper/zk1/apache-zookeeper-3.6.2-bin/
[root@vmlocalhost apache-zookeeper-3.6.2-bin]# mkdir data
[root@vmlocalhost apache-zookeeper-3.6.2-bin]# vim data/myid
--内容为1,与下面的 server.1=192.168.17.223:2888:3888 对应
1
[root@vmlocalhost apache-zookeeper-3.6.2-bin]# mkdir log
[root@vmlocalhost apache-zookeeper-3.6.2-bin]# cd conf
[root@vmlocalhost conf]# cp zoo_sample.cfg zoo.cfg
[root@vmlocalhost conf]# vim zoo.cfg
--主要修改的内容和添加集群地址
dataDir=/usr/local/zookeeper/zk1/apache-zookeeper-3.6.2-bin/data
logDir=/usr/local/zookeeper/zk1/apache-zookeeper-3.6.2-bin/log
clientPort=2181
server.1=192.168.17.223:2888:3888
server.2=192.168.17.223:2889:3889
server.3=192.168.17.223:2890:3890
复制zk1给zk2和zk3,修改其中的配置和端口
[root@vmlocalhost zookeeper ]cp -rf zk1/apache-zookeeper-3.6.2-bin zk2
[root@vmlocalhost zookeeper ]cp -rf zk1/apache-zookeeper-3.6.2-bin zk3
[root@vmlocalhost zookeeper ]# vim zk2/apache-zookeeper-3.6.2-bin/data/myid
--内容为2,与下面的 server.2=192.168.17.223:2889:3889 对应
2
[root@vmlocalhost zookeeper ]# vim zk3/apache-zookeeper-3.6.2-bin/data/myid
--内容为3,与下面的 server.3=192.168.17.223:2890:3890 对应
3
[root@vmlocalhost zookeeper ]# vim zk2/apache-zookeeper-3.6.2-bin/conf/zoo.cfg
dataDir=/usr/local/zookeeper/zk2/apache-zookeeper-3.6.2-bin/data
logDir=/usr/local/zookeeper/zk2/apache-zookeeper-3.6.2-bin/log
clientPort=2182
server.1=192.168.17.223:2888:3888
server.2=192.168.17.223:2889:3889
server.3=192.168.17.223:2890:3890
[root@vmlocalhost zookeeper ]# vim zk3/apache-zookeeper-3.6.2-bin/conf/zoo.cfg
dataDir=/usr/local/zookeeper/zk3/apache-zookeeper-3.6.2-bin/data
logDir=/usr/local/zookeeper/zk3/apache-zookeeper-3.6.2-bin/log
clientPort=2183
server.1=192.168.17.223:2888:3888
server.2=192.168.17.223:2889:3889
server.3=192.168.17.223:2890:3890
3、启动zk
[root@vmlocalhost zookeeper]# zk1/apache-zookeeper-3.6.2-bin/bin/zkServer.sh start
[root@vmlocalhost zookeeper]# zk2/apache-zookeeper-3.6.2-bin/bin/zkServer.sh start
[root@vmlocalhost zookeeper]# zk3/apache-zookeeper-3.6.2-bin/bin/zkServer.sh start