CentOS7安裝Zookeeper-3.4.11

1.下載並上傳值CentOS中bash

在Windows中下載ZK安裝包:zookeeper-3.4.11.tar.gz服務器

2.配置ZKoop

首先解壓ZK安裝包,命令:測試

tar -zxvf zookeeper-3.4.11.tar.gzui

在zookeeper-3.4.11文件夾下,添加建立data和logs目錄:this

mkdir data spa

mkdir logsrest

將zookeeper-3.4.11/conf目錄下的zoo_sample.cfg文件拷貝一份,命名爲zoo.cfg:code

cp zoo_sample.cfg zoo.cfg  server

修改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=/home/hadoop/usoft/zookeeper-3.4.11/data  
dataLogDir=/home/hadoop/usoft/zookeeper-3.4.11/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  
server.1=192.168.84.130:2888:3888

zoo.cfg若提示只讀,則須要給讀寫權限。

在data下建立myid文件(編輯myid文件,並在對應的IP的機器上輸入對應的編號。如在zookeeper上,myid 文件內容就是1。若是隻在單點上進行安裝配置,那麼只有一個server.1)

編輯/etc/profile文件,vi /etc/profile

使配置文件生效,source /etc/profile

備註:默認防火牆已經關閉

3.啓動並測試ZK

備註使用普通用戶啓動,不要使用root用戶

#使用fendo用戶到/home/fendo/zookeeper-3.4.10/bin目錄中執行  
./zkServer.sh start  
  
#查看進程
jps

其中,QuorumPeerMain是zookeeper進程,啓動正常。
  
#查看狀態  
./zkServer.sh status  
  
#服務器輸出信息  
tail -500f zookeeper.out  
  
#中止zookeeper進程  
./zkServer.sh stop 

注意:使用普通用戶啓動時有時會出現一些問題:

沒有權限問題--須要給用戶賦給讀寫權限

4.設置ZK開機自啓

# 切換到/etc/rc.d/init.d/目錄下  
cd /etc/rc.d/init.d  
  
# 建立zookeeper文件  
touch zookeeper  
  
#更新權限  
chmod +x zookeeper  
  
#編輯文件,在zookeeper裏面輸入以下內容  
#!/bin/bash  
#chkconfig:2345 20 90  
#description:zookeeper  
#processname:zookeeper  
export JAVA_HOME=/usr/usoft/jdk1.8.0_151 
export PATH=$JAVA_HOME/bin:$PATH  
case $1 in  
          start)su root /home/hadoop/usoft/zookeeper-3.4.11/bin/zkServer.sh start;;  
          stop)su root /home/hadoop/usoft/zookeeper-3.4.11/bin/zkServer.sh stop;;  
          status)su root /home/hadoop/usoft/zookeeper-3.4.11/bin/zkServer.sh status;;  
          restart)su root /home/hadoop/usoft/zookeeper-3.4.11/bin/zkServer.sh restart;;  
          *)  echo "require start|stop|status|restart"  ;;  
esac  

使用命令把zookeeper添加到開機啓動裏面

以後就可使用service zookeeper start/stop來啓動中止zookeeper服務

相關文章
相關標籤/搜索