ZooKeeper安裝

ZooKeeper安裝

ZooKeeper單機(jī)安裝

  • 官網(wǎng)下載地址

  • 環(huán)境

    • centos7
    • jdk8
  • 創(chuàng)建用戶zookeeper

    # 創(chuàng)建用戶組
    groupadd zookeeper
    # 創(chuàng)建用戶
    useradd -d /home/zookeeper -g zookeeper -G zookeeper -m zookeeper
    # 創(chuàng)建密碼
    passwd zookeeper
    
  • 上傳安裝包并解壓

    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ ll
    total 35816
    drwxr-xr-x 11 zookeeper zookeeper     4096 Mar  9 11:44 zookeeper-3.4.12
    -rwxr-xr-x  1 zookeeper zookeeper 36667596 Mar  9 11:43 zookeeper-3.4.12.tar.gz
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ 
    
  • 修改配置文件

    # 進(jìn)入配置目錄
    cd zookeeper-3.4.12/conf/
    # 修改配置文件名
    cp zoo_sample.cfg zoo.cfg
    # 修改配置文件
    vi zoo.cfg
    
    # The number of milliseconds of each tick
    # tickTime:CS通信心跳數(shù)
    # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔拳氢,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳储耐。tickTime以毫秒為單位。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信時(shí)限
    # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)犯助。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信時(shí)限
    # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:數(shù)據(jù)文件目錄
    # zookeeper保存數(shù)據(jù)的目錄暑脆,默認(rèn)情況下渠啤,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。
    dataDir=/home/zookeeper/software/zookeeper-3.4.12/data
    
    # dataLogDir:日志文件目錄
    # zookeeper保存日志文件的目錄添吗。
    dataLogDir=/home/zookeeper/software/zookeeper-3.4.12/logs
    
    # the port at which the clients will connect
    # clientPort:客戶端連接端口
    # 客戶端連接 Zookeeper 服務(wù)器的端口沥曹,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求根资。
    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
    
  • 命令匯總

    # 啟動(dòng)命令
    ./bin/zkServer.sh start
    # 停止命令
    ./bin/zkServer.sh stop  
    # 重啟命令
    ./bin/zkServer.sh restart
    # 狀態(tài)查看命令
    ./bin/zkServer.sh status
    

ZooKeeper集群?jiǎn)螜C(jī)部署

  • 部署規(guī)劃

    ip client端服務(wù)端口 zk通訊端口 zk選舉端口
    127.0.0.1 2181 2887 3887
    127.0.0.1 2182 2888 3888
    127.0.0.1 2183 2889 3889
  • 官網(wǎng)下載地址

  • 環(huán)境

    • centos7
    • jdk8
  • 創(chuàng)建用戶zookeeper

    # 創(chuàng)建用戶組
    groupadd zookeeper
    # 創(chuàng)建用戶
    useradd -d /home/zookeeper -g zookeeper -G zookeeper -m zookeeper
    # 創(chuàng)建密碼
    passwd zookeeper
    
  • 上傳安裝包并解壓三份

    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ ll
    total 35824
    drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 10 16:56 zk1
    drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 10 16:56 zk2
    drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 10 16:56 zk3
    -rwxr-xr-x  1 zookeeper zookeeper 36667596 Mar  9 11:43 zookeeper-3.4.12.tar.gz
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ 
    
  • 創(chuàng)建myid文件

    # zk1服務(wù)器
    mkdir zk1/data
    cd zk1/data/
    
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ pwd
    /home/zookeeper/software/zk1/data
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$
    
    # 創(chuàng)建myid文件架专,并寫入內(nèi)容1
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ cat myid
    1
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ 
    
    # zk2, zk3服務(wù)器分別創(chuàng)建myid文件,分別寫入2玄帕,3
    
  • 配置文件

    # 進(jìn)入配置目錄
    cd zk1/conf/
    # 修改配置文件名
    cp zoo_sample.cfg zoo.cfg
    

    zk1-zoo.cfg

    # The number of milliseconds of each tick
    # tickTime:CS通信心跳數(shù)
    # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔部脚,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。tickTime以毫秒為單位裤纹。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信時(shí)限
    # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)委刘。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信時(shí)限
    # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:數(shù)據(jù)文件目錄
    # zookeeper保存數(shù)據(jù)的目錄鹰椒,默認(rèn)情況下锡移,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。
    dataDir=/home/zookeeper/software/zk1/data
    # dataLogDir:日志文件目錄
    # zookeeper保存日志文件的目錄漆际。
    dataLogDir=/home/zookeeper/software/zk1/logs
    
    # the port at which the clients will connect
    # clientPort:客戶端連接端口
    # 客戶端連接 Zookeeper 服務(wù)器的端口淆珊,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求奸汇。
    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.myid文件中的值=ip:集群內(nèi)部通訊地址:集群選舉端口
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    

    zk2-zoo.cfg

    # The number of milliseconds of each tick
    # tickTime:CS通信心跳數(shù)
    # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔施符,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。tickTime以毫秒為單位擂找。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信時(shí)限
    # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)戳吝。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信時(shí)限
    # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:數(shù)據(jù)文件目錄
    # zookeeper保存數(shù)據(jù)的目錄贯涎,默認(rèn)情況下听哭,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。
    dataDir=/home/zookeeper/software/zk2/data
    # dataLogDir:日志文件目錄
    # zookeeper保存日志文件的目錄塘雳。
    dataLogDir=/home/zookeeper/software/zk2/logs
    
    # the port at which the clients will connect
    # clientPort:客戶端連接端口
    # 客戶端連接 Zookeeper 服務(wù)器的端口陆盘,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求败明。
    clientPort=2182
    
    # 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.myid文件中的值=ip:集群內(nèi)部通訊地址:集群選舉端口
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    

    zk3-zoo.cfg

    # The number of milliseconds of each tick
    # tickTime:CS通信心跳數(shù)
    # Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔礁遣,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。tickTime以毫秒為單位肩刃。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信時(shí)限
    # 集群中的follower服務(wù)器(F)與leader服務(wù)器(L)之間初始連接時(shí)能容忍的最多心跳數(shù)(tickTime的數(shù)量)。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信時(shí)限
    # 集群中的follower服務(wù)器與leader服務(wù)器之間請(qǐng)求和應(yīng)答之間能容忍的最多心跳數(shù)(tickTime的數(shù)量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:數(shù)據(jù)文件目錄
    # zookeeper保存數(shù)據(jù)的目錄盈包,默認(rèn)情況下沸呐,Zookeeper將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。
    dataDir=/home/zookeeper/software/zk3/data
    # dataLogDir:日志文件目錄
    # zookeeper保存日志文件的目錄呢燥。
    dataLogDir=/home/zookeeper/software/zk3/logs
    
    # the port at which the clients will connect
    # clientPort:客戶端連接端口
    # 客戶端連接 Zookeeper 服務(wù)器的端口崭添,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請(qǐng)求叛氨。
    clientPort=2183
    
    # 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.myid文件中的值=ip:集群內(nèi)部通訊地址:集群選舉端口
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    
  • 啟動(dòng)

    # zk1
    /home/zookeeper/software/zk1/bin/zkServer.sh start
    # zk2
    /home/zookeeper/software/zk2/bin/zkServer.sh start
    # zk3
    /home/zookeeper/software/zk3/bin/zkServer.sh start
    
  • 查看狀態(tài)

    # zk1
    /home/zookeeper/software/zk1/bin/zkServer.sh status
    ----------------
    ZooKeeper JMX enabled by default
    Using config: /home/zookeeper/software/zk1/bin/../conf/zoo.cfg
    Mode: follower
    ----------------
    # zk2
    /home/zookeeper/software/zk2/bin/zkServer.sh status
    ----------------
    ZooKeeper JMX enabled by default
    Using config: /home/zookeeper/software/zk2/bin/../conf/zoo.cfg
    Mode: leader
    ----------------
    # zk3
    /home/zookeeper/software/zk3/bin/zkServer.sh status
    ----------------
    ZooKeeper JMX enabled by default
    Using config: /home/zookeeper/software/zk3/bin/../conf/zoo.cfg
    Mode: follower
    ----------------
    

    ?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末呼渣,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子寞埠,更是在濱河造成了極大的恐慌屁置,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件仁连,死亡現(xiàn)場(chǎng)離奇詭異蓝角,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)饭冬,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門使鹅,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人昌抠,你說我怎么就攤上這事患朱。” “怎么了炊苫?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵裁厅,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我劝评,道長(zhǎng)姐直,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任蒋畜,我火速辦了婚禮声畏,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘姻成。我一直安慰自己插龄,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布科展。 她就那樣靜靜地躺著均牢,像睡著了一般。 火紅的嫁衣襯著肌膚如雪才睹。 梳的紋絲不亂的頭發(fā)上徘跪,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天甘邀,我揣著相機(jī)與錄音,去河邊找鬼垮庐。 笑死松邪,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的哨查。 我是一名探鬼主播逗抑,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼寒亥!你這毒婦竟也來了邮府?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤溉奕,失蹤者是張志新(化名)和其女友劉穎褂傀,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體腐宋,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡紊服,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了胸竞。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片欺嗤。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖卫枝,靈堂內(nèi)的尸體忽然破棺而出煎饼,到底是詐尸還是另有隱情,我是刑警寧澤校赤,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布吆玖,位于F島的核電站,受9級(jí)特大地震影響马篮,放射性物質(zhì)發(fā)生泄漏沾乘。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧角钩,春花似錦、人聲如沸掷匠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽讹语。三九已至,卻和暖如春蜂科,著一層夾襖步出監(jiān)牢的瞬間顽决,已是汗流浹背短条。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留才菠,地道東北人慌烧。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像鸠儿,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子厕氨,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容