zookeeper集羣搭建與監控工具ZK UI安裝

zookeeper相關安裝

記錄下安裝zookeeper集羣的過程

zookeeper集羣搭建

本次安裝集羣需要3個節點,下面是我的節點信息:

  1. node1 192.168.75.200
  2. node2 192.168.75.201
  3. node3 193.168.75.202

安裝包下載

鏈接:https://pan.baidu.com/s/1pmDKErhMLfx0pcMMoZHPaQ
提取碼:wghz

信息配置

  1. 下載安裝後,解壓到某個目錄下面,複製一個zoo_sample.cfg文件並改名爲zoo.cfg
  2. 下面是我的配置信息
    配置dataDir,dataLogDir的屬性值;clientPort端口號;相關集羣節點信息
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/root/packages/zookeeper3.5.6/data
dataLogDir=/root/packages/zookeeper3.5.6/log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
autopurge.purgeInterval=1
#此處是重點關注的地方,其中0,1,2是myid裏面的編號
server.0=192.168.75.200:2888:3888
server.1=192.168.75.201:2888:3888
server.2=192.168.75.202:2888:3888
  1. 在dataDir配置的目錄下創建myid文件,寫入節點對應的編號
  2. 開放2181,2888,3888端口(重點)

監控工具ZK UI安裝

zkui參考這條教程

Shell一鍵啓動腳本編寫

這個啓動腳本僅供參考:
start-zookeeper.sh

#!/bin/bash
echo "啓動zookeeper中........"
#節點列表
nodes=("node1" "node2" "node3")
for node in ${nodes[@]}
do
    echo "$node:啓動開始"
    ssh root@$node  "zkServer.sh start"
    echo "$node:啓動成功"
done
echo "啓動zookeeper成功"
echo "開啓zookeeper客戶端監控....."
cd /root/packages/zookeeper3.5.6/zkui/target
nohup java -jar zkui-2.0-SNAPSHOT-jar-with-dependencies.jar &
echo $! > tpid
exit0

stop-zookeeper.sh

#!/bin/bash
echo "關閉zookeeper中........"
nodes=("node1" "node2" "node3")
for node in ${nodes[@]}
do
    echo "$node:關閉開始"
    ssh root@$node  "zkServer.sh stop"
    echo "$node:關閉成功"
done
echo "關閉zookeeper成功"
echo "關閉zookeeper監控平臺....."
cd /root/packages/zookeeper3.5.6/zkui/target
PID=$(cat tpid)
kill -9 $PID  && echo "監控服務停止成功...."
name=$(lsof -i:9090|tail -1|awk '"$1"!=""{print $2}')
if [ -z $name ]
then
        echo "No process can be used to killed!"
else
        id=$(lsof -i:9090|tail -1|awk '"$1"!=""{print $2}')
        kill -9 $id
        echo "Process name=$name($id) kill!"
fi
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章