debian

Debian Zookeeper如何安装配置

小樊
46
2025-02-20 12:04:20
栏目: 智能运维

在Debian系统上安装和配置Zookeeper的步骤如下:

安装Zookeeper

  1. 下载Zookeeper
  1. 解压文件
tar -zxvf zookeeper-3.4.14.tar.gz -C /usr/local/soft/
  1. 配置环境变量(可选):
export ZOOKEEPER_HOME=/usr/local/soft/zookeeper-3.4.14
export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
  1. 启动Zookeeper
cd /usr/local/soft/zookeeper-3.4.14/bin/
./zkServer.sh start
  1. 设置开机启动(可选):
# 创建服务文件
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

配置Zookeeper

  1. 配置文件
cd /usr/local/soft/zookeeper-3.4.14/conf/
cp zoo_sample.cfg zoo.cfg
  1. 修改配置文件
# 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
  1. 创建并配置myid文件
cd /usr/local/soft/zookeeper-3.4.14/data
echo "1" > myid
  1. 启动Zookeeper集群
cd /usr/local/soft/zookeeper-3.4.14/bin/
./zkServer.sh start
./zkServer.sh status

以上步骤展示了如何在Debian系统上安装和配置Zookeeper。请根据实际需求调整配置参数,并确保所有服务器的配置一致,以实现集群功能。

0
看了该问题的人还看了