注意:如果zk已经启动了,要先停掉,再执行下面的命令。
1.新增zk.service文件
sudo vi /etc/systemd/system/zk.service
#zk.service的内容,注意修改成自己的JAVA_HOME和zk安装目录
[Unit]
Description=Apache ZooKeeper Service
After=network.target
[Service]
Type=forking
ExecStart=/opt/app/middles/apache-zookeeper-3.5.7-bin/bin/zkServer.sh start
ExecStop=/opt/app/middles/apache-zookeeper-3.5.7-bin/bin/zkServer.sh stop
ExecReload=/opt/app/middles/apache-zookeeper-3.5.7-bin/bin/zkServer.sh restart
User=root
Group=root
RestartSec=5
Environment="JAVA_HOME=/opt/app/middles/jdk8"
[Install]
WantedBy=multi-user.target
2.加载并设置开机自动启动
sudo systemctl daemon-reload
sudo systemctl enable zk.service
sudo systemctl start zk.service
sudo systemctl status zk.service
sudo systemctl stop zk.service
sudo systemctl restart zk.service
标签:bin,sudo,service,zk,app,Zookeeper,systemctl,自启动
From: https://www.cnblogs.com/hujunwei/p/18453242