CentOS安装搭建zookeeper
原文连接:https://www.cnblogs.com/rwxwsblog/p/5806075.html
zookeeper集群搭建(三台)
注意关闭机器防火墙!
配置ip别名:编辑文件
# /etc/hosts
加入内容:
192.168.1.80 c1
192.168.1.81 c2
192.168.1.82 c3
zookeeper安装
# mkdir -p /var/download && cd /var/download
# wget -c http://www.eu.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
# tar zxvf zookeeper-3.4.6.tar.gz
# mkdir -p /var/local/server
# mv zookeeper-3.4.6 /var/local/server/zookeeper
# cd /var/local/server/zookeeper/conf
# touch zoo.cfg
配置 zoo.cfg,添加内容
tickTime=2000
dataDir=/var/data/zookeeper
dataLogDir=/var/local/server/zookeeper/log
clientPort=2181
initLimit=5
syncLimit=2
server.1=c1:2888:3888
server.2=c2:2888:3888
server.3=c3:2888:3888
创建数据目录和日志目录:
# mkdir -p /var/data/zookeeper
# mkdir -p /var/local/server/zookeeper/log
创建myid文件, id 与 zoo.cfg 中的序号对应,位置在数据目录下,c1为1、c2为2 、 c3为3
# echo 1 > /var/data/zookeeper/myid
常用命令:
启动
/var/local/server/zookeeper/bin/zkServer.sh start
查看状态
/var/local/server/zookeeper/bin/zkServer.sh status
重启
/var/local/server/zookeeper/bin/zkServer.sh restart
关闭
/var/local/server/zookeeper/bin/zkServer.sh stop
在其中一台用客户端连接
/var/local/server/zookeeper/bin/zkCli.sh -server c1:2181
操作实例:
- 启动:
/var/local/server/zookeeper/bin/zkServer.sh start
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
- 查看状态:
/var/local/server/zookeeper/bin/zkServer.sh status
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
此时发现zookeeper并没有正常运行。
查看日志more zookeeper.out
,发现如下异常:
2016-08-25 09:55:54,088 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 2 at election address c2/192.168.1.81:3888
java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:341)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:449)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:430)
at java.lang.Thread.run(Thread.java:745)
2016-08-25 09:55:54,101 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 3 at election address c3/192.168.1.82:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:341)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:449)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:430)
at java.lang.Thread.run(Thread.java:745)
2016-08-25 09:55:54,287 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@382] - Cannot open channel to 2 at election address c2/192.168.1.81:3888
java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:402)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:840)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:762)
这是由于2、3号机器没有正常配置导致。可以在zoo.cfg
中将其注释
后再次尝试。
tickTime=2000
dataDir=/var/data/zookeeper
dataLogDir=/var/local/server/zookeeper/log
clientPort=2181
initLimit=5
syncLimit=2
server.1=c1:2888:3888
#server.2=c2:2888:3888
#server.3=c3:2888:3888
正常启动效果:[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: standalone
测试
在 c1 上连接 c1 上的 zookeeper
/var/local/server/zookeeper/bin/zkCli.sh -server c1:2181
[root@sso conf]# /var/local/server/zookeeper/bin/zkCli.sh -server c1:2181
Connecting to c1:2181
2016-08-25 10:06:30,235 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-08-25 10:06:30,244 [myid:] - INFO [main:Environment@100] - Client environment:host.name=sso.xxx.com
2016-08-25 10:06:30,244 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_79
2016-08-25 10:06:30,250 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2016-08-25 10:06:30,251 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/jdk1.7.0_79/jre
2016-08-25 10:06:30,251 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/var/local/server/zookeeper/bin/../build/classes:/var/local/server/zookeeper/bin/../build/lib/*.jar:/var/local/server/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/var/local/server/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/var/local/server/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/var/local/server/zookeeper/bin/../lib/log4j-1.2.16.jar:/var/local/server/zookeeper/bin/../lib/jline-0.9.94.jar:/var/local/server/zookeeper/bin/../zookeeper-3.4.6.jar:/var/local/server/zookeeper/bin/../src/java/lib/*.jar:/var/local/server/zookeeper/bin/../conf:
2016-08-25 10:06:30,251 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2016-08-25 10:06:30,253 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-327.10.1.el7.x86_64
2016-08-25 10:06:30,253 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2016-08-25 10:06:30,253 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2016-08-25 10:06:30,254 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/var/local/server/zookeeper/conf
2016-08-25 10:06:30,257 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=c1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@194d62f1
Welcome to ZooKeeper!
2016-08-25 10:06:30,335 [myid:] - INFO [main-SendThread(sso.xxx.com:2181):ClientCnxn$SendThread@975] - Opening socket connection to server sso.xxx.com/192.168.1.80:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2016-08-25 10:06:30,349 [myid:] - INFO [main-SendThread(sso.xxx.com:2181):ClientCnxn$SendThread@852] - Socket connection established to sso.xxx.com/192.168.1.80:2181, initiating session
2016-08-25 10:06:30,412 [myid:] - INFO [main-SendThread(sso.xxx.com:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server sso.xxx.com/192.168.1.80:2181, sessionid = 0x156bf70d7580000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: c1:2181(CONNECTED) 0]
添加一个根节点目录zookeeper_project
create /project zookeeper_project
[zk: c1:2181(CONNECTED) 0] create /project zookeeper_project
Created /project
[zk: c1:2181(CONNECTED) 1] get /project
zookeeper_project
cZxid = 0x2
ctime = Thu Aug 25 10:09:09 CST 2016
mZxid = 0x2
mtime = Thu Aug 25 10:09:09 CST 2016
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 17
numChildren = 0
此时说明单机配置成功
多机集群
取消zoo.cfg中server.2
和server.3
的注释,最后zoo.cfg配置文件如下:
tickTime=2000
dataDir=/var/data/zookeeper
dataLogDir=/var/local/server/zookeeper/log
clientPort=2181
initLimit=5
syncLimit=2
server.1=c1:2888:3888
server.2=c2:2888:3888
server.3=c3:2888:3888
在c2和c3中执行类似的操作
多机联合测试
c1运行结果:
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: leader
c2运行结果:
[root@cas zookeeper]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
c3运行结果:
[root@localhost zookeeper]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
同步测试
c1上执行:
create /c1project c1projecttest
和get /c1project
[zk: c1:2181(CONNECTED) 2] create /c1project c1projecttest
Created /c1project
[zk: c1:2181(CONNECTED) 1] get /c1project
c1projecttest
cZxid = 0x100000013
ctime = Thu Aug 25 11:03:49 CST 2016
mZxid = 0x100000013
mtime = Thu Aug 25 11:03:49 CST 2016
pZxid = 0x100000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
c2上查看同步结果:
get /c1project
[zk: c2:2181(CONNECTED) 0] get /c1project
c1projecttest
cZxid = 0x100000013
ctime = Thu Aug 25 11:03:49 CST 2016
mZxid = 0x100000013
mtime = Thu Aug 25 11:03:49 CST 2016
pZxid = 0x100000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
c3上查看同步结果:
[zk: c3:2181(CONNECTED) 4] get /c1project
c1projecttest
cZxid = 0x100000013
ctime = Thu Aug 25 11:03:49 CST 2016
mZxid = 0x100000013
mtime = Thu Aug 25 11:03:49 CST 2016
pZxid = 0x100000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
此时说明zookeeper集群配置成功。
从节点主动升级和接管成为主节点
leader
和follower
的自动切换,前面我们知道c1是leader
,当leader
down掉后是否有从节点升级为leader
。
c1上执行
/var/local/server/zookeeper/bin/zkServer.sh stop
c2上查看状态
[root@cas ~]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
可以发现c2仍然为从节点
再看看c3
[root@localhost ~]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: leader
此时c3升级为了主节点
再次启动c1,并查看状态
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@sso conf]#
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
发现c1作为了从节点。
zookeeper部署及集群测试
zookeeper部署及集群测试
环境
三台测试机
- 操作系统: centos7 ; hostname: c1 ; ip: 192.168.1.80
- 操作系统: centos7 ; hostname: c2 ; ip: 192.168.1.81
- 操作系统: centos7 ; hostname: c3 ; ip: 192.168.1.82
备注
注意要关闭防火墙
查看磁盘状况
为了避免磁盘使用不均而导致系统问题,因而先查看磁盘的分布情况。
[root@sso conf]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 18G 33G 36% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 65M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-var 900G 529M 900G 1% /var
/dev/mapper/centos-home 66G 12G 55G 18% /home
/dev/sda1 497M 168M 330M 34% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@sso conf]#
/var目录共900G,只使用了1%不到,因此可以将后续的所有文件和程序存放在此目录下。当然,这要根据你的实际情况而定。
zookeeper安装
安装
mkdir -p /var/download && cd /var/download
wget -c http://www.eu.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar zxvf zookeeper-3.4.6.tar.gz
mkdir -p /var/local/server
mv zookeeper-3.4.6 /var/local/server/zookeeper
cd /var/local/server/zookeeper/conf
touch zoo.cfg
编辑zoo.cfg中加入如下内容:
tickTime=2000
dataDir=/var/data/zookeeper
dataLogDir=/var/local/server/zookeeper/log
clientPort=2181
initLimit=5
syncLimit=2
server.1=c1:2888:3888
server.2=c2:2888:3888
server.3=c3:2888:3888
保存
创建数据目录和日志目录:
mkdir -p /var/data/zookeeper
mkdir -p /var/local/server/zookeeper/log
如不创建启动时会报如下异常:
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
创建myid文件, id 与 zoo.cfg 中的序号对应
echo 1 > /var/data/zookeeper/myid
注意:
- 注意,如果是
c2
和c3
中进行相应的修改c2
上应改为:echo 2 > /var/data/zookeeper/myid
c3
上应改为:echo 3 > /var/data/zookeeper/myid
配置hosts文件:编辑/etc/hosts
,加入如下内容:
192.168.1.80 c1
192.168.1.81 c2
192.168.1.82 c3
常用命令
启动
/var/local/server/zookeeper/bin/zkServer.sh start
查看状态
/var/local/server/zookeeper/bin/zkServer.sh status
重启
/var/local/server/zookeeper/bin/zkServer.sh restart
关闭
/var/local/server/zookeeper/bin/zkServer.sh stop
在其中一台用客户端连接
/var/local/server/zookeeper/bin/zkCli.sh -server c1:2181
操作实例:
- 启动:
/var/local/server/zookeeper/bin/zkServer.sh start
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
- 查看状态:
/var/local/server/zookeeper/bin/zkServer.sh status
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
此时发现zookeeper并没有正常运行。
查看日志more zookeeper.out
,发现如下异常:
2016-08-25 09:55:54,088 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 2 at election address c2/192.168.1.81:3888
java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:341)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:449)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:430)
at java.lang.Thread.run(Thread.java:745)
2016-08-25 09:55:54,101 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 3 at election address c3/192.168.1.82:3888
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:341)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:449)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:430)
at java.lang.Thread.run(Thread.java:745)
2016-08-25 09:55:54,287 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@382] - Cannot open channel to 2 at election address c2/192.168.1.81:3888
java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:402)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:840)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:762)
这是由于2、3号机器没有正常配置导致。可以在zoo.cfg
中将其注释
后再次尝试。
tickTime=2000
dataDir=/var/data/zookeeper
dataLogDir=/var/local/server/zookeeper/log
clientPort=2181
initLimit=5
syncLimit=2
server.1=c1:2888:3888
#server.2=c2:2888:3888
#server.3=c3:2888:3888
正常启动效果:
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: standalone
测试
在 c1 上连接 c1 上的 zookeeper
/var/local/server/zookeeper/bin/zkCli.sh -server c1:2181
[root@sso conf]# /var/local/server/zookeeper/bin/zkCli.sh -server c1:2181
Connecting to c1:2181
2016-08-25 10:06:30,235 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-08-25 10:06:30,244 [myid:] - INFO [main:Environment@100] - Client environment:host.name=sso.xxx.com
2016-08-25 10:06:30,244 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_79
2016-08-25 10:06:30,250 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2016-08-25 10:06:30,251 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/jdk1.7.0_79/jre
2016-08-25 10:06:30,251 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/var/local/server/zookeeper/bin/../build/classes:/var/local/server/zookeeper/bin/../build/lib/*.jar:/var/local/server/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/var/local/server/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/var/local/server/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/var/local/server/zookeeper/bin/../lib/log4j-1.2.16.jar:/var/local/server/zookeeper/bin/../lib/jline-0.9.94.jar:/var/local/server/zookeeper/bin/../zookeeper-3.4.6.jar:/var/local/server/zookeeper/bin/../src/java/lib/*.jar:/var/local/server/zookeeper/bin/../conf:
2016-08-25 10:06:30,251 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2016-08-25 10:06:30,252 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2016-08-25 10:06:30,253 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-327.10.1.el7.x86_64
2016-08-25 10:06:30,253 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2016-08-25 10:06:30,253 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2016-08-25 10:06:30,254 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/var/local/server/zookeeper/conf
2016-08-25 10:06:30,257 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=c1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@194d62f1
Welcome to ZooKeeper!
2016-08-25 10:06:30,335 [myid:] - INFO [main-SendThread(sso.xxx.com:2181):ClientCnxn$SendThread@975] - Opening socket connection to server sso.xxx.com/192.168.1.80:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2016-08-25 10:06:30,349 [myid:] - INFO [main-SendThread(sso.xxx.com:2181):ClientCnxn$SendThread@852] - Socket connection established to sso.xxx.com/192.168.1.80:2181, initiating session
2016-08-25 10:06:30,412 [myid:] - INFO [main-SendThread(sso.xxx.com:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server sso.xxx.com/192.168.1.80:2181, sessionid = 0x156bf70d7580000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: c1:2181(CONNECTED) 0]
添加一个根节点目录zookeeper_project
create /project zookeeper_project
[zk: c1:2181(CONNECTED) 0] create /project zookeeper_project
Created /project
[zk: c1:2181(CONNECTED) 1] get /project
zookeeper_project
cZxid = 0x2
ctime = Thu Aug 25 10:09:09 CST 2016
mZxid = 0x2
mtime = Thu Aug 25 10:09:09 CST 2016
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 17
numChildren = 0
此时说明单机配置成功
多机集群
取消zoo.cfg中server.2
和server.3
的注释,最后zoo.cfg配置文件如下:
tickTime=2000
dataDir=/var/data/zookeeper
dataLogDir=/var/local/server/zookeeper/log
clientPort=2181
initLimit=5
syncLimit=2
server.1=c1:2888:3888
server.2=c2:2888:3888
server.3=c3:2888:3888
在c2和c3中执行类似的操作
多机联合测试
c1运行结果:
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: leader
c2运行结果:
[root@cas zookeeper]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
c3运行结果:
[root@localhost zookeeper]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
同步测试
c1上执行:
create /c1project c1projecttest
和get /c1project
[zk: c1:2181(CONNECTED) 2] create /c1project c1projecttest
Created /c1project
[zk: c1:2181(CONNECTED) 1] get /c1project
c1projecttest
cZxid = 0x100000013
ctime = Thu Aug 25 11:03:49 CST 2016
mZxid = 0x100000013
mtime = Thu Aug 25 11:03:49 CST 2016
pZxid = 0x100000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
c2上查看同步结果:
get /c1project
[zk: c2:2181(CONNECTED) 0] get /c1project
c1projecttest
cZxid = 0x100000013
ctime = Thu Aug 25 11:03:49 CST 2016
mZxid = 0x100000013
mtime = Thu Aug 25 11:03:49 CST 2016
pZxid = 0x100000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
c3上查看同步结果:
[zk: c3:2181(CONNECTED) 4] get /c1project
c1projecttest
cZxid = 0x100000013
ctime = Thu Aug 25 11:03:49 CST 2016
mZxid = 0x100000013
mtime = Thu Aug 25 11:03:49 CST 2016
pZxid = 0x100000013
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
此时说明zookeeper集群配置成功。
从节点主动升级和接管成为主节点
leader
和follower
的自动切换,前面我们知道c1是leader
,当leader
down掉后是否有从节点升级为leader
。
c1上执行
/var/local/server/zookeeper/bin/zkServer.sh stop
c2上查看状态
[root@cas ~]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
可以发现c2仍然为从节点
再看看c3
[root@localhost ~]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: leader
此时c3升级为了主节点
再次启动c1,并查看状态
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh start
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@sso conf]#
[root@sso conf]# /var/local/server/zookeeper/bin/zkServer.sh status
JMX enabled by default
Using config: /var/local/server/zookeeper/bin/../conf/zoo.cfg
Mode: follower
发现c1作为了从节点。
CentOS安装搭建zookeeper的更多相关文章
- ZooKeeper系列(1):安装搭建ZooKeeper环境
ZooKeeper系列文章:https://www.cnblogs.com/f-ck-need-u/p/7576137.html#zk ZooKeeper有三种安装模式:单机安装(standalone ...
- CentOS 7搭建Zookeeper和Kafka集群
环境 CentOS 7.4 Zookeeper-3.6.1 Kafka_2.13-2.4.1 Kafka-manager-2.0.0.2 本次安装的软件全部在 /home/javateam 目录下. ...
- centos安装单机zookeeper
1.下载zookeeper版本 wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz ...
- Linux CentOS安装搭建FTP文件服务
本文环境:centos7,IP=192.168.1.11 1.安装vsftpd和默认配置启动 1.1 安装vsftpd yum install -y vsftpd 1.2 启动vsftpd syste ...
- centos安装服务参考博客,亲测可用
centos 安装nginx参考 日志log报错 nginx -c /etc/nginx/nginx.conf https://blog.csdn.net/weixin_41004350/articl ...
- Hadoop集群搭建-02安装配置Zookeeper
Hadoop集群搭建-05安装配置YARN Hadoop集群搭建-04安装配置HDFS Hadoop集群搭建-03编译安装hadoop Hadoop集群搭建-02安装配置Zookeeper Hado ...
- centos 6.5 搭建zookeeper集群
为什么使用Zookeeper? 大部分分布式应用需要一个主控.协调器或控制器来管理物理分布的子进程(如资源.任务分配等)目前,大部分应用需要开发私有的协调程序,缺乏一个通用的机制协调程序的反复编写浪费 ...
- 虚拟机搭建Zookeeper服务器集群完整笔记
虚拟机搭建Zookeeper服务器集群完整笔记 本笔记主要记录自己搭建Zookeeper服务器的全过程,默认已经安装部署好Centos7. 一.虚拟机下Centos无法联网解决方案 1.首先调整虚拟机 ...
- 搭建zookeeper和Kafka集群
搭建zookeeper和Kafka集群: 本实验拥有3个节点,均为CentOS 7系统,分别对应IP为10.211.55.11.10.211.55.13.10.211.55.14,且均有相同用户名 ( ...
随机推荐
- c# ftp 判断目录是否存在和创建文件夹
工作中项目一直使用的ftp上传日志文件出现了问题,新的服务器搭建好后,日志无法上传.正好来学习一下ftp. 程序中的流程是,一个计时器,每分钟检测配置文件中本地日志文件路径下有没有日志文件,如果有就上 ...
- 关于sudo apt-get update错误 http://archive.canonical.com natty InRelease
sudo apt-get update 错误 http://archive.canonical.com natty InRelease 错误 http://mirror.rootguide.org n ...
- java校验银行卡号
public class CheckBankCard { /* 校验过程: 1.从卡号最后一位数字开始,逆向将奇数位(1.3.5等等)相加. 2.从卡号最后一位数字开始,逆向将偶数位数字,先乘以2(如 ...
- Google-优秀移动站点设计10招
Google-优秀移动网站设计10招 1)添加一个醒目的搜索条:在移动终端上,人们希望能够快速找到自己需要的东西 2)把大表格拆分成小块:别搞一个长长的表格页面,上面包含各种输入框 3)允许用户匿名浏 ...
- Windows下搭建JSP开发环境
1. 配置说明: => 编辑器: Eclipse (Java EE IDE) => 数据库: MySQL (MySQL Workbench 进行数据库管理, 用 MySQL Connect ...
- 38 写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度. public class _038PrintLength { public static void main(Stri ...
- 编写高质量代码改善C#程序的157个建议——建议114:MD5不再安全
建议114:MD5不再安全 MD5不再安全不是就算法本身而言的.如果从可逆性的角度出发,MD5值不存在被破解的可能性. MD5被广泛应用于密码验证和消息完整性验证.假设新注册一个用户,当注册用户的密码 ...
- Android-ListView-CursorAdapter
在上篇博客,Android-ListView-SimpleCursorAdapter,中介绍了SimpleCurosrAdapter的使用操作(SimpleCursorAdapter是简单便捷Curs ...
- oracle数据库sqlldr命令的使用
将数据导入 oracle 的方法应该很多 , 对于不同需求有不同的导入方式 , 最近使用oracle的sqlldr命令 导入数据库数据感觉是个挺不错的技术点 . 使用sqlldr命令 将文本文件导入 ...
- solr入门教程-较详细
Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注意事项;主要包括以下内容:环境搭建及调试;两个核心配置文件介绍;维护索引;查询索引,和在 ...