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
zookeeper源码安装
00-zookeeper启动报错: myid file is missing 和 Problem starting AdminServer
02-zookeeper集群搭建
2016/05/14 08:00 于 数据分析
0
zookeeper集群节点启动时候会读取“dataDir”目录下的id,所以必须在对应节点的“dataDir”目录下创建“myid”文件,里面填写serverid
举例:
vim conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper
clientPort=2181
server.1=192.168.1.128:2008:6008
server.2=192.168.1.128:2008:6008
server.3=192.168.1.129:2008:6008
我在这里就需要在
“192.168.1.127”节点echo "1" >/data/zookeeper/myid
“192.168.1.128”节点echo "2" >/data/zookeeper/myid
“192.168.1.129”节点echo "3" >/data/zookeeper/myid
2016-05-14 12:01:01,079 [myid:] - INFO [main:QuorumPeerConfig@114] - Reading configuration from: /usr/local/zookeeper/bin/../conf/zoo.cfg
2016-05-14 12:01:01,085 [myid:] - INFO [main:QuorumPeerConfig@316] - clientPortAddress is 0.0.0.0/0.0.0.0:2181
2016-05-14 12:01:01,085 [myid:] - INFO [main:QuorumPeerConfig@320] - secureClientPort is not set
2016-05-14 12:01:01,089 [myid:] - ERROR [main:QuorumPeerMain@86] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /usr/local/zookeeper/bin/../conf/zoo.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:135)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:110)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:79)
Caused by: java.lang.IllegalArgumentException: myid file is missing
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.checkValidity(QuorumPeerConfig.java:637)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.setupQuorumPeerConfig(QuorumPeerConfig.java:508)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:348)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:131)
... 2 more
Invalid config, exiting abnormally
zookeeper的管理员端口被占用,需要修改配置里的“zookeeper.admin.serverPort=8080”,默认8080没有写出来,只要改为一个没使用端口即可
2016-05-14 12:17:36,385 [myid:1] - WARN [main:QuorumPeer@723] - Problem starting AdminServer
org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands
at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:100)
at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:721)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:183)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:120)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:79)
Caused by: java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:216)
at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:315)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.Server.doStart(Server.java:235)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:96)
... 4 more
org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands
zookeeper
zookeeper源码安装
00-zookeeper启动报错: myid file is missing 和 Problem starting AdminServer
2016/04/15 22:56 于 数据分析
0
介绍
zookeeper是一个管理分布式服务协调的开源服务,它本身亦是分布式服务。
是hadoop,Hbase,codis服务的重要组件,为分布式应用提供一致性服务:配置维护,域名服务,分布式同步,组服务等。
下载安装包
yum -y install openjdk
wget http://apache.fayea.com/zookeeper/zookeeper-3.5.1-alpha/zookeeper-3.5.1-alpha.tar.gz
tar zxf zookeeper-3.5.1-alpha.tar.gz
cd zookeeper-3.5.1-alpha
配置文件
这里先使用默认设置
cat ./conf/zoo.cfg
tickTime=2000 单位毫秒,用来做两次心跳最低超时时间间隔
initLimit=10 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
syncLimit=5 F节点和L节点最多心跳失败5次。
dataDir=/data/zookeeper 内存数据快照到本地的数据,除非特别说明,否则将是更新事物日志。
clientPort=2181 客户端端口
启动服务
zookeeper默认会占用2181,8080,55144三个端口
[root@salt-master zookeeper-3.5.1-alpha]# ./bin/zkServer.sh
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.5.1-alpha/bin/../conf/zoo.cfg
Usage: ./bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}
[root@salt-master zookeeper-3.5.1-alpha]# ./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.5.1-alpha/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
连接测试
./bin/zkCli.sh -server 192.168.1.115:2181
Connecting to 192.168.1.115:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 192.168.1.115:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: 192.168.1.115:2181(CONNECTED) 4] ls2 /zookeeper
'ls2' has been deprecated. Please use 'ls [-s] path' instead.
[config, quota]
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -2
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 2
查看zookeeper服务信息
[root@salt-master codis]# echo stat | nc 192.168.1.115 2181
Zookeeper version: 3.5.1-alpha-1693007, built on 07/28/2015 07:19 GMT
Clients:
/192.168.1.115:56637[0](queued=0,recved=1,sent=0)
/192.168.1.115:56608[1](queued=0,recved=160,sent=160)
Latency min/avg/max: 0/0/22
Received: 162
Sent: 161
Connections: 2
Outstanding: 0
Zxid: 0x1
Mode: standalone
Node count: 5