版权声明:本文为博主原创文章,未经博主允许不得转载。 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