systemd有系统和用户区分;系统(/user/lib/systemd/system/)、用户(/etc/lib/systemd/system/).
一般系统管理员手工创建的单元文件建议存放在/etc/systemd/system/目录下面。
进入/etc/systemd/system目录
创建zookeeper.service文件
[Unit] Description=Zookeeper Requires=network.target After=network.target [Service] Type=forking Environment=JAVA_HOME=/opt/soft/jdk1.8 WorkingDirectory=/opt/soft/zookeeper-3.4.6 ExecStart=/opt/soft/zookeeper-3.4.6/bin/zkServer.sh start /opt/soft/zookeeper-3.4.6/conf/zoo.cfg ExecStop=/opt/soft/zookeeper-3.4.6/bin/zkServer.sh stop /opt/soft/zookeeper-3.4.6/conf/zoo.cfg ExecReload=/opt/soft/zookeeper-3.4.6/bin/zkServer.sh restart /opt/soft/zookeeper-3.4.6/conf/zoo.cfg Restart=always RestartSec=10 TimeoutSec=360 [Install] WantedBy=multi-user.target
启动 zookeeper
systemctl daemon-reload
systemctl start zookeeper
查看日志:journalctl -f -u zookeeper.service
加入开机启动
systemctl enable zookeeper
检查是否已经开机启动
systemctl is-enabled zookeeper
机器重启验证自启动
reboot
后期如果想关闭服务,或者移除开机启动:
关闭服务:
systemctl stop zookeeper.service
移除开机启动:
systemctl disable zookeeper
参考文档:https://blog.csdn.net/qq562029186/article/details/67639676/