zookeeper环境搭建

系统:CentOS6.7,CentOS7,Red Hat Enterprise
软件:zookeeper-3.4.8.tar.gz
准备:

  1. 下载zookeeper:http://apache.fayea.com/zookeeper/
    或者:wget http://apache.fayea.com/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz
    (需要安装wget : yum install -y wget
  2. 关闭系统防火墙:
    CentOS6/Red Hat Enterprise : service iptables stop
    CentOS7 : systemctl stop firewalld.service

安装(三个系统修改一致):

  1. 解压安装包:tar -zxvf zookeeper-3.4.8.tar.gz

  2. cd到解压目录conf下:cd zookeeper-3.4.8/conf

  3. 复制配置文件cp zoo_sample.cfg zoo.cfg

  4. 修改配置文件(用以下内容覆盖即可):配置参数说明

tickTime=2000
initLimit=5
syncLimit=2
dataDir=/usr/log/zookeeper/
clientPort=2181
server.1=slave-01:2888:3888
server.2=slave-02:2888:3888
server.3=slave-03:2888:3888
  1. 新建目录/usr/log/zookeeper
mkdir -p /usr/log/zookeeper
  1. 在目录下新建myid
vi myid

*三个系统中的这个需要做区分需要与配置(4)的server.id对应
CentOS6中的myid为1
CentOS7 中的myid为 2
Red Hat Enterprise 中的myid为 3*

  1. 修改hosts : vi /etc/hosts ip地址 与其对应的节点名称,添加以下配置
192.168.82.251   slave-01
192.168.82.252   slave-02
192.168.82.8     slave-03

测试
按照myid依次(随意)启动zookeeper: bin/zkServer.sh start

016-06-16 20:36:19,222 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.name=Linux
2016-06-16 20:36:19,222 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.arch=amd64
2016-06-16 20:36:19,222 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.version=3.10.0-327.18.2.el7.x86_64
2016-06-16 20:36:19,222 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.name=root
2016-06-16 20:36:19,222 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.home=/root
2016-06-16 20:36:19,222 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.dir=/usr/soft/apache/zk/zookeeper-3.4.8/bin
2016-06-16 20:36:19,224 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:ZooKeeperServer@170] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /user/log/zookeeper/version-2 snapdir /user/log/zookeeper/version-2
2016-06-16 20:36:19,225 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Leader@361] - LEADING - LEADER ELECTION TOOK - 54873
2016-06-16 20:36:19,682 [myid:2] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@192] - Accepted socket connection from /192.168.82.77:62516
2016-06-16 20:36:19,683 [myid:2] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@362] - Exception causing close of session 0x0 due to java.io.IOException: ZooKeeperServer not running
2016-06-16 20:36:19,683 [myid:2] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1008] - Closed socket connection for client /192.168.82.77:62516 (no session established for client)
2016-06-16 20:36:29,227 [myid:2] - WARN  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:QuorumPeer@862] - Unexpected exception
java.lang.InterruptedException: Timeout while waiting for epoch from quorum
    at org.apache.zookeeper.server.quorum.Leader.getEpochToPropose(Leader.java:881)
    at org.apache.zookeeper.server.quorum.Leader.lead(Leader.java:380)
    at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:859)
2016-06-16 20:36:29,228 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Leader@496] - Shutting down
2016-06-16 20:36:29,228 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Leader@502] - Shutdown called
java.lang.Exception: shutdown Leader! reason: Forcing shutdown
    at org.apache.zookeeper.server.quorum.Leader.shutdown(Leader.java:502)
    at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:865)
2016-06-16 20:36:29,228 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:QuorumPeer@774] - LOOKING
2016-06-16 20:36:29,228 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@818] - New election. My id =  2, proposed zxid=0x30000068e
2016-06-16 20:36:29,229 [myid:2] - INFO  [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 2 (n.leader), 0x30000068e (n.zxid), 0x2 (n.round), LOOKING (n.state), 2 (n.sid), 0x3 (n.peerEpoch) LOOKING (my state)
2016-06-16 20:36:29,230 [myid:2] - INFO  [LearnerCnxAcceptor-slave-02/192.168.82.252:2888:Leader$LearnerCnxAcceptor@325] - exception while shutting down acceptor: java.net.SocketException: Socket closed
2016-06-16 20:36:29,231 [myid:2] - INFO  [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x30000068e (n.zxid), 0x2 (n.round), FOLLOWING (n.state), 1 (n.sid), 0x4 (n.peerEpoch) LOOKING (my state)
2016-06-16 20:36:29,232 [myid:2] - INFO  [WorkerReceiver[myid=2]:FastLeaderElection@600] - Notification: 1 (message format version), 3 (n.leader), 0x30000068e (n.zxid), 0x2 (n.round), LEADING (n.state), 3 (n.sid), 0x4 (n.peerEpoch) LOOKING (my state)
2016-06-16 20:36:29,232 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:QuorumPeer@844] - FOLLOWING
2016-06-16 20:36:29,237 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Learner@86] - TCP NoDelay set to: true
2016-06-16 20:36:29,238 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:ZooKeeperServer@170] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /user/log/zookeeper/version-2 snapdir /user/log/zookeeper/version-2
2016-06-16 20:36:29,238 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Follower@63] - FOLLOWING - LEADER ELECTION TOOK - 10
2016-06-16 20:36:29,239 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:QuorumPeer$QuorumServer@149] - Resolved hostname: slave-03 to address: slave-03/192.168.82.8
2016-06-16 20:36:29,245 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Learner@326] - Getting a diff from the leader 0x30000068e
2016-06-16 20:36:29,248 [myid:2] - INFO  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:FileTxnSnapLog@240] - Snapshotting: 0x30000068e to /user/log/zookeeper/version-2/snapshot.30000068e
2016-06-16 20:36:59,987 [myid:2] - WARN  [QuorumPeer[myid=2]/0:0:0:0:0:0:0:0:2181:Follower@118] - Got zxid 0x400000001 expected 0x1
2016-06-16 20:36:59,987 [myid:2] - INFO  [SyncThread:2:FileTxnLog@199] - Creating new log file: log.400000001
2016-06-16 20:37:20,620 [myid:2] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@192] - Accepted socket connection from /192.168.82.77:62546
2016-06-16 20:37:20,627 [myid:2] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@900] - Client attempting to establish new session at /192.168.82.77:62546
2016-06-16 20:37:20,837 [myid:2] - INFO  [CommitProcessor:2:ZooKeeperServer@645] - Established session 0x255593675c00000 with negotiated timeout 40000 for client /192.168.82.77:62546

启动成功,客户端成功连接。

搞了一天的时间算是有个成果吧只是简单的搭建,研究的只是九牛一毛,望小伙伴指正!

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值