测试环境redhat5.5:
vmware建两台虚拟机(btw,似乎双核系统只能建俩,3个就死掉了)
192.168.229.129
192.168.229.130
下载2011年12月15日的最新zookeeper
加压到
/opt/zookeeper-3.4.0/
配置/opt/zookeeper-3.4.0/conf/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=/opt/zookeeper-3.4.0/data/zookeeper
- datalogdir=/opt/zookeeper-3.4.0/data/log
- # the port at which the clients will connect
- clientport=2181
- #
- # be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http:
- #
- # 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=192.168.229.129:2888:3888
- server.2=192.168.229.130:2888:3888
# 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=/opt/zookeeper-3.4.0/data/zookeeper
datalogdir=/opt/zookeeper-3.4.0/data/log
# the port at which the clients will connect
clientport=2181
#
# 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=192.168.229.129:2888:3888
server.2=192.168.229.130:2888:3888
修改/opt/zookeeper-3.4.0/bin/zkserver.sh
- status)
- # -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
- #stat=`echo stat | nc -q 1 localhost $(grep "^[[:space:]]*clientport" "$zoocfg" | sed -e 's/.*=//') 2> /dev/null| grep mode`
- stat=`echo stat | nc localhost $(grep "^[[:space:]]*clientport" "$zoocfg" | sed -e 's/.*=//') 2> /dev/null| grep mode`
status)
# -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
#stat=`echo stat | nc -q 1 localhost $(grep "^[[:space:]]*clientport" "$zoocfg" | sed -e 's/.*=//') 2> /dev/null| grep mode`
stat=`echo stat | nc localhost $(grep "^[[:space:]]*clientport" "$zoocfg" | sed -e 's/.*=//') 2> /dev/null| grep mode`
以上这些多台机器一样
log和data都在datadir下面
如果找不到log了用大招:
ps -ef|grep zookeeper
ls -l /proc/123123/fd
其中有一个是log
然后datadir建立一个文件myid
在192.168.229.129上
echo 1 >/opt/zookeeper-3.4.0/data/zookeeper/myid
在192.168.229.130上
echo 2 >/opt/zookeeper-3.4.0/data/zookeeper/myid
对应zoo.cfg里面的
注意一定是数字 然后zkserver.sh start
启动
zkserver.sh status
看状态
echo ruok|nc localhost 2181
//are you ok?
echo dump|nc localhost 2181
echo stat|nc localhost 2181
echo srst|nc localhost 2181
zkserver.sh stop