zookeeper3.4.9集羣模式安裝部署

環境要求

software version download
centos 7.2 省略
jdk 1.8 http://www.oracle.com/technet...
zookeeper 3.4.9 https://mirrors.tuna.tsinghua...

下載解壓

按照上述提供的地址下載zookeeper後,使用命令tar -zxvf zookeeper-3.4.9.tar.gz進行解壓後,可獲得下圖的文件目錄結構html

clipboard.png

  • bin目錄

zk的可執行腳本目錄,包括zk服務進程,zk客戶端,等腳本。其中,.sh是Linux環境下的腳本,.cmd是Windows環境下的腳本。java

  • conf目錄

配置文件目錄。zoo_sample.cfg爲樣例配置文件,須要修改成本身的名稱,通常爲zoo.cfg。log4j.properties爲日誌配置文件。apache

  • contrib目錄

一些用於操做zk的工具包。vim

  • recipes目錄

zk某些用法的代碼示例centos

配置說明

複製 zoo_sample.cfg 文件的並命名爲爲 zoo.cfg

cp zoo_sample.cfg zoo.cfgbash

修改配置文件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=/data/ms/zookeeper-3.4.9/data
dataLogDir=/data/ms/zookeeper-3.4.9/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
server.1=zk149:2888:3888
server.2=zk150:2888:3888
server.3=zk151:2888:3888

配置項說明

配置項 說明
initLimit ZooKeeper集羣模式下包含多個zk進程,其中一個進程爲leader,餘下的進程爲follower。 當follower最初與leader創建鏈接時,它們之間會傳輸至關多的數據,尤爲是follower的數據落後leader不少。initLimit配置follower與leader之間創建鏈接後進行同步的最長時間。
syncLimit 配置follower和leader之間發送消息,請求和應答的最大時間長度。
tickTime tickTime則是上述兩個超時配置的基本單位,例如對於initLimit,其配置值爲5,說明其超時時間爲 2000ms * 5 = 10秒。
server.id=host:port1:port2 其中id爲一個數字,表示zk進程的id,這個id也是dataDir目錄下myid文件的內容。host是該zk進程所在的IP地址,port1表示follower和leader交換消息所使用的端口,port2表示選舉leader所使用的端口。
dataDir 其配置的含義跟單機模式下的含義相似,不一樣的是集羣模式下還有一個myid文件。myid文件的內容只有一行,且內容只能爲1 - 255之間的數字,這個數字亦即上面介紹server.id中的id,表示zk進程的id。
dataLogDir zookeeper日誌存儲路徑

配置環境變量

vim /etc/profile
並在其尾部追加以下內容:oracle

ZOOKEEPER_HOME=/data/ms/zookeeper-3.4.9
JAVA_HOME=/data/java/jdk1.8.0_111
JRE_HOME=/data/java/jdk1.8.0_111/jre
CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH

刷新環境變量

source /etc/profile

關閉系統防火牆或配置防火牆規則

  • 直接關閉防火牆

systemctl stop firewalld.serviceide

  • 禁止firewall開機啓動

禁用防火牆命令 systemctl disable firewalld.service
中止防火牆 systemctl stop firewalld.service工具

zookeeper命令

啓動 zookeeper 服務

zkServer.sh start
如打印以下信息則代表啓動成功:
 ZooKeeper JMX enabled by default
 Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
 Starting zookeeper ... STARTED

查看zookeeper 服務狀態

zkServer.sh status

關閉zookeeper服務

zkServer.sh stop
如打印以下信息則代表成功關閉:
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

重啓zookeeper服務

zkServer.sh restart
 如打印以下信息則代表重啓成功:
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

zookeeper自啓動服務

新建zookeeper腳本

[root@zookeeper ~]# cd /etc/rc.d/init.d/  
[root@zookeeper init.d]# pwd  
/etc/rc.d/init.d  
[root@zookeeper init.d]# vim zookeeper
#!/bin/bash  
#chkconfig:2345 20 90  
#description:zookeeper  
#processname:zookeeper  
export JAVA_HOME=/data/java/jdk1.8.0_111
export ZOOKEEPER_HOME=/data/ms/zookeeper-3.4.9
case $1 in
        start) su root $ZOOKEEPER_HOME/bin/zkServer.sh start;;
        stop) su root $ZOOKEEPER_HOME/bin/zkServer.sh stop;;
        status) su root $ZOOKEEPER_HOME/bin/zkServer.sh status;;
        restart) su $ZOOKEEPER_HOME/bin/zkServer.sh restart;;
        *) echo "require start|stop|status|restart" ;;
esac

給zookeeper腳本授可執行權限

chmod +x zookeeper

添加開機自啓動服務

chkconfig --add zookeeper

查看自啓動狀態

chkconfig --list
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole         0:off    1:off    2:off    3:off    4:off    5:off    6:off
network            0:off    1:off    2:on    3:on    4:on    5:on    6:off
vmware-tools       0:off    1:off    2:on    3:on    4:on    5:on    6:off
zookeeper          0:off    1:off    2:on    3:on    4:on    5:on    6:off
相關文章
相關標籤/搜索