1.准备zookeeper用户
groupadd zookeeperuseradd -M -s /bin/false -g zookeeper zookeeper
2.准备工作目录
mkdir -p /zookeeper/{data,conf,logs,src}wget -P /zookeeper/src https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gztar zxf /zookeeper/src/zookeeper-3.4.13.tar.gzchown zookeeper.zookeeper -R /zookeeperchmod 750 -R /zookeeperln -s /zookeeper/src/zookeeper-3.4.13 /opt/zookeeper
3.创建zookeeper配置文件:/zookeeper/conf/zoo.cfg
- Standalone模式:
tickTime=2000initLimit=10syncLimit=5clientPort=2181dataDir=/zookeeper/datadataLogDir=/zookeeper/data/logs
- Clustered模式:
tickTime=2000initLimit=10syncLimit=5clientPort=2181dataDir=/zookeeper/datadataLogDir=/zookeeper/data/logsserver.1=zk1:2888:3888server.2=zk2:2888:3888server.3=zk3:2888:3888
Clustered模式下需要创建myid文件,节点对应id:echo "1" > /zookeeper/data/myid
4.编写systemd.service
服务脚本:/etc/systemd/system/zookeeper.service
[Unit]Description=ZooKeeper ServiceAfter=network.targetAfter=syslog.target[Service]Environment=ZOO_LOG_DIR=/zookeeper/logsSyslogIdentifier=zookeeperType=forkingUser=zookeeperGroup=zookeeperExecStart=/opt/zookeeper/bin/zkServer.sh start /zookeeper/conf/zoo.cfgExecStop=/opt/zookeeper/bin/zkServer.sh stop /zookeeper/conf/zoo.cfgExecReload=/opt/zookeeper/bin/zkServer.sh restart /zookeeper/conf/zoo.cfg[Install]WantedBy=default.target
重新加载配置信息:systemctl daemon-reload
systemctl start zookeeper.service
关掉zookeeper:systemctl stop zookeeper.service
查看进程状态及日志:systemctl status zookeeper.service
开机自启动:systemctl enable zookeeper.service
关闭自启动:systemctl disable zookeeper.service