zookeeper叢集部署

語言: CN / TW / HK

參考了一些文章,並且自己在測試環境手動搭建

有三臺CentOS7的機器已經配置好host,分別為cdh50-121,cdh50-122,cdh50-127,使用者名稱都是hdfs,並且設定免密互信(免密互信安裝Hadoop時用,安裝zookeeper時不需要)

一、下載解壓Zookeeper

  1. 下載地址 https://www.jianshu.com/p/eca909471eb3,下載tar.gz壓縮包,我選擇版本是3.4.14
  2. 為方便操作,zookeeper安裝在使用者目錄下(/home/hdfs)後續操作都以hdfs使用者操作
  3. 壓縮包放置到使用者目錄,並且解壓壓縮包,解壓後文件夾名修改為zookeepe
    	cd ~
    	tar zxf zookeeper-3.4.14.tar.gz
    	mv zookeeper-3.4.14 zookeeper
    

二、環境配置

  1. zookeeper 配置,進入配置目錄 /home/hdfs/zookeeper/conf
  2. 重新命名配置檔案zoo_sample.cfg為zoo.cfg,並修改
    	## 配置臨時目錄
    	dataDir=/home/hdfs/tmp/zookeeper
    	## 配置埠
    	clientPort=2181
    	## 配置叢集內所有伺服器的ip地址和埠(具體什麼意義見後面解釋)
    	server.1=cdh50-121:2888:3888
    	server.2=cdh50-122:2888:3888
    	server.3=cdh50-127:2888:3888
    	## 其他配置暫時使用預設配置
    

解釋:

  • 用奇數臺伺服器做叢集:zookeeper預設半數以上伺服器節點正常,才可以正常執行,即2x臺和2x-1臺效果是一樣的,而後者相當於節約一臺機器
  • server.X=A:B:C代表什麼意思?(如server.1=cdh50-121:2888:3888)
    	官方解釋:
    	    The entries of the form server.X list the servers that make up the ZooKeeper service.
    	When the server starts up, it knows which server it is by looking for the file myid in
    	the data directory. That file has the contains the server number, in ASCII.
    	    Finally, note the two port numbers after each server name: " 2888" and "3888". Peers 
    	use the former port to connect to other peers. Such a connection is necessary so that 
    	peers can communicate, for example, to agree upon the order of updates. More specifically,
    	a ZooKeeper server uses this port to connect followers to the leader. 
    	    When a new leader arises, a follower opens a TCP connection to the leader using this 
    	port. Because the default leader election also uses TCP, we currently require another 
    	port for leader election. This is the second port in the server entry.
    
    	通俗概括:
    	    X代表每個伺服器節點的命名(以用來節點之間進行標識區分)
    	    A代表節點的IP地址
    	    B、C代表埠號,用於節點之間的相互連線通訊(注意避免機器上已被佔用的埠)
    

三、建立標識檔案

在臨時目錄(/home/hdfs/tmp/zookeeper)中新建檔案'myid'並寫入標識,即server.X中的X,注意每臺機器寫對應的標識

四、三臺機器上進行相同操作,並在部分地方改成對應機器的內容即可(ip、埠、標識等注意一下)

五、啟動zookeeper並檢查

## 三臺機器同時執行,以下操作統一在使用者根目錄操作
cd ~
./zookeeper/bin/zkServer.sh start

## 如需要停止叢集
./zookeeper/bin/zkServer.sh stop

## 檢查客戶端情況
./zookeeper/bin/zkServer.sh status

## 顯示using config:................和mode:follower/leader則表示該節點啟動成功
## Mode: follower(從節點)
## Mode: leader  (主節點)
「其他文章」