zookeeper replicated模式

standalone适合开发,因为是单机,因此不能作为产品环境使用。先准备三台Ubuntu虚拟机,IP地址分别为:

192.168.1.70 zka
192.168.1.71 zkb
192.168.1.72 zkc

然后在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/zk_data
# 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.1=zka:2888:3888
server.2=zkb:2888:3888
server.3=zkc:2888:3888

注意最下面三行,zka/zkb/zkc是hostname,因为前面在hosts都已经配置了相应的IP地址,因此不会找不到主机。

2888端口是zookeeper服务相互通信使用的,3888端口是zookeeper服务选举使用的。

server.后面的1,2和3需要做些配置,在每台服务器的dataDir目录下(我这里是/opt/zk_data),创建myid文件,里面包含对应的1,2和3.

然后分别启动三台服务器上的zookeeper server。

bin/zkServer.sh start
由于我没有设置日志目录,所以可以看一下默认日志文件zookeeper.out, 没有错误,一切正常。

2015-03-02 15:43:00,685 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.library.path=/usr/java/pa\
ckages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-03-02 15:43:00,685 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.io.tmpdir=/tmp
2015-03-02 15:43:00,685 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.compiler=<NA>
2015-03-02 15:43:00,685 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.name=Linux
2015-03-02 15:43:00,686 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.arch=amd64
2015-03-02 15:43:00,686 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.version=3.2.0-59-virtual
2015-03-02 15:43:00,686 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.name=root
2015-03-02 15:43:00,686 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.home=/root
2015-03-02 15:43:00,686 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.dir=/opt/zookeeper-3.4.6
2015-03-02 15:43:00,687 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:ZooKeeperServer@162] - Created server with tickTime 2000 minSessionT\
imeout 4000 maxSessionTimeout 40000 datadir /opt/zk_data/version-2 snapdir /opt/zk_data/version-2
2015-03-02 15:43:00,687 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Follower@63] - FOLLOWING - LEADER ELECTION TOOK - 34
2015-03-02 15:43:00,738 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:Learner@326] - Getting a snapshot from leader
2015-03-02 15:43:00,745 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FileTxnSnapLog@240] - Snapshotting: 0x100000000 to /opt/zk_data/vers\
ion-2/snapshot.100000000




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值