# 注意替换一下新的链接
curl -sSLO https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt/
cd /opt
ln -s zookeeper-3.4.10 ./zookeeper
cd zookeeper
mkdir data
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
/opt/zookeeper/bin/zkServer.sh start
Ctrl-c out of that and lets create a systemd unit file for the service.
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
[Install]
WantedBy=multi-user.target
Systemd 的 unit 的配置文件位置 (redhat系): /usr/lib/systemd/system/
Systemd服务主要内容为:控制单元[unit]的定义、服务[service]的定义、安装[install]部分
fork() 函数,把必要的通信频道都设置好之后父进程退出,留下守护精灵的子进程; 隔开WantedBy=multi-user.target 多用户环境下启用Restart
Restart=always: 只要不是通过systemctl stop来停止服务,任何情况下都必须要重启服务,默认值为no
RestartSec=5: 重启间隔,比如某次异常后,等待5(s)再进行启动,默认值0.1(s)
StartLimitInterval: 无限次重启,默认是10秒内如果重启超过5次则不再重启,设置为0表示不限次数重启
Next
systemctl daemon-reload # 重新加载服务配置文件
systemctl enable zookeeper.service
systemctl start zookeeper.service
SystemCtl
systemctl --help # 查看帮助
# enable 是在 /etc/systemd/system/multi-user.target.wants/ 这个目录下 做 unit 配置文件的软链
systemctl enable | disable | is-enabled | status | is-active unit
systemctl get-default | set-default graphical.target | multi-user.target # islate 在线切换模式
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
https://zookeeper.apache.org/releases.html
https://blog.redbranch.net/2018/04/19/zookeeper-install-on-centos-7/