Zookeeper Installation
Next, create a non-administrative user named,zookeeper
to run Kafka. You can do this by executing the following from the command-line:
You should add this user to the DenyUsers section of your nodes /etc/ssh/sshd_config
file to prevent it from being able to ssh or sftp into the node. Remember to restart the sshd daemon after making the change. Once the system has finished updating and the user has been created, you can install ZooKeeper.
Installation
Navigate to opt directory and download a of ZooKeeper. The official release site is Apache Zookeeper Release
cd /opt
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
/opt/zookeeper
like so:
Navigate to zookeeper sub-directory and create a data directory for ZooKeeper:
Configuration
Using a text editor, create the ZooKeeper configuration file in the conf sub-directory. Name the file, zoo.cfg. For example, /opt/zookeeper/conf/zoo.cfg
. Copy the lines below into that file:
tickTime = 2000
dataDir = /var/zookeeper/data
clientPort = 2181
initLimit = 5
syncLimit = 2
maxClientCnxns=60
autopurge.purgeInterval=1
admin.enableServer=false
4lw.commands.whitelist=*
server.1=127.0.0.1:2888:3888
admin.enableServer=false
bash -c 'echo 1 > /var/zookeeper/data/myid'
./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-x.x.x/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
./bin/zkServer.sh stop
chown -R zookeeper:zookeeper /opt/apache-zookeeper-x.x.x
chown -R zookeeper:zookeeper /var/zookeeper/data
So that ZooKeeper will start when the server is rebooted, you'll need to create a ZooKeeper service file named zookeeper.service in the /etc/systemd/system/
sub-directory. Use a text editor to create the file and copy the following lines into it.
[Unit]
Description=ZooKeeper Daemon
Documentation=http://zookeeper.apache.org
Requires=network.target
After=network.target
[Service]
Type=forking
WorkingDirectory=/opt/zookeeper
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop /opt/zookeeper/conf/zoo.cfg
ExecReload=/opt/zookeeper/bin/zkServer.sh restart /opt/zookeeper/conf/zoo.cfg
TimeoutSec=30
Restart=on-failure
[Install]
WantedBy=default.target