【Linux Centos7】ZooKeeper單機版安裝與部署

Zookeeper單機版安裝

關於我:http://huangth.com

GitHub地址:https://github.com/RobertoHuang

  • 下載Zookeeper

  • 解壓Zookeeper安裝包

    # tar -zxvf zookeeper-3.4.8.tar.gz
    
  • 配置Zookeeper文件及日誌目錄

    • 創建保存文件及日誌的目錄

      # mkdir data
      # mkdir logs
      
    • 修改Zookeeper的配置文件

      • zookeeper-3.4.8/conf目錄下的zoo_sample.cfg文件拷貝一份命名爲爲zoo.cfg

        # cp zoo_sample.cfg zoo.cfg
        
      • 編輯zoo.cfgzookeeperdataDirdataLogDir指向之前創建好的文件及日誌目錄

        # 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=/opt/zookeeper/data
        dataLogDir=/opt/zookeeper/logs
        
        # the port at which the clients will connect
        clientPort=2181
        
        server.1=localhost:2888:3888
        
      • dataDir下創建myid文件(編輯myid文件並在對應的IP的機器上輸入對應的編號)

        # echo 1 > myid
        
  • 添加Zookeeper環境變量配置(修改/etc/profile添加如下配置),並使環境變量配置生效

    ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.8
    export PATH=$ZOOKEEPER_HOME/bin:$PATH
    
    # source /etc/profile
    
  • 啓動並測試Zookeeper

    # 啓動Zookeeper
    zkServer.sh start
     
    # 查看Zookeeper狀態
    zkServer.sh status
     
    # 服務器輸出信息
    tail -500f zookeeper.out
     
    # 停止zookeeper
    zkServer.sh stop
    
  • 設置Zookeeper服務開機啓動

    • /etc/rc.d/init.d添加可執行文件zookeeper

      # 切換到/etc/rc.d/init.d/目錄下
      # cd /etc/rc.d/init.d
      
      # 創建zookeeper文件
      # touch zookeeper
      
      # 將zookeeper修改爲可執行文件
      # chmod +x zookeeper
      
      # 編輯文件,在zookeeper裏面輸入如下內容
      #!/bin/bash
      #chkconfig:2345 20 90
      #description:zookeeper
      #processname:zookeeper
      export JAVA_HOME=/opt/java/jdk1.8.0_91
      export PATH=$JAVA_HOME/bin:$PATH
      case $1 in
           start) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh start;;
           stop) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh stop;;
           status) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh status;;
           restart) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh restart;;
           *) echo "require start|stop|status|restart";;
      esac
      
    • 這個時候我們就可以用service zookeeper start/stop來啓動停止Zookeeper服務了

    • 使用命令把zookeeper添加到開機啓動任務中

      # chkconfig zookeeper on
      # chkconfig --add zookeeper
      
    • 添加完成之後接這個使用chkconfig --list來看看我們添加的zookeeper是否在裏面

    • 如果上面的操作都正常的話,你就可以重啓你的Linux服務器了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章