1. 程式人生 > >Linux下叢集部署zookeeper

Linux下叢集部署zookeeper

  1. 環境準備 1. 準備三臺虛擬機器 2. 每臺機器上都安裝好jdk環境 3. 全網統一hosts對映配置 4. 關閉防火牆

  2. 上傳zookeeper安裝包

  3. 解壓

    [root@hadoop05 local]# tar -zxvf zookeeper-3.4.6.tar.gz 
    [root@hadoop05 local]# ln -s zookeeper-3.4.6 zookeeper  (建立軟連線)
    [root@hadoop05 local]#
    
  4. 刪除多餘的檔案(可忽略)

    [root@hadoop05 zookeeper]# rm -rf *.txt *.xml docs/ src/ dist-
    maven/ [root@hadoop05 zookeeper]# ll total 1344 drwxr-xr-x 2 1000 1000 4096 Feb 20 2014 bin drwxr-xr-x 2 1000 1000 4096 Feb 20 2014 conf drwxr-xr-x 10 1000 1000 4096 Feb 20 2014 contrib drwxr-xr-x 4 1000 1000 4096 Feb 20 2014 lib drwxr-xr-x 5 1000 1000 4096 Feb 20 2014 recipes -rw-rw-r-- 1 1000 1000 1340305 Feb 20 2014 zookeeper-3.4
    .6.jar -rw-rw-r-- 1 1000 1000 836 Feb 20 2014 zookeeper-3.4.6.jar.asc -rw-rw-r-- 1 1000 1000 33 Feb 20 2014 zookeeper-3.4.6.jar.md5 -rw-rw-r-- 1 1000 1000 41 Feb 20 2014 zookeeper-3.4.6.jar.sha1
  5. 設定環境變數 注意:每臺zookeeper都需要修改

    1. 開啟環境變數配置檔案
      [root@hadoop05 zookeeper]# vim /etc/profile
      [root@hadoop01 local]# 
      
    2. 修改環境變數,在profile檔案中加入下面內容
      #set zookeeper enviroment
      export ZOOKEEPER_HOME=/usr/local/zookeeper     
      export PATH=$PATH:${ZOOKEEPER_HOME}/bin
      
    3. 載入配置檔案,使之生效 source /etc/profile
  6. 修改Zookeeper配置檔案

    [[email protected] conf]# cp zoo_sample.cfg  zoo.cfg 
    [[email protected] conf]# vim zoo.cfg 
    
    dataDir=/usr/local/zookeeper/zkdata
    server.1=mini1:2888:3888     ## (心跳埠、選舉埠)
    server.2=mini2:2888:3888
    server.3=mini3:2888:3888
    
  7. 建立資料夾,並在該檔案下建立myid檔案

    [[email protected] zookeeper]# mkdir zkdata
    [[email protected] zookeeper]# cd zkdata/
    [[email protected] zkdata]# echo 1 > myid
    [[email protected] zkdata]# cat myid 
    1
    [[email protected] zkdata]# 
    
  8. 分發安裝包到其他機器

    [[email protected] local]# scp -r /usr/local/zookeeper [email protected]:/usr/local/
    [[email protected] local]# scp -r /usr/local/zookeeper [email protected]:/usr/local/
    ...
    
  9. 修改其他機器的配置檔案 hadoop06上修改myid為:2 hadoop07上修改myid為:3

  10. 啟動(每臺機器)

    [[email protected] local]# zookeeper/bin/zkServer.sh start
    JMX enabled by default
    Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    [[email protected] local]# 
    
    
  11. zookeeper叢集啟動指令碼

    #!/bin/bash
    
    for host in hadoop05 hadoop06 hadoop07
    do
    echo "$host zookeeper is starting..."
    ssh $host "/usr/local/zookeeper/bin/zkServer.sh  start"
    done