1.安裝jdk,zookeeper就不說啦,自己搜索下。
2.開機自啟動和注冊為服務。
(1)開機自啟動:編輯/etc/rc.d/rc.local文件,添加zkServer.sh路徑。
vi /etc/rc.d/rc.local
#!/bin/sh
# This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local export JAVA_HOME=/usr/java/jdk1.8.0_221 --jdk的路徑,自己安裝的目錄 /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start --zookeeper的zkServer.sh的路徑
(2)注冊為服務:到/etc/rc.d/init.d目錄下添加,zookeeper腳本
cd /etc/rc.d/init.d
touch zookeeper
ls -al --查看到沒有執行權限,修改權限
chmod +x zookeeper
vi zookeeper -- 打開zookeeper編輯腳本,下面為要 編輯的內容
#! /bin/bash
#chkconfig: 2345 20 90 -- 系統啟動級別為2 3 4 5 啟動優先級20 關閉優先權90。必須,否則執行chkconfig命令是會報錯
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=/usr/java/jdk1.8.0_221
case $1 in
start) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start;;
stop) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh stop;;
status) su root /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh status;;
restart) su /home/zookeeper/zookeeper-3.4.14/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart" ;;
esac
添加好后保存。測試:
service zookeeper start
啟動成功后則添加服務成功了。
(3)將服務添加為開機啟動。
chkconfig --add zookeeper --zookeeper為剛才注冊的服務
chkconfig --list --查看剛才添加的zookeeper是否成功。有顯示為成功。