zookeeper简介
zookeeper是apache的一个子项目,通常用在分布式管理服务,多个server节点,少数server down并不会影响整个zookeeper服务。
zookeeper 配置及部署:
单服务器模式的配置。注意:dataDir一定不能使/tmp/,否则会出现内存错误。
这样的配置,启动zookeeper服务就在本机可以使用zookeeper服务了。
./zkServer.sh start ../conf/zoo.cfg
多服务器模式部署。zookeeper是为集群配置管理等需求出现的,所以更多是这种部署。
这里展示单服务器伪集群式部署。实际使用肯定是多服务器部署。
server1配置conf/zoo1.cfg
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/
# the port at which the clients will connect
clientPort=2181
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
注意:dataDir下放一个myid文件表示这个server。echo 1 > /data/zookeeper/myid
server2配置
server2配置conf/zoo2.cfg
<span style="font-size:18px;">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/
# the port at which the clients will connect
clientPort=2182
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890</span>
echo 2 > /data/zookeeper/myid
server3配置
server3配置conf/zoo3.cfg
<span style="font-size:18px;"><span style="font-size: 18px;">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/
# the port at which the clients will connect
clientPort=2183
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890</span></span>
echo 3 > /data/zookeeper/myid
- server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。
启动服务:
./zkServer.sh start ../conf/zoo1.cfg
./zkServer.sh start ../conf/zoo2.cfg
./zkServer.sh start ../conf/zoo3.cfg
参考:http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/