Zookeeper集群的配置与使用

原创
2017/03/29 16:51
阅读数 66

第一步:首先下载zookeeper安装文件,这里使用的版本3.4.9.将软件解压:

tar -zxvf zookeeper-3.4.9.tar.gz -C /home/dd171290/apps/

第二步:配置bin目录,这一步可以省略。方便启动服务。

sudo vi /etc/profile
#末尾添加如下
export ZOOKEEPER_HOME=/home/dd171290/apps/zookeeper-3.4.9
export PATH=$PATH:$ZOOKEEPER_HOME/bin
#最后使用source命令
source /etc/profile

第三步:配置zookeeper

将zookeeper-3.4.9/conf/zoo_sample.cfg 修改为zoo.cfg文件

cp  zookeeper-3.4.9/conf/zoo_sample.cfg  zookeeper-3.4.9/conf/zoo.cfg 

在zoo.cfg配置三个地方:

dataDir=/home/dd171290/apps/zookeeper-3.4.9/data    
dataLogDir=/home/dd171290/apps/zookeeper-3.4.9/log

#在末尾配置:格式:server.id:(主机名, 心跳端口、数据端口)

server.1=192.168.1.111:2888:3888 
server.2=192.168.1.112:2888:3888
server.3=192.168.1.113:2888:3888

# 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=/home/dd171290/apps/zookeeper-3.4.9/data    
dataLogDir=/home/dd171290/apps/zookeeper-3.4.9/log
# 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=192.168.1.111:2888:3888
server.2=192.168.1.112:2888:3888
server.3=192.168.1.113:2888:3888

第四步:创建目录

创建data目录和log目录
dataDir=/home/dd171290/apps/zookeeper-3.4.9/data    
dataLogDir=/home/dd171290/apps/zookeeper-3.4.9/log

然后在data目录下创建文件myid,其内容为主机名对应的id。同样的将配置好的文件拷贝到其他机器并配置bin。

scp -r  apps/zookeeper-3.4.9  dd171290@192.168.1.112:/home/dd171290/apps/
scp -r  apps/zookeeper-3.4.9  dd171290@192.168.1.113:/home/dd171290/apps/

修改对应的myid:

192.168.1.111 myid为1
192.168.1.112 myid为2
192.168.1.113 myid为3

第五步:启动zookeeper

/home/dd171290/apps/zookeeper-3.4.9/bin/zkServer.sh start

#启动客户端
/home/dd171290/apps/zookeeper-3.4.9/bin/zkCli.sh

注意:所有的zookeeper服务都要启动

启动过程中出现的问题:

[main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
[main-SendThread(localhost:2181):ClientCnxn$SendThread@1158] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect

查看日志文件发现:java.net.bindexception: address already in use

表示客户端启动的线程ID被占用,需要重新分配。如果还未解决重启系统,再启动zookeeper。

出现这种错误的原因有很多种:在StackOverflow上有一种解决办法,仅供参考。

http://stackoverflow.com/questions/13316776/zookeeper-connection-error

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部