步骤1:上传压缩文件并解压
# tar xzvf zookeeper-3.4.5.tar.gz
步骤2:创建文件夹zookeeper并把zookeeper解压文件复制到zk1、zk2、zk3
# mkdir /usr/local/zookeeper
# cp -r zookeeper-3.4.5 /usr/local/zookeeper/zk3
# cp -r zookeeper-3.4.5 /usr/local/zookeeper/zk3
# cp -r zookeeper-3.4.5 /usr/local/zookeeper/zk3
步骤3:zk1\zk2\zk3下创建data文件夹,并data下创建文件myid并写1\2\3
# cd /usr/local/zookeeper/zk1
# mkdir data
# cd data
# vim myid
1
# cd /usr/local/zookeeper/zk2
# mkdir data
# cd data
# vim myid
2
# cd /usr/local/zookeeper/zk3
# mkdir data
# cd data
# vim myid
3
步骤4:进入到zk1/conf \zk2/conf\zk3/conf下把zoo_sample.cfg复制一份叫做zoo.cfg
# cd /usr/local/zookeeper/zk1/conf
# cp zoo_sample.cfg zoo.cfg
# cd /usr/local/zookeeper/zk2/conf
# cp zoo_sample.cfg zoo.cfg
# cd /usr/local/zookeeper/zk3/conf
# cp zoo_sample.cfg zoo.cfg
步骤5:编辑zoo.cfg内容,设置dataDIR为data文件夹,并在文件最下面添加下面内容
dataDIR=/usr/local/zookeeper/zk1/data
dataDIR=/usr/local/zookeeper/zk2/data
dataDIR=/usr/local/zookeeper/zk3/data
clientPort=2181
clientPort=2182
clientPort=2183
server.1=192.168.126.139:2688:3888
server.2=192.168.126.139:2689:3889
server.3=192.168.126.139:2690:3890
7.1 server.1 中的1 是myid的内容
7.2 2688,2689,2690 是zookeeper内部端口
7.3 3888,3889,3890 是leader端口
步骤6:编写脚本zkstartup.sh zkstatus.sh zkstop.sh
zkstartup.sh:
cd zk1/bin
./zkServer.sh start
cd …/…/
cd zk2/bin
./zkServer.sh start
cd …/…/
cd zk3/bin
./zkServer.sh start
cd …/…/
zkstatus.sh:
cd zk1/bin
./zkServer.sh status
cd …/…/
cd zk2/bin
./zkServer.sh status
cd …/…/
cd zk3/bin
./zkServer.sh status
cd …/…/
zkstop.sh:
cd zk1/bin
./zkServer.sh stop
cd …/…/
cd zk2/bin
./zkServer.sh stop
cd …/…/
cd zk3/bin
./zkServer.sh stop
cd …/…/
# chmod z+x zkstartup.sh zkstatus.sh zkstop.sh