Zookeeper的下載安裝


 

很多服務器都不建議安裝在windows上,安裝在windows上容易報亂七八糟的錯。

 

1、下載ZK,上傳到Linux,移到/usr/local下,解壓

mv apache-zookeeper-3.6.0-bin.tar.gz /usr/local/

cd /usr/local/

tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz

rm apache-zookeeper-3.6.0-bin.tar.gz

我們看到解壓目錄的lib下有很多jar包,zk依賴jdk,沒有安裝、配置jdk的需要先安裝jdk,並配置jdk的環境變量。

 

 

 

 2、將conf/zoo_sample.cfg復制為zoo.cfg,並修改zk的數據存儲位置

啟動zk時會默認加載conf/zoo.cfg,zoo_sample.cfg是官方提供的配置模板。

#將zoo_sample.cfg復制一份,重命名為zoo.cfg
cp conf/zoo_sample.cfg conf/zoo.cfg


#在解壓目錄下新建目錄data
mkdir data


#data下新建文件myid
touch data/myid
#編輯myid,寫一個1。myid在zkServer集群中才有用,單機版zkServer可以不配置
vim data/myid


vim conf/zoo.cfg

 

 

 

 

其它使用默認配置即可。介紹一下配置項

# The number of milliseconds of each tick
tickTime=2000  #心跳間隔,每隔2000ms即2s發送一次心跳
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10  #10*2s=20s,如果連續10次即20s內沒有收到某個服務節點的心跳,就認為該節點掛掉了
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5  #follower從leader同步數據時,發送同步請求后,如果5個心跳時間即10s內沒有收到leader的確認應答,就認為本次同步請求失敗
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
#dataDir=/tmp/zookeeper
dataDir=/usr/local/apache-zookeeper-3.6.0-bin/data  #數據存儲位置
# the port at which the clients will connect
clientPort=2181  #zk client與zk server通信使用的端口號
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60  #zk client的最大數量

 

 

 

3、防火牆開放指定端口給zk client連接

firewall-cmd --add-port=2181/tcp --zone=public --permanent 

firewall
-cmd --reload

 

 

 

4、啟動zk server

windows、linux的zk安裝包都是同一個,bin下面的.cmd文件是windows上用的,.sh文件是linux用的。

.cmd不需要,可以刪掉。執行bin/zkServer.sh啟動ZK。

cd bin

rm *.cmd

./zkServer.sh start

注意zkServer的S是大寫,要帶上后綴.sh

 

看到started的說明zk server已經啟動了

 

 

zk server常用的參數

start  #啟動

stop  #停止

restart  #重啟

status  #查看狀態

version  #查看zk server的版本

注意:這些參數前面不帶短橫。

查看參數可以用文本編輯器打開腳本,查看源代碼;也可以./zkServer.sh  --help,help可以帶2根短橫、1根短橫。

 

 

 

5、連接zk server

此時啟動bin/zkCli.sh可連接到zk server,zkCli.sh是zk自帶的客戶端

./zkCli -server 192.168.1.9:2181

因為zk server就在本地,ip寫127.0.0.1也行

 看到打印的信息中有   就說明連接上了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM