UbuntuϵͳÏ°²×°Zookeeper
1.1 ZookeeperµÄÏÂÔØ
ZookeeperµÄÓ¦Óã¬ËüÊÇÒ»¸öÀàËÆ·þÎñÆ÷µÄ¿ò¼Ü£¬ËùÒÔ£¬ÒªÊ¹ÓÃËü£¬ÊÇÐèÒª½øÐа²×°ºÍÅäÖõġ£Ò»°ã¶¼»á°ÑZookeeper°²×°ÔÚLinuxϵͳÖС£
Ìáʾһµã£¬ÔÚ°²×°Ê¹ÓÃZookeeper֮ǰ£¬±ØÐëÒªÏÈÈ·±£ÄãµÄLinuxϵͳÖУ¬¿ÉÒÔÕý³£Ê¹ÓÃJDK¡£
È»ºóÔÚWindowsϵͳÖÐÏÂÔØZookeeper°²×°°ü¡£
ZookeeperÏÂÔصØÖ·£º
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
https://www-eu.apache.org/dist/zookeeper/
Ñ¡ÔñÄúÒªµÄ°æ±¾£¬ÕâÀïÏÂÔصÄÊÇ3.5.4°æ±¾£º
ͼ 1 ZookeeperÏÂÔصØÖ·
ÏÂÔغõÄLinuxѹËõ°ü£ºzookeeper-3.5.4-beta.tar
1.1 °²×°Zookeeper
1.1.1 »ñÈ¡°²×°°ü
°ÑÕâ¸ö°²×°°ü·¢Ë͵½LinuxÖнøÐа²×°¡£
·¢Ë͵ķ½Ê½Óкܶ࣬Èç¹ûÄãµÄUbuntu°²×°ÁËVMware Tools¹¤¾ß£¬¿ÉÒÔÖ±½Ó°Ñ°²×°°üÍ϶¯¸´ÖƵ½UbuntuµÄ×ÀÃæ¡£
Ò²¿ÉÒÔʹÓÃXShell +XFtp¹¤¾ßÀ´½øÐд«Êä¡£
ÕâÀïÎÒÃÇʹÓõÄÊÇÖ±½Ó¸´ÖƵķ½Ê½£¬°ÑѹËõ°ü¸´ÖƵ½UbuntuµÄ×ÀÃæÖУº
ͼ2 ¸´ÖÆZookeeperѹËõ°üµ½Ubuntu×ÀÃæÖÐ
¸´ÖƺÃÖ®ºó£¬ÔÚ¸ùĿ¼ʹÓÃÃüÁî´´½¨Ò»¸özookeeperµÄĿ¼£º
ͼ3 ´´½¨zookeeperµÄĿ¼
°ÑUbuntu×ÀÃæµÄZookeeperѹËõ°üÒƶ¯µ½zookeeperĿ¼À
±í1
edu118@edu118-virtual-machine:/zookeeper$ cd ~ edu118@edu118-virtual-machine:~$ ls ¹«¹²µÄ Ä£°å ÊÓƵ ͼƬ Îĵµ ÏÂÔØ ÒôÀÖ ×ÀÃæ edu118@edu118-virtual-machine:~$ cd ×ÀÃæ edu118@edu118-virtual-machine:~/×ÀÃæ$ ls zookeeper-3.5.4-beta.tar.gz edu118@edu118-virtual-machine:~/×ÀÃæ$ sudo mv zookeeper-3.5.4-beta.tar.gz /zookeeper/ edu118@edu118-virtual-machine:~/×ÀÃæ$ cd /zo bash: cd: /zo: ûÓÐÄǸöÎļþ»òĿ¼ edu118@edu118-virtual-machine:~/×ÀÃæ$ cd /zookeeper/ edu118@edu118-virtual-machine:/zookeeper$ ls zookeeper-3.5.4-beta.tar.gz edu118@edu118-virtual-machine:/zookeeper$ |
ͼ4 Òƶ¯Ñ¹Ëõ°ü
1.1.1 ½âѹ°²×°°ü
½âѹÎļþ£º
±í2
edu118@edu118-virtual-machine:/zookeeper$ ls zookeeper-3.5.4-beta.tar.gz edu118@edu118-virtual-machine:/zookeeper$ sudo tar -xvf zookeeper-3.5.4-beta.tar.gz |
½âѹºÃÁËÖ®ºó£¬¾Í¿ÉÒÔ¿´µ½ÔÚzookeeperĿ¼Ï£¬ÓÐÕâÑùµÄÒ»¸ö×ÓĿ¼£º
ͼ5 ½âѹÎļþ
ʹÓÃÃüÁî½øÈëµ½/zookeeper/zookeeper-3.5.4-betaĿ¼Ï£¬´´½¨Ò»¸ödataĿ¼£º
ͼ6 ´´½¨dataĿ¼
1.1.1 ÐÞ¸ÄÅäÖÃÎļþ
ÔÙʹÓÃÃüÁî½øÈëµ½/zookeeper/zookeeper-3.5.4-beta/confĿ¼Ï£¬¸´ÖÆzoo_sample.cfgÎļþ£¬ÖØÃüÃûΪzoo.cfg¡£
±í3
edu118@edu118-virtual-machine:/zookeeper$ cd zookeeper-3.5.4-beta/ edu118@edu118-virtual-machine:/zookeeper/zookeeper-3.5.4-beta$ ls bin ivy.xml src build.xml lib zookeeper-3.5.4-beta.jar conf LICENSE.txt zookeeper-3.5.4-beta.jar.asc contrib NOTICE.txt zookeeper-3.5.4-beta.jar.md5 dist-maven README.md zookeeper-3.5.4-beta.jar.sha1 docs README_packaging.txt ivysettings.xml recipes edu118@edu118-virtual-machine:/zookeeper/zookeeper-3.5.4-beta$ cd conf edu118@edu118-virtual-machine:/zookeeper/zookeeper-3.5.4-beta/conf$ ls configuration.xsl log4j.properties zoo_sample.cfg edu118@edu118-virtual-machine:/zookeeper/zookeeper-3.5.4-beta/conf$ sudo cp zoo_sample.cfg zoo.cfg edu118@edu118-virtual-machine:/zookeeper/zookeeper-3.5.4-beta/conf$ ls configuration.xsl log4j.properties zoo.cfg zoo_sample.cfg |
ͼ7 ¸´ÖÆZookeeperÅäÖÃÎļþ
´ò¿ª¸´ÖƵÄzoo.cfgÅäÖÃÎļþ½øÐÐÐ޸ģº
±í4
sudo vim zoo.cfg |
ÐÞ¸ÄdataDirµÄÐÅÏ¢£¬°´ÏÂinsert¼ü½øÐÐÐ޸ġ£
ͼ8 ÐÞ¸ÄÇ°µÄÔÊý¾Ý
°ÑdataDirµÄ·¾¶£¬Ö¸Ïòµ±Ç°ZookeeperËùÔÚµÄλÖõÄdataĿ¼Ï£º
ͼ9 ÐÞ¸ÄdataDirĿ¼
Ð޸ĺÃÁËÖ®ºó£¬°´ÏÂEscͨ¹ýÐÞ¸Ä״̬£¬ÔÙÊäÈë:wq±£´æ²¢Í˳ö¡£
1.1.1 ZookeeperµÄʹÓÃÃüÁî
Õâ¸öʱºò¾Í¿ÉÒÔÆô¶¯ZookeeperÁË£¬½øÈëµ½binĿ¼Ï£º
ͼ10 ½øÈëZookeeperµÄbinĿ¼
ÒªÆô¶¯Zookeeper£¬¾ÍÐèÒªÇл»µ½rootÓû§²Å¿ÉÒÔ£¬Ê¹ÓÃsuÃüÁÊäÈëÃÜÂë¾Í¿ÉÒÔÁË¡£
±í5
Æô¶¯zookeeper£º bin/zkServer.sh start ¹Ø±Õzookeeper£º bin/zkServer.sh stop ²é¿´zookeeper״̬£º bin/zkServer.sh status ÖØÆôzookeeper£º bin/zkServer.sh restart |
Èç¹ûÊǽøÈëµ½binĿ¼Ï£¬¾Í¿ÉÒÔÔËÐе±Ç°Ä¿Â¼ÏµÄÎļþ£¬±ÈÈç: ./zkServer.sh start
Æô¶¯£º
ͼ11 ZookeeperµÄÆô¶¯×´Ì¬
²é¿´£º
ͼ12 ²é¿´Zookeeperµ±Ç°×´Ì¬
ÏÖÔÚÊÇÆô¶¯µÄ״̬¡£
Í£Ö¹£º
ͼ13 Í£Ö¹ZookeeperµÄÔËÐÐ
×¢Ò⣺zookeeperʹÓÃ2181¶Ë¿ÚºÅ£¬ÎªÁËÄÜÕý³£Ê¹ÓÃzookeeper£¬ÎÒÃÇÐèÒª´ò¿ª2181¶Ë¿ÚºÅ£¬»òÕ߹رշÀ»ðǽ¡£
ÒªÐ޸ķÀ»ð·À»ðǽ£¬¿ª·¢¶Ë¿Ú£¬ÐèҪʹÓÃrootȨÏÞ½øÐÐÉèÖ㬿ÉÒÔʹÓÃsuÃüÁÊäÈëÃÜÂë¾Í¿ÉÒÔÇл»µ½rootÓû§¡£
¹Ø±Õ·À»ðǽ£ºserviceiptables stop
ʹÓÃÕâ¸öÃüÁîÀ´¹Ø±Õ·À»ðǽ£¬ÊÇÒ»´ÎÐԵģ¬µ±ÏµÍ³Æô¶¯µÄʱºò£¬·À»ðǽ»áÔٴοªÆô£¬Èç¹ûÊÇÓÀ¾Ã¹Ø±Õ£¬¿ÉÒÔʹÓÃÕâ¸öÃüÁchkconfigiptables off
²é¿´ÊÖÖ¸¶¨¶Ë¿ÚÊÇ·ñ¿ª·Å£ºlsof-i:2181£¬ÓÐÊý¾Ý³öÀ´£¬¾Í˵Ã÷ÒѾ¿ª·Å¡£
²é¿´ËùÓÐÒÑ¿ª·ÅµÄ¶Ë¿Ú£ºnetstat¨Captn
1.1.1 ²âÊÔ
²âÊÔÊÇ·ñÆô¶¯³É¹¦£¬´ò¿ªZookeeperµÄ¿Í»§¶Ë£¬Èç¹ûÁ¬½Ó³É¹¦£¬¾Í˵Ã÷ZookeeperÆô¶¯ÊÇûÓÐÎÊÌâµÄ£º
±í6
./zkCli.sh -server 127.0.0.1:2181 |
Èç¹û³öÏÖÀàËÆÕâÑùµÄÐÅÏ¢£¬ËµÃ÷Á¬½Ó³É¹¦£º
±í7
Connecting to 127.0.0.1:2181 2019-01-04 21:03:52,250 [myid:] - INFO [main:Environment@109] - Client environment:zookeeper.version=3.5.4-beta-7f51e5b68cf2f80176ff944a9ebd2abbc65e7327, built on 05/11/2018 16:27 GMT 2019-01-04 21:03:52,256 [myid:] - INFO [main:Environment@109] - Client environment:host.name=edu118-virtual-machine 2019-01-04 21:03:52,256 [myid:] - INFO [main:Environment@109] - Client environment:java.version=1.8.0_191 2019-01-04 21:03:52,260 [myid:] - INFO [main:Environment@109] - Client environment:java.vendor=Oracle Corporation 2019-01-04 21:03:52,260 [myid:] - INFO [main:Environment@109] - Client environment:java.home=/java/jdk1.8.0_191/jre 2019-01-04 21:03:52,260 [myid:] - INFO [main:Environment@109] - Client environment:java.class.path=/zookeeper/zookeeper-3.5.4-beta/bin/../build/classes:/zookeeper/zookeeper-3.5.4-beta/bin/../build/lib/*.jar:/zookeeper/zookeeper-3.5.4-beta/bin/../lib/slf4j-log4j12-1.7.25.jar:/zookeeper/zookeeper-3.5.4-beta/bin/../lib/slf4j-api-1.7.25.jar:/zookeeper/zookeeper-3.5.4-beta/bin/../lib/netty-3.10.6.Final.jar:/zookeeper/zookeeper-3.5.4-beta/bin/../lib/log4j- ...... Welcome to ZooKeeper! 2019-01-04 21:03:52,305 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1106] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2019-01-04 21:03:52,412 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@947] - Socket connection established, initiating session, client: /127.0.0.1:40578, server: 127.0.0.1/127.0.0.1:2181 2019-01-04 21:03:52,499 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1381] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x10000357f030000, negotiated timeout = 30000 [zk: 127.0.0.1:2181(CONNECTING) 0] WATCHER::
WatchedEvent state:SyncConnected type:None path:null |
Èç¹ûÁ¬½Óʧ°Ü£¬»áÓÐÌáʾ¡£
Õâ¸öʱºò£¬¾Í¿ÉÒÔ½øÐÐһЩ¼òµ¥µÄ²âÊÔ£¬±ÈÈçÊäÈëÕâÑùµÄÃüÁ
±í8
ls / [zookeeper] [zk: 127.0.0.1:2181(CONNECTED) 1] create /edu118 hello Created /edu118 [zk: 127.0.0.1:2181(CONNECTED) 2] get /edu118 hello [zk: 127.0.0.1:2181(CONNECTED) 3] |
ls / ÏÔʾ¸ùĿ¼ÏÂÎļþ
´´½¨Îļþ£¬²¢ÉèÖóõʼÄÚÈÝ£º
create /edu118 hello
»ñÈ¡ÎļþÄÚÈÝ£º
get /edu118
Í˳ö¿Í»§¶Ë£º
quit