版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/SunnyYoona/article/details/51247539
1. 下載下傳位址
http://www.apache.org/dyn/closer.cgi/zookeeper/2. 解壓
tar zxvf zookeeper-3.4.8.tar.gz
3. 重命名
在對應的zookeeper-3.4.8/conf 下有一個檔案zoo_sample.cfg的這個檔案裡面配置了監聽用戶端連接配接的端口等一些資訊,Zookeeper 在啟動時會找zoo.cfg這個檔案作為預設配置檔案,是以我們重命名zoo_sample.cfg為zoo.cfg。使用如下指令:
-
mv zoo_sample.cfg zoo.cfg
4. 配置檔案 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/xiaosi/zookeeper/data
-
# 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
隻需修改dataDir項即可,不要使用預設的/tmp目錄;
如果需要叢集,zoo.cfg的内容如下:(其中data目錄和server位址需改成你真實部署機器的資訊):
-
tickTime=2000
-
initLimit=10
-
syncLimit=5
-
dataDir=/home/xiaosi/zookeeper/data
-
clientPort=2181
-
server.1=10.20.153.10:2555:3555
-
server.2=10.20.153.11:2555:3555
并在data目錄下放置myid檔案:(上面zoo.cfg中的dataDir)
-
sudo mkdir data
-
sudo vim myid
myid指明自己的id,對應上面zoo.cfg中server.後的數字,第一台的内容為1,第二台的内容為2,myid内容如下:
-
1
5. 啟動
進入bin目錄 ./zkServer.sh start
-
xiaosi@Qunar:/opt/zookeeper-3.4.8/bin$ ./zkServer.sh start
-
ZooKeeper JMX enabled by default
-
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
-
Starting zookeeper ... STARTED
檢視zookeeper狀态:
-
xiaosi@Qunar:/opt/zookeeper-3.4.8/bin$ ./zkServer.sh status
-
ZooKeeper JMX enabled by default
-
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
-
Mode: standalone
當zookeeper啟動時,會在/home/xiaosi/zookeeper/data下生成一個zookeeper_server.pid檔案。記錄了zookeeper程序的程序ID号(本例中為13402)。
-
xiaosi 13402 6831 0 00:06 pts/20 00:00:00 /opt/jdk1.7.0_40/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /opt/zookeeper-3.4.8/bin/../build/classes:/opt/zookeeper-3.4.8/bin/../build/lib/*.jar:/opt/zookeeper-3.4.8/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper-3.4.8/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.8/bin/../lib/netty-3.7.0.Final.jar:/opt/zookeeper-3.4.8/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper-3.4.8/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.8/bin/../zookeeper-3.4.8.jar:/opt/zookeeper-3.4.8/bin/../src/java/lib/*.jar:/opt/zookeeper-3.4.8/bin/../conf:.:/opt/jdk1.7.0_40/lib -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
-
xiaosi 13497 12559 0 00:07 pts/20 00:00:00 grep --color=auto zookeeper
6. 關閉
進入bin目錄 ./zkServer.sh stop
-
xiaosi@Qunar:/opt/zookeeper-3.4.8/bin$ ./zkServer.sh stop
-
ZooKeeper JMX enabled by default
-
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
-
Stopping zookeeper ... STOPPED