Zookeeper install on CentOS 7

Good concise article here on devopscube for installing zookeeper cluster. I’ve added some of my own bits:

Firewall

Disable firewalld or allow ports 2181 3888 2888

Install Java

yum install java-1.8.0-openjdk

Install Zookeeper

Download ZooKeeper from the Apache:

wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

mv zookeeper-3.4.10.tar.gz /opt
cd /opt
tar xzf zookeeper-3.4.10.tar.gz
ln -s zookeeper-3.4.10 ./zookeeper
cd zookeeper

mkdir data

User

Create a zookeeper user

groupadd zookeeper
useradd -g zookeeper -d /opt/zookeeper -s /sbin/nologin zookeeper

Set the permissions:

chown -R zookeeper:zookeeper /opt/zookeeper/*
vi /opt/zookeeper/conf/zoo.cfg

Add the following:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/data
clientPort=2181
server.1=192.168.187.75:2888:3888
server.2=192.168.187.77:2888:3888
server.3=192.168.187.78:2888:3888

Test the service:

/opt/zookeeper/bin/zkServer.sh start

Ctrl-c out of that and lets create a systemd unit file for the service.

Systemd

vi /usr/lib/systemd/system/zookeeper.service

Add the following:

[Unit]
Description=Zookeeper Service

[Service]
Type=simple
WorkingDirectory=/opt/zookeeper/
PIDFile=/opt/zookeeper/data/zookeeper_server.pid
SyslogIdentifier=zookeeper
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
Restart=always
TimeoutSec=20
SuccessExitStatus=130 143
Restart=on-failure

[Install]
WantedBy=multi-user.target

Next

systemctl daemon-reload
systemctl enable zookeeper.service
systemctl start zookeeper.service

Test

Running the following will give a client interface to the zookeeper service:

/opt/zookeeper/bin/zkCli.sh

There are some examples here but you can create and get info as shown below:

To check which nodes are followers and which is the leader try issuing the following commands to each node:

echo srvr | nc localhost 2181

There is excellent information on monitoring Zookeeper here (from ServerDenisty) and a Nagios check here.

Troubleshooting

  • Reset the user permissions on the /opt/zookeeper directory recursively
  • Switch off firewalld and/or check a telnet connect to port 2181 on each node
  • Try switching to the zookeeper user (su – zookeeper -s /bin/bash) and run the zkServer.sh start command

8 Responses to “Zookeeper install on CentOS 7”

  1. Gokul

    I am stuck at the step “cd zookeeper”

    [kafka@Kafka opt]$ cd /zookeeper
    -bash: cd: /zookeeper: No such file or directory

    Reply
    • jonny

      You’ve got a slash in front of zookeeper. To navigate from the root you could use:
      cd /opt/zookeeper

      Reply
  2. Stuart

    When you create the zookeeper account, a home directory “/opt/zookeeper” is created:

    useradd -g zookeeper -d /opt/zookeeper -s /sbin/nologin zookeeper

    This command conflicts with creating a link to a common “zookeeper” directory:

    ln -s zookeeper-3.4.10 ./zookeeper

    The link fails and subsequent commands do not work correctly.

    Reply
    • jonny

      apologies, I have now moved the user creation commands to after the creation of the symlink

      Reply
  3. Will Gutshall

    Using config: /opt/zookeeper/bin/../conf/zoo.cfg
    Starting zookeeper … FAILED TO START

    I tried installing this on RHEL and CentOS and I’m getting this same issue.

    Reply
    • Dan

      I had similar. Had to switch out server in /opt/zookeeper/conf/zoo.cfg

      e.g. instead of

      server.1=192.168.187.75:2888:3888

      I used

      server.1=192.168.0.1:2888:3888

      and comment out the other options. Not sure if this is correct but managed to run the client interface ok. Planning to set up up solr next.

      Reply

Leave a Reply to Stuart

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>