zookeeper 使用(一)

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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值