当前位置:   article > 正文

Linux之zookeeper安装配置

Linux之zookeeper安装配置

一、安装

cd /service
rz -e
tar zxvf zookeeper-3.4.6.tar.gz
cp ./zookeeper-3.4.6/conf/zoo_sample.cfg  ./zookeeper-3.4.6/conf/zoo.cfg 
  • 1
  • 2
  • 3
  • 4

二、修改配置
1、修改myid文件:

[root@h4 data]# pwd
/opt/zookeeper-3.4.5-cdh5.5.1/data
[root@h4 data]# more myid 
4
[root@h4 data]# 
mkdir -p /var/lib/zookeeper
touch /var/lib/zookeeper/myid
echo "1" >/var/lib/zookeeper/myid
cat /var/lib/zookeeper/myid
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2、修改hosts配置: 以下ip地址换成实际部署的地址

server.0=192.168.1.100:2888:3888
server.1=192.168.1.101:2888:3888
server.2=192.168.1.102:2888:3888
  • 1
  • 2
  • 3

以上不用修改hosts文件,直接在zoo.cfg文件下配置即可,要修改hosts也是可以的。

[root@beta-test-v5-zk01 ~]# cd /etc/
[root@beta-test-v5-zk01 etc]# vi hosts
#hosts文件内容如下
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.217.140  beta-test-v5-zk01.novalocal
192.168.217.140  zoo1
192.168.217.141  zoo2
192.168.217.142  zoo3
192.168.217.140  beta-test-v5-zk01
192.168.217.141  beta-test-v5-zk02
192.168.217.142  beta-test-v5-zk03
192.168.212.116 beta-test-V5-zk01
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

3、修改zookeeper配置文件路径:

vi /service/zookeeper-3.4.6/conf/zoo.cfg 
#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
# 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
dataDir=/var/lib/zk/zookeeper
dataLogDir=/var/lib/zk/logs
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

三、同样配置第二台和第三台
第二台机器:

mkdir -p /var/lib/zookeeper
touch /var/lib/zookeeper/myid
echo "2" >/var/lib/zookeeper/myid
cat /var/lib/zookeeper/myid
  • 1
  • 2
  • 3
  • 4

第三台机器:

mkdir -p /var/lib/zookeeper
touch /var/lib/zookeeper/myid
echo "3" >/var/lib/zookeeper/myid
cat /var/lib/zookeeper/myid
  • 1
  • 2
  • 3
  • 4

四、启动zookeeper 每台服务器各自启动
进入目录: /opt/zookeeper-3.4.5-cdh5.5.1
启动命令:sh bin/zkServer.sh start 回车后启动
查看状态:sh bin/zkServer.sh status 回车后返回本台服务器是leader还是follower 例如:

ZooKeeper JMX enabled by default
Using config: /service/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
  • 1
  • 2
  • 3

----这样,说明启动正常
核心总结:zoo.cfg里面的ip配置,dataDir=/var/lib/zk/zookeeper目录下myid的设置,zookeeper的运行依赖于jdk,在搭建之前需具备jdk环境。
参考链接
问题记录:
java.net.ConnectException: Connection refused

java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
        at java.net.Socket.connect(Socket.java:529)
        at java.net.Socket.connect(Socket.java:478)
        at java.net.Socket.<init>(Socket.java:375)
        at java.net.Socket.<init>(Socket.java:189)
        at TCPClient.main(TCPClient.java:13)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

原因分析:

  • You are trying to connect to the wrong IP/Host or port.
  • You have not started your server.
  • Your server is not listening for connections.
  • On Windows servers, the listen backlog queue is full.
    StackOverflow的解答
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/968254
推荐阅读
相关标签
  

闽ICP备14008679号