zookeeper安装

Zookeeper 集群搭建

环境: CentOS release 6.10 + zookeeper-3.4.14

环境准备

特别注意防火墙问题

环境准备

下载解压

download

1
tar -zxvf zookeeper-3.4.14.tar.gz

修改配置文件

1
2
3
4
5
6
7
8
cp zoo_sample.cfg zoo.cfg
# 修改存储快照文件snapshot的目录(自己随便修改)
dataDir=/home/hadoop/zookeeper-3.4.14/tmp

# 添加集群节点信息,本机器上必须是0.0.0.0,否则其他机器访问,zk集群起不来,这里server.x中的x是一个数字,与myid文件中的id是一致的
server.1=0.0.0.0:2888:3888
server.2=server02:2888:3888
server.3=server03:2888:3888

创建myid文件

myid文件必须在dataDir目录下

1
2
mkdir /home/hadoop/zookeeper-3.4.14/tmp
echo 1 > /home/hadoop/apps/zookeeper-3.4.9/tmp/myid

启动

1
2
3
4
5
6
7
cd /home/hadoop/zookeeper-3.4.14
# 启动
bin/zkServer.sh start
# 查看状态
bin/zkServer.sh status
# 客户端连接
bin/zkCli.sh

问题:

  • 启动用户
    网上会有说必须用root用户启动,其实并不用
  • Error contacting service. It is probably not running.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # zkServer.sh start
    JMX enabled by default
    Using config: /usr/local/zk/bin/../conf/zoo.cfg
    Starting zookeeper … STARTED(正常启动就是这样的显示)

    查看状态却报错:
    # zkServer.sh status
    JMX enabled by default
    Using config: /usr/local/zk/bin/../conf/zoo.cfg
    Error contacting service. It is probably not running.(就是集群没有起来,可以根据zookeeper.out来查看失败原因)

Zookeep启动正常,却报错:Error contacting service. It is probably not running

  • 遇到问题排查思路
    # 确认进程是否启动
    [hadoop@server02 zookeeper-3.4.14]$ jps
    3216 QuorumPeerMain
    3303 Jps
    [hadoop@server02 zookeeper-3.4.14]$ netstat -tunlp|grep 3216
    # 确认端口是否开放
    (Not all processes could be identified, non-owned process info
    will not be shown, you would have to be root to see it all.)
    tcp        0      0 :::2181                     :::*                        LISTEN      3216/java
    tcp        0      0 :::2888                     :::*                        LISTEN      3216/java
    tcp        0      0 :::43919                    :::*                        LISTEN      3216/java
    tcp        0      0 :::3888                     :::*                        LISTEN      3216/java
    # 确认防火墙是否关闭
    [hadoop@server01 zookeeper-3.4.14]$ telnet  server02 3888
    Trying 100.80.128.165...
    Connected to server02.

Zookeeper 集群搭建