zookeeper cluster setup

1 下载zookeeper, 我用了之前的稳定版本3.3.6

可参考安装:
http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html
http://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html#sc_maintenance

2 解压安装, 如果是cluster安装, 最好选取奇数的server, 原因在于zookeeper的leader election的策略.

3 修改zookeeper的配置文件, 默认启动时会使用conf/zoo.cfg.
http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/

# The number of milliseconds of each tick
#每个心跳的单位时间, 也是其他属性的基础时间单位
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take,
# 在集群中, follower和leader建立连接时的超时
initLimit=10

# The number of ticks that can pass between
# sending a request and getting an acknowledgement
#这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒
syncLimit=5

# the directory where the snapshot is stored.
dataDir=/var/zookeeper

# the port at which the clients will connect
clientPort=2181

#集群server配置, 2888是follower和leader进行通讯的端口, 3888是选举leader时使用的端口
server.1=10.0.3.130:2888:3888
server.2=10.0.3.153:2888:3888
server.3=10.0.3.115:2888:3888

4 根据上述配置, 建立/var/zookeeper目录, 并在目录下创建文件myid, myid的内容只有相应的server.X中的X. 比如在10.0.3.130上, myid的内容是1.

5 启动zookeeper服务, sh zkServer.sh start

6 检验集群是否配置成功, sh zkCli.sh -server 127.0.0.1:2181.
在命令行下输入help, 可以得到帮助信息.

猜你喜欢

转载自shixin42.iteye.com/blog/1707448