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