zookeeper3.4.8安装和集群搭建

Posted guan-li

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zookeeper3.4.8安装和集群搭建相关的知识,希望对你有一定的参考价值。


1.环境准备

创建zookeeper用户.
准备安装包: zookeeper-3.4.8.tar.gz.
拷贝至安装目录并解压

tar zxvf zookeeper-3.3.6.tar.gz
mv zookeeper-3.3.6 zookeeper

2.配置文件

  • zookeeper/conf/zoo.cfg(需手动创建)
#zookeeper使用的基本时间单位(ms)
tickTime=2000

#leader和follow之间的最长心跳时间(ticktime的倍数)
initLimit=5

#leader和follower之间的消息交换的最长时间(ticktime的倍数)
syncLimit=2

#数据目录
dataDir=/home/zookeeper/zookeeper/data

#日志目录,该目录事先创建,否则无法启动
dataLogDir=/home/zookeeper/zookeeper/logs

#服务端口
clientPort=2181

#server0...分别对应集群中的各台,ip:数据交换端口:leader选举端口
server.0=192.168.163.101:8880:7770
server.1=192.168.163.102:8880:7770
server.2=192.168.163.103:8880:7770

  • zookeeper/data/myid(需手动创建)
#唯一标识
0

拷贝至其他节点,此文件对应修改.


  • .bashrc
export ZOOKEEPER_HOME=/home/zookeeper/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf:$PATH

source .bashrc


3.启动

各节分别执行启动

zkServer.sh start

注意: 启动第一个节点时,由于其他两个节点未启动,所以会报错,不用管.

java.net.ConnectException: 拒绝连接
        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: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)
2018-05-16 19:40:26,103 [myid:0] - INFO  [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:[email protected]] - Resolved hostname: 192.168.163.103 to address: /192.168.163.103
2018-05-16 19:40:26,104 [myid:0] - WARN  [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:[email protected]] - Cannot open channel to 1 at election address /192.168.163.102:7770

4.测试

  • jps查看进程
QuorumPeerMain
  • 查看节点状态
./zkServer.sh status
  • 启动客户端
./zkCli.sh -server localhost:2181
  • 创建节点
create /zk ‘test‘
get /zk
quit


以上是关于zookeeper3.4.8安装和集群搭建的主要内容,如果未能解决你的问题,请参考以下文章

CentOS下ZooKeeper 3.4.8 集群环境搭建

solr6安装部署

zookeeper集群一次性启动

kafka--linux环境搭建

基于hadoop2.7集群的Spark2.0,Sqoop1.4.6,Mahout0.12.2完全分布式安装

kafka安装以及入门demo