溫馨提示×

Debian Zookeeper如何安裝配置

小樊
83
2025-02-20 12:04:20
欄目: 智能運維

在Debian系統上安裝和配置Zookeeper的步驟如下:

安裝Zookeeper

  1. 下載Zookeeper
  • 訪問Apache Zookeeper官網下載最新版本的Zookeeper。
  • 例如,下載zookeeper-3.4.14.tar.gz。
  1. 解壓文件
tar -zxvf zookeeper-3.4.14.tar.gz -C /usr/local/soft/
  1. 配置環境變量(可選):
  • 編輯/etc/profile文件,添加以下內容:
export ZOOKEEPER_HOME=/usr/local/soft/zookeeper-3.4.14
export PATH=$PATH:$ZOOKEEPER_HOME/bin
  • 刷新配置:
source /etc/profile
  1. 啟動Zookeeper
  • 進入bin目錄,啟動Zookeeper服務:
cd /usr/local/soft/zookeeper-3.4.14/bin/
./zkServer.sh start
  1. 設置開機啟動(可選):
  • 將Zookeeper添加到開機啟動服務:
# 創建服務文件
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
  • 將Zookeeper服務添加到開機啟動項:
chkconfig --add zookeeper
  • 查看開機自啟項:
chkconfig --list | grep zookeeper
  • 重啟系統測試服務:
reboot
  • 測試服務狀態:
service zookeeper status

配置Zookeeper

  1. 配置文件
  • 進入conf目錄,復制zoo_sample.cfgzoo.cfg
cd /usr/local/soft/zookeeper-3.4.14/conf/
cp zoo_sample.cfg zoo.cfg
  1. 修改配置文件
  • 使用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
  1. 創建并配置myid文件
  • dataDir目錄下創建myid文件,并寫入服務器ID:
cd /usr/local/soft/zookeeper-3.4.14/data
echo "1" > myid
  1. 啟動Zookeeper集群
  • 分別在每臺服務器上執行以下命令啟動Zookeeper:
cd /usr/local/soft/zookeeper-3.4.14/bin/
./zkServer.sh start
  • 檢查Zookeeper狀態:
./zkServer.sh status

以上步驟展示了如何在Debian系統上安裝和配置Zookeeper。請根據實際需求調整配置參數,并確保所有服務器的配置一致,以實現集群功能。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女