02-zookeeper集群搭建
2016/05/14 13:16 于 安全 0
首先准备三个节点
192.168.1.127
192.168.1.128
192.168.1.129
先安装zookeeper
cd /usr/local/src/
wget http://apache.fayea.com/zookeeper/zookeeper-3.5.1-alpha/zookeeper-3.5.1-alpha.tar.gztar zxf zookeeper-3.5.1-alpha.tar.gz
mv zookeeper-3.5.1-alpha /usr/local/zookeeper
更改三个节点配置
server.1=192.168.1.127:2008:6008
server.服务器编号=服务器地址:LF通信端口:选举端口
cd /usr/local/zookeeper && mkdir -p /data/zookeeper
vim conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper
clientPort=2181
server.1=192.168.1.127:2008:6008
server.2=192.168.1.128:2008:6008
server.3=192.168.1.129:2008:6008
启动前两个节点
./bin/zkServer.sh start
ZooKeeper JMX enabled by default
/usr/bin/java
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
你会发现有报错是因为其他节点没有起来
2016-05-14 12:05:18,540 [myid:3] - WARN [QuorumPeer[myid=3](plain=/0:0:0:0:0:0:0:0:2181)(secure=disabled):QuorumCnxManager@459] - Cannot open channel to 2 at election address /192.168.199.22
2:6008
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:444)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:485)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:513)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:919)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:1040)
查看集群状态
echo 'stat'|nc 192.168.1.128 2181
Zookeeper version: 3.5.1-alpha-1693007, built on 07/28/2015 07:19 GMT
Clients:
/192.168.1.128:182810
Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x100000000
Mode: follower
Node count: 5
查看节点角色[root@test-node4 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
/usr/bin/java
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
zookeeper
00-zookeeper启动报错: myid file is missing 和 Problem starting AdminServer