本案例選用zookeeper-3.4.14.tar.gz搭建僞集羣服務;
因爲我使用的是雲主機,時常會重裝主機,所以安裝文件我一般會選擇在/data 盤。
且本次安裝目標是爲了搭建solrcloud 集羣,所以一步一步的分解,本篇爲第一篇,使用單主機不同端口搭建zk僞集羣
1.上傳zookeeper-3.4.14.tar.gz文件到/data目錄,解壓後到如下文件夾下 /data/solrcloud/zookeeper01
#進入目錄
cd /data/solrcloud
#解壓文件
tar -zxvf zookeeper-3.4.14.tar.gz
#重命名
mv zookeeper-3.4.14 /data/solrcloud/zookeeper01
2.重命名zoo_sample.cfg文件爲zoo.cfg
#進入
cd zookeeper01/conf
#重命名
mv zoo_sample.cfg /data/solrcloud/zookeeper01/conf/zoo.cfg
3. 添加配置信息:
clientPort=2181 其他兩個端口設計爲2182,2183 ;
server.1=30.4.2.7:2888:3888 ,server.1中的1是編號 和myid文件要做綁定 、30.4.2.7是主機IP 、 2888:3888 不用特別注意
#編輯 zoo.cfg 文件
[root@SHB-L0120794 conf]# 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=/data/solrcloud/zookeeper01
#dataDir=/tmp/zookeeper
# the port at which the clients will connect
#修改端口的地方
clientPort=2181
# 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=30.4.2.7:2888:3888
server.2=30.4.2.7:2887:3887
server.3=30.4.2.7:2889:3889
4.進入zookeeper01目錄,創建myid文件;編輯myid文件 添加數字1 ,和zoo.cfg中server.1這個配置項綁定
#進入
cd /data/solrcloud/zookeeper01/
#創建文件
touch myid
#編輯myid文件,添加數字1 ,數字1 是和zoo.cfg中server.1這個配置項目綁定的;一次類推 其他綁定2,3 兩個數字
vim myid
5.複製zookeeper01 到 zookeeper02,zookeeper03
#進入目錄
cd /data/solrcloud/
#複製文件
mv zookeeper01 /data/solrcloud/zookeeper02
mv zookeeper01 /data/solrcloud/zookeeper03
#查看
[root@SHB-L0120794 solrcloud]# ll
drwxr-xr-x 16 2002 2002 4096 Mar 17 18:15 zookeeper01
drwxr-xr-x 15 root root 4096 Mar 17 18:22 zookeeper02
drwxr-xr-x 15 root root 4096 Mar 17 18:47 zookeeper03
5.修改zookeeper02,zookeeper03 中的zoo.cfg文件,還有每個文件夾下的myid文件,配置爲2 和3
#zookeeper02 編輯 zoo.cfg 文件修改如下地方
#修改路徑的地方
dataDir=/data/solrcloud/zookeeper02
#修改端口的地方
clientPort=2182
#zookeeper03 編輯 zoo.cfg 文件修改如下地方
#修改路徑的地方
dataDir=/data/solrcloud/zookeeper03
#修改端口的地方
clientPort=2183
6.啓動服務並查看狀態
#啓動
bin/zkServer.sh start
#查看
bin/zkServer.sh status
#案例1
[root@SHB-L0120794 zookeeper01]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/solrcloud/zookeeper01/bin/../conf/zoo.cfg
Mode: follower
#案例2
[root@SHB-L0120794 zookeeper02]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/solrcloud/zookeeper02/bin/../conf/zoo.cfg
Mode: leader