码迷,mamicode.com
首页 > 其他好文 > 详细

zookeeper replicated模式

时间:2015-03-02 23:56:07      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:zookeeper

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/packages/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 minSessionTimeout 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/version-2/snapshot.100000000




zookeeper replicated模式

标签:zookeeper

原文地址:http://blog.csdn.net/csfreebird/article/details/44007295

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!