1. 程式人生 > >centos7安裝zookeeper-單例項

centos7安裝zookeeper-單例項

  1. 下載zookeeper,http://mirrors.hust.edu.cn/apache/zookeeper/ ,我這裡下載的是3.4.6
  2. 建立zookeeper資料夾,並將下載好的檔案上傳,然後解壓,同時刪除壓縮檔案
    cd /usr/local
    mkdir zookeeper
    cd zookeeper
    tar -zxvf zookeeper-3.4.6.tar.gz
    rm -f zookeeper-3.4.6.tar.gz

    進入解壓後的檔案,將conf資料夾下的zoo_sample.cfg複製出一份並命名為zoo.cfg檔案並開啟

    cd zookeeper-3.4.6/conf
    cp zoo_sample.cfg zoo.cfg
    vi zoo.cfg
    # 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=/usr/local/zookeeper/zookeeper-3.4.6/data
    dataLogDir=/usr/local/zookeeper/zookeeper-3.4.6/logs
    # the port at which the clients will connect
    clientPort=2181
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60
    #
    # Be sure to read the maintenance section of the
    # administrator guide before turning on autopurge.
    #
    # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    #
    # The number of snapshots to retain in dataDir
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
    

    修改後儲存退出,可以看到,我們指定了兩個資料夾一個是data,另一個是logs,我們需要分別建立

    cd ..
    mkdir data
    mkdir logs

     

  3. 配置環境變數

    vi /etc/profile
    
    

    在檔案末尾插入並儲存退出

    export ZOOKEEPER_HOME=/usr/local/zookeeper/zookeeper-3.4.6/
    export PATH=$ZOOKEEPER_HOME/bin:$PATH
    export PATH

    使之生效

    source /etc/profile

     

  4. 啟動zk

    cd /usr/local/zookeeper/zookeeper-3.4.6/bin
    ./zkServer.sh start

    如正常輸出

    JMX enabled by default
    Using config: /usr/local/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    

    則啟動正常

  5. 關閉zk

    ./zkServer.sh stop