Zookeeper-3.4.10 叢集的安裝配置

appleyk發表於2018-07-13



一、Hadoop叢集配置如下




主機名IPJDK版本描述
m1     192.168.142.1441.8.0_161  Hadoop叢集2.7  NameNode
s1      192.168.142.145 1.8.0_161  Hadoop叢集2.7  DataNode1
s2     192.168.142.1461.8.0_161  Hadoop叢集2.7  DataNode2



別忘了在/etc/目錄下,修改host檔案,新增主機名與IP地址之間的對映








二、ZooKeeper - 3.4.10 下載地址



百度網盤下載地址:zookeeper-3.4.10.tar.gz


官網下載地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/





三、ZooKeeper 安裝



下載後的tar.gz上傳至m1機器上的/usr/local目錄下,並解壓


tar -zxvf  zookeeper-3.4.10.tar.gz


解壓後,進入zookeeper目錄如下








四、ZooKeeper 配置




(1)配置環境變數


vim /etc/profile    (新增如下內容)






export JAVA_HOME=/usr/local/jdk1.8.0_161
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HBASE_HOME=/usr/local/hbase-1.3.1
export HADOOP_HOME=/usr/local/hadoop-2.7.6
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.10
export PATH=$PATH:$HADOOP_HOME/bin:$HBASE_HOME/bin:$ZOOKEEPER_HOME/bin:$HADOOP_HOME/sbin:$JAVA_HOME/bin



新增後,使用source命令,使剛才修改的配置立即生效


source /etc/profile




(2)配置conf



cp zoo_sample.cfg zoo.cfg







開啟zoo.cfg,需要配置的內容如下:



vim zoo.cfg







dataDir=/usr/local/zookeeper-3.4.10/data
dataLogDir=/usr/local/zookeeper-3.4.10/data/logs
server.1=m1:2888:3888
server.2=s1:2888:3888
server.3=s2:2888:3888




1、指定Zookeeper的資料存放路徑(/usr/local/zookeeper-3.4.10/data)

2、指定Zookeeper的資料日誌存放路徑(/usr/local/zookeeper-3.4.10/data/logs)

3、客戶端連線zookeeper服務端的預設埠為2181

4、Zookeeper叢集最好是奇數個節點,根據選舉機制,半數以上的票數才能當選為leader(假如有兩個節點,你選我,我選你,根據半數以上票數規則,是無法確定叢集中到底是你來當leader還是我來當),因此,我們基於Hadoop的叢集,分別以NaneNode和兩個DataNode作為Zookeeper叢集的三個節點

5、server.1 、server.2、server.3表示Zookeeper叢集中各個節點所在的主機及服務埠號

6、埠2888:Zookeeper服務之間的通訊埠,比如leader和follower之間的通訊

7、埠3888:Zookeeper選舉leader用的埠




(3)建立data和日誌目錄


切換到zookeeper目錄下,建立data目錄和日誌目錄(-p 遞迴建立目錄,檢查目錄是否存在,不存在則建立)


mkdir -p data

mkdir -p data/logs



(4)建立myid檔案


      由於Zookeeper叢集中的每一個Zk服務都會有一個唯一標識自己的ID(zk程式ID),這個ID應用在myid和zoo.cfg兩個檔案中,其中myid檔案中存放的是當前Zk服務的標識ID,而zoo.cfg中以server.ID來指定當前的Zk服務程式對應的是哪一臺主機,當Zk服務啟動的時候,會首先讀取myid中的id標識,拿著這個id再去zoo.cfg檔案中進行匹配查詢,查詢的目的是為了弄清楚當前Zk服務在整個ZooKeeper叢集中的位置

      因此,如果沒有指定Zk服務的myid,Zk是啟動不了的


     


分別在m1、s1、s2三臺主機上的ZK安裝目錄下的data目錄下建立myid檔案,並依次寫入值:1,2,3如下:















(5)分別在三臺機器上啟動zk服務



zkServer.sh start







啟動叢集后,zkServer之間會互相進行投票選舉,選出來一個leader,檢視zkServer狀態如下:




zkServer.sh status









(6)客戶端連線Zk叢集



 zkCli.sh -server m1:2181,s1:2181,s2:2181



Connecting to m1:2181,s1:2181,s2:2181
2018-07-12 21:04:11,689 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2018-07-12 21:04:11,693 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=m1
2018-07-12 21:04:11,693 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_161
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/local/jdk1.8.0_161/jre
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper-3.4.10/bin/../build/classes:/usr/local/zookeeper-3.4.10/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/usr/local/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.10/bin/../conf:.:/usr/local/jdk1.8.0_161/lib/dt.jar:/usr/local/jdk1.8.0_161/lib/tools.jar
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2018-07-12 21:04:11,696 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2018-07-12 21:04:11,697 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-431.el6.x86_64
2018-07-12 21:04:11,697 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2018-07-12 21:04:11,697 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2018-07-12 21:04:11,697 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/root
2018-07-12 21:04:11,698 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=m1:2181,s1:2181,s2:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@446cdf90
Welcome to ZooKeeper!
2018-07-12 21:04:11,724 [myid:] - INFO  [main-SendThread(s2:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server s2/192.168.142.146:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2018-07-12 21:04:11,839 [myid:] - INFO  [main-SendThread(s2:2181):ClientCnxn$SendThread@876] - Socket connection established to s2/192.168.142.146:2181, initiating session
[zk: m1:2181,s1:2181,s2:2181(CONNECTING) 0] 2018-07-12 21:04:11,907 [myid:] - INFO  [main-SendThread(s2:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server s2/192.168.142.146:2181, sessionid = 0x36491c9d1e60000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null



相關文章