在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。请根据实际需求调整配置参数,并确保所有服务器的配置一致,以实现集群功能。