1. 在 /etc/systemd/system/ 文件夹下创建一个启动脚本 zookeeper.service
注意:
(1) Type=forking
(2) 设置环境变量
Environment=ZOO_LOG_DIR=/opt/app/zookeeper/bin
Environment=JAVA_HOME=/usr/java/jdk1.8
[Unit] Description=Zookeeper After=network.target [Service] Type=forking User=deploy Group=deploy Environment=ZOO_LOG_DIR=/opt/app/zookeeper/bin Environment=JAVA_HOME=/usr/java/jdk1.8 WorkingDirectory=/opt/app/zookeeper/bin ExecStart=/opt/app/zookeeper/bin/zkServer.sh start ExecStop=/opt/app/zookeeper/bin/zkServer.sh stop Restart=always RestartSec=10 TimeoutSec=360 [Install] WantedBy=multi-user.target
2. 将zookeeper的目录赋权给普通用户 deploy
chown -R deploy.deploy /opt/app/zookeeper
3. 启动 zookeeper
systemctl daemon-reload systemctl start zookeeper
4. 加入开机启动
systemctl enable zookeeper
5. 检查是否已经开机启动
systemctl is-enabled zookeeper
6. 机器重启验证自启动
reboot
转自:
https://blog.51cto.com/kusorz/1920778
https://developer.aliyun.com/article/517723