在Debian系統上安裝和配置Zookeeper的步驟如下:
zookeeper-3.4.14.tar.gz。tar -zxvf zookeeper-3.4.14.tar.gz -C /usr/local/soft/
/etc/profile文件,添加以下內容:export ZOOKEEPER_HOME=/usr/local/soft/zookeeper-3.4.14
export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
bin目錄,啟動Zookeeper服務:cd /usr/local/soft/zookeeper-3.4.14/bin/
./zkServer.sh start
# 創建服務文件
touch /etc/init.d/zookeeper
chmod +x /etc/init.d/zookeeper
# 編輯服務文件
vim /etc/init.d/zookeeper
#!/bin/bash
# chkconfig: 234 20 90
# description: Zookeeper
# processname: zookeeper
case "$1" in
start)
su - zookeeper -c '/usr/local/soft/zookeeper-3.4.14/bin/zkServer.sh start'
;;
stop)
su - zookeeper -c '/usr/local/soft/zookeeper-3.4.14/bin/zkServer.sh stop'
;;
status)
su - zookeeper -c '/usr/local/soft/zookeeper-3.4.14/bin/zkServer.sh status'
;;
restart)
su - zookeeper -c '/usr/local/soft/zookeeper-3.4.14/bin/zkServer.sh restart'
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0
chkconfig --add zookeeper
chkconfig --list | grep zookeeper
reboot
service zookeeper status
conf目錄,復制zoo_sample.cfg為zoo.cfg:cd /usr/local/soft/zookeeper-3.4.14/conf/
cp zoo_sample.cfg zoo.cfg
vim編輯zoo.cfg文件,添加或修改以下內容:# The port at which the clients will connect to the server
clientPort=2181
# The directory where the data is stored.
dataDir=/usr/local/soft/zookeeper-3.4.14/data
# The directory where the transaction log is stored.
dataLogDir=/usr/local/soft/zookeeper-3.4.14/logs
# The tick time in milliseconds
tickTime=2000
# The number of ticks that the initial synchronization phase can take
initLimit=5
# The maximum number of ticks that can pass between when a follower starts
# and when it is ready to serve requests
syncLimit=2
# The ID of this server
server.1:2888:3888
server.2:2888:3888
server.3:2888:3888
myid文件:dataDir目錄下創建myid文件,并寫入服務器ID:cd /usr/local/soft/zookeeper-3.4.14/data
echo "1" > myid
cd /usr/local/soft/zookeeper-3.4.14/bin/
./zkServer.sh start
./zkServer.sh status
以上步驟展示了如何在Debian系統上安裝和配置Zookeeper。請根據實際需求調整配置參數,并確保所有服務器的配置一致,以實現集群功能。