搭建zookeeper集群(Debian 8)

环境信息

三台虚拟机节点(192.168.100.171<debian171>, 192.168.100.172<debian172>, 192.168.100.173<debian173>)

Debian jessie 8.5 

Zookeeper 3.4.8

安装zookeeper

#解压zookeeper

tar xvf zookeeper-3.4.8.tar.gz
sudo mkdir /usr/local/zookeeper
sudo mv zookeeper-3.4.8 /usr/local/zookeeper

#配置环境变量(可略过)

vi ~/.profile
export ZK_HOME=/usr/local/zookeeper/zookeeper-3.4.8/
export PATH=$ZK_HOME/bin:$PATH

 该步骤仅为便于zk命令调用,可以略过

#修改zoo.cfg

cd /usr/local/zookeeper/zookeeper-3.4.8/conf
cp zoo_sample.cfg zoo.cfg
vi 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=/tmp/zookeeper
dataDir=/var/lib/zookeeper
# 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=debian171:2888:3888
server.2=debian172:2888:3888
server.3=debian173:2888:3888

其中dataDir修改为/var/lib/zookeeper,/tmp路径仅作开发时使用

另外需要在hosts中将hostname配置进去,zoo.cfg中的server需要配置为hostname,不能使用ip,否则无法正常启动

127.0.0.1	localhost
192.168.100.171	debian171
192.168.100.172	debian172
192.168.100.173	debian173

其他节点的zoo.cfg和hostname基本一致

#设置myid

sudo echo “1” > /var/lib/zookeeper/myid

根据zoo.cfg中的配置,为各节点设置myid

#启动zookeeper

zkServer.sh start

逐个节点启动zk,刚开始server.1和server.2会报如下警告,当3台节点都启动后,就没有问题了

2016-07-06 11:40:36,108 [myid:1] - WARN  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@400] - Cannot open channel to 2 at election address debian172/192.168.100.172:3888
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:381)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:426)
        at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:843)
        at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:822)

Well done!

参考资料:

http://www.linuxidc.com/Linux/2015-02/114230.htm

http://blog.csdn.net/shirdrn/article/details/7183503

转载于:https://my.oschina.net/norxiva/blog/707204

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值