zookeeper-3.4.6安装配置

环境

  • 服务器三台,系统centos6.x 64位
  • java1.7

资源下载

安装

tar xvzf zookeeper-3.4.6.tar.gz -C /usr/local  

修改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/zookeeper/tmp  
dataLogDir=/data/zookeeper/logs  
# 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.0=fy.hdp.kafka.loadata.com:2888:3888  
server.1=fy.hdp.slave1.loadata.com:2888:3888  
server.2=fy.hdp.slave2.loadata.com:2888:3888  

/usr/local/zookeeper-3.4.6 拷贝到其他两台服务器上

修改myid

三台服务器的 /data/zookeeper/tmp 目录下都存一个 myid 文件,内容分别为 0 1 2

分别启动zookeeper

#三台机器上执行
./zkServer.sh start

#关闭
./zkServer.sh start

#查看状态
./zkServer.sh status

测试

[hadoop@VM_110_107_centos bin]$ ./zkCli.sh 
Connecting to localhost:2181  
2016-11-29 16:55:22,178 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT  
2016-11-29 16:55:22,181 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=localhost  
2016-11-29 16:55:22,181 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_79  
2016-11-29 16:55:22,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation  
2016-11-29 16:55:22,183 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/local/jdk/jdk1.7.0_79/jre  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.6/bin/../conf:.:/usr/local/jdk/jdk1.7.0_79/lib/dt.jar:/usr/local/jdk/jdk1.7.0_79/lib/tools.jar  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/local/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64/lib:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-573.el6.x86_64  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=hadoop  
2016-11-29 16:55:22,184 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/hadoop  
2016-11-29 16:55:22,185 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/usr/local/zookeeper-3.4.6/bin  
2016-11-29 16:55:22,186 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@2765c17  
Welcome to ZooKeeper!  
2016-11-29 16:55:22,212 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)  
2016-11-29 16:55:22,217 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2181, initiating session  
JLine support is enabled  
2016-11-29 16:55:22,227 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x58af3649ea0001, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null  
[zk: localhost:2181(CONNECTED) 0] ls
[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 2]