讓Hadoop跑在云端系列文章,介紹了如何整合虛擬化和Hadoop,讓Hadoop集群跑在VPS虛擬主機上,通過云向用戶提供存儲和計算的服務。
創(chuàng)新互聯(lián)專注于新絳網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供新絳營銷型網(wǎng)站建設,新絳網(wǎng)站制作、新絳網(wǎng)頁設計、新絳網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務,打造新絳網(wǎng)絡公司原創(chuàng)品牌,更為您提供新絳網(wǎng)站排名全網(wǎng)營銷落地服務。現(xiàn)在硬件越來越便宜,一臺非品牌服務器,2顆24核CPU,配48G內(nèi)存,2T的硬盤,已經(jīng)降到2萬塊人民幣以下了。這種配置如果簡單地放幾個web應用,顯然是奢侈的浪費。就算是用來實現(xiàn)單節(jié)點的hadoop,對計算資源浪費也是非常高的。對于這么高性能的計算機,如何有效利用計算資源,就成為成本控制的一項重要議題了。
通過虛擬化技術,我們可以將一臺服務器,拆分成12臺VPS,每臺2核CPU,4G內(nèi)存,40G硬盤,并且支持資源重新分配。多么偉大的技術?。‖F(xiàn)在我們有了12個節(jié)點的hadoop集群, 讓Hadoop跑在云端,讓世界加速。
關于作者:
張丹(Conan), 程序員Java,R,PHP,Javascript weibo:@Conan_Z blog:http://blog.fens.me email: bsspirit@gmail.com轉(zhuǎn)載請注明出處:
http://blog.fens.me/hadoop-zookeeper-intro/
前言
ZooKeeper是Hadoop家族的一款高性能的分布式協(xié)作的產(chǎn)品。在單機中,系統(tǒng)協(xié)作大都是進程級的操作。分布式系統(tǒng)中,服務協(xié)作都是跨服務器才能完成的。在ZooKeeper之前,我們對于協(xié)作服務大都使用消息中間件,隨著分布式系統(tǒng)的普及,用消息中間件完成協(xié)作,會有大量的程序開發(fā)。ZooKeeper直接面向于分布式系統(tǒng),可以減少我們自己的開發(fā),幫助我們更好完成分布式系統(tǒng)的數(shù)據(jù)管理問題。
目錄
zookeeper介紹 zookeeper單節(jié)點安裝 zookeeper偽分布式集群安裝 zookeeper命令行操作 Java編程現(xiàn)實命令行操作 1. zookeeper介紹ZooKeeper是一個為分布式應用所設計的分布的、開源的協(xié)調(diào)服務,它主要是用來解決分布式應用中經(jīng)常遇到的一些數(shù)據(jù)管理問題,簡化分布式應用協(xié)調(diào)及其管理的難度,提供高性能的分布式服務。ZooKeeper本身可以以Standalone模式安裝運行,不過它的長處在于通過分布式ZooKeeper集群(一個Leader,多個Follower),基于一定的策略來保證ZooKeeper集群的穩(wěn)定性和可用性,從而實現(xiàn)分布式應用的可靠性。
ZooKeeper是作為分布式協(xié)調(diào)服務,是不需要依賴于Hadoop的環(huán)境,也可以為其他的分布式環(huán)境提供服務。
2. zookeeper單節(jié)點安裝Standalones模式系統(tǒng)環(huán)境:
Linux Ubuntu 12.04.2 LTS 64bit server Java: 1.6.0_29 64-Bit Server VM~ uname -a Linux conan 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:13:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux ~ cat /etc/issue Ubuntu 12.04.2 LTS n l ~ java -version java version "1.6.0_29" Java(TM) SE Runtime Environment (build 1.6.0_29-b11) Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)
下載zookeeper
~ mkdir /home/conan/toolkit ~ cd /home/conan/toolkit ~ wget http://apache.dataguru.cn/zookeeper/stable/zookeeper-3.4.5.tar.gz ~ tar xvf zookeeper-3.4.5.tar.gz ~ mv zookeeper-3.4.5 zookeeper345 ~ cd zookeeper345 ~ ls -l drwxr-xr-x 2 conan conan 4096 Aug 12 04:34 bin -rw-r--r-- 1 conan conan 75988 Aug 12 04:34 build.xml -rw-r--r-- 1 conan conan 70223 Aug 12 04:34 CHANGES.txt drwxr-xr-x 2 conan conan 4096 Aug 12 04:34 conf drwxr-xr-x 10 conan conan 4096 Aug 12 04:34 contrib drwxr-xr-x 2 conan conan 4096 Aug 12 04:34 dist-maven drwxr-xr-x 6 conan conan 4096 Aug 12 04:34 docs -rw-r--r-- 1 conan conan 1953 Aug 12 04:34 ivysettings.xml -rw-r--r-- 1 conan conan 3120 Aug 12 04:34 ivy.xml drwxr-xr-x 4 conan conan 4096 Aug 12 04:34 lib -rw-r--r-- 1 conan conan 11358 Aug 12 04:34 LICENSE.txt -rw-r--r-- 1 conan conan 170 Aug 12 04:34 NOTICE.txt -rw-r--r-- 1 conan conan 1770 Aug 12 04:34 README_packaging.txt -rw-r--r-- 1 conan conan 1585 Aug 12 04:34 README.txt drwxr-xr-x 5 conan conan 4096 Aug 12 04:34 recipes drwxr-xr-x 8 conan conan 4096 Aug 12 04:34 src -rw-r--r-- 1 conan conan 1315806 Aug 12 04:34 zookeeper-3.4.5.jar -rw-r--r-- 1 conan conan 833 Aug 12 04:34 zookeeper-3.4.5.jar.asc -rw-r--r-- 1 conan conan 33 Aug 12 04:34 zookeeper-3.4.5.jar.md5 -rw-r--r-- 1 conan conan 41 Aug 12 04:34 zookeeper-3.4.5.jar.sha1
修改配置文件conf/zoo.cfg
~ mkdir /home/conan/zoo/zk0 ~ cp conf/zoo_sample.cfg conf/zoo.cfg ~ vi conf/zoo.cfg ckTime=2000 initLimit=10 syncLimit=5 dataDir=/home/conan/zoo/zk0 clientPort=2181
非常簡單,我們已經(jīng)配置好了的zookeeper單節(jié)點
啟動zookeeper
~ bin/zkServer.sh JMX enabled by default Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd} conan@conan:~/zoo/zk0/zookeeper345$ bin/zkServer.sh start JMX enabled by default Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg Starting zookeeper ... STARTED #zk的服務顯示為QuorumPeerMain ~ jps 5321 QuorumPeerMain 5338 Jps #查看運行狀態(tài) ~ bin/zkServer.sh status JMX enabled by default Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg Mode: standalone
單節(jié)點的時,Mode會顯示為standalone
停止ZooKeeper服務
~ bin/zkServer.sh stop JMX enabled by default Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED 3. zookeeper偽分布式集群安裝
所謂 “偽分布式集群” 就是在,在一臺PC中,啟動多個ZooKeeper的實例。“完全分布式集群” 是每臺PC,啟動一個ZooKeeper實例。
由于我的測試環(huán)境PC數(shù)量有限,所以在一臺PC中,啟動3個ZooKeeper的實例。
創(chuàng)建環(huán)境目錄
~ mkdir /home/conan/zoo/zk1 ~ mkdir /home/conan/zoo/zk2 ~ mkdir /home/conan/zoo/zk3 #新建myid文件 ~ echo "1" > /home/conan/zoo/zk1/myid ~ echo "2" > /home/conan/zoo/zk2/myid ~ echo "3" > /home/conan/zoo/zk3/myid
分別修改配置文件
修改:dataDir,clientPort
增加:集群的實例,server.X,”X”表示每個目錄中的myid的值
~ vi /home/conan/toolkit/zookeeper345/conf/zk1.cfg ckTime=2000 initLimit=10 syncLimit=5 dataDir=/home/conan/zoo/zk1 clientPort=2181 server.1=192.168.1.201:2888:3888 server.2=192.168.1.201:2889:3889 server.3=192.168.1.201:2890:3890 ~ vi /home/conan/toolkit/zookeeper345/conf/zk2.cfg ckTime=2000 initLimit=10 syncLimit=5 dataDir=/home/conan/zoo/zk2 clientPort=2182 server.1=192.168.1.201:2888:3888 server.2=192.168.1.201:2889:3889 server.3=192.168.1.201:2890:3890 ~ vi /home/conan/toolkit/zookeeper345/conf/zk3.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/conan/zoo/zk3 clientPort=2183 server.1=192.168.1.201:2888:3888 server.2=192.168.1.201:2889:3889 server.3=192.168.1.201:2890:3890
3個節(jié)點的ZooKeeper集群配置完成,接下來我們的啟動服務。
啟動集群
~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh start zk1.cfg ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh start zk2.cfg ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh start zk3.cfg ~ jps 5422 QuorumPeerMain 5395 QuorumPeerMain 5463 QuorumPeerMain 5494 Jps #查看節(jié)點狀態(tài) ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh status zk1.cfg JMX enabled by default Using config: /home/conan/toolkit/zookeeper345/bin/../conf/zk1.cfg Mode: follower ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh status zk2.cfg JMX enabled by default Using config: /home/conan/toolkit/zookeeper345/bin/../conf/zk2.cfg Mode: leader ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh status zk3.cfg JMX enabled by default Using config: /home/conan/toolkit/zookeeper345/bin/../conf/zk3.cfg Mode: follower
我們可以看到zk2是leader,zk1和zk3是follower
查看ZooKeeper物理文件目錄結構
~ tree -L 3 /home/conan/zoo /home/conan/zoo ├── zk0 ├── zk1 │ ├── myid │ ├── version-2 │ │ ├── acceptedEpoch │ │ ├── currentEpoch │ │ ├── log.100000001 │ │ └── snapshot.0 │ └── zookeeper_server.pid ├── zk2 │ ├── myid │ ├── version-2 │ │ ├── acceptedEpoch │ │ ├── currentEpoch │ │ ├── log.100000001 │ │ └── snapshot.0 │ └── zookeeper_server.pid └── zk3 ├── myid ├── version-2 │ ├── acceptedEpoch │ ├── currentEpoch │ ├── log.100000001 │ └── snapshot.100000000 └── zookeeper_server.pid 7 directories, 18 files 4. zookeeper命令行操作
我們通過客戶端連接ZooKeeper的集群,我們可以任意的zookeeper是進行連接。
~ /home/conan/toolkit/zookeeper345/bin/zkCli.sh -server 192.168.1.201:2181 Connecting to 192.168.1.201 2013-08-12 05:25:39,260 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT 2013-08-12 05:25:39,267 [myid:] - INFO [main:Environment@100] - Client environment:host.name=conan 2013-08-12 05:25:39,269 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.6.0_29 2013-08-12 05:25:39,269 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Sun Microsystems Inc. 2013-08-12 05:25:39,270 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/home/conan/toolkit/jdk16/jre 2013-08-12 05:25:39,270 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/home/conan/toolkit/zookeeper345/bin/../build/classes:/home/conan/toolkit/zookeeper345/bin/../build/lib/*.jar:/home/conan/toolkit/zookeeper345/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/conan/toolkit/zookeeper345/bin/../lib/slf4j-api-1.6.1.jar:/home/conan/toolkit/zookeeper345/bin/../lib/netty-3.2.2.Final.jar:/home/conan/toolkit/zookeeper345/bin/../lib/log4j-1.2.15.jar:/home/conan/toolkit/zookeeper345/bin/../lib/jline-0.9.94.jar:/home/conan/toolkit/zookeeper345/bin/../zookeeper-3.4.5.jar:/home/conan/toolkit/zookeeper345/bin/../src/java/lib/*.jar:/home/conan/toolkit/zookeeper345/bin/../conf: 2013-08-12 05:25:39,271 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/home/conan/toolkit/jdk16/jre/lib/amd64/server:/home/conan/toolkit/jdk16/jre/lib/amd64:/home/conan/toolkit/jdk16/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2013-08-12 05:25:39,275 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2013-08-12 05:25:39,276 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler= 2013-08-12 05:25:39,276 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2013-08-12 05:25:39,277 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2013-08-12 05:25:39,281 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.5.0-23-generic 2013-08-12 05:25:39,282 [myid:] - INFO [main:Environment@100] - Client environment:user.name=conan 2013-08-12 05:25:39,282 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/conan 2013-08-12 05:25:39,283 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/conan/zoo 2013-08-12 05:25:39,284 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=192.168.1.201 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@22ba6c83 Welcome to ZooKeeper! JLine support is enabled [zk: 192.168.1.201(CONNECTING) 0] 2013-08-12 05:25:39,336 [myid:] - INFO [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@966] - Opening socket connection to server 192.168.1.201/192.168.1.201:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration) 2013-08-12 05:25:39,345 [myid:] - INFO [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@849] - Socket connection established to 192.168.1.201/192.168.1.201:2181, initiating session 2013-08-12 05:25:39,384 [myid:] - INFO [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@1207] - Session establishment complete on server 192.168.1.201/192.168.1.201:2181, sessionid = 0x1406f3c1ef90001, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: 192.168.1.201(CONNECTED) 0]
集群已連接,下面我們要使用一下,ZooKeeper的命令行操作。
命令行操作
通過help打印命令行幫助
[zk: 192.168.1.201(CONNECTED) 1] help ZooKeeper -server host:port cmd args connect host:port get path [watch] ls path [watch] set path data [version] rmr path delquota [-n|-b] path quit printwatches on|off create [-s] [-e] path data acl stat path [watch] close ls2 path [watch] history listquota path setAcl path acl getAcl path sync path redo cmdno addauth scheme auth delete path [version] setquota -n|-b val path
ZooKeeper的結構,很像是目錄結構,我們看到了像ls這樣熟悉的命令。
#ls,查看/目錄內(nèi)容 [zk: 192.168.1.201(CONNECTED) 1] ls / [zookeeper] #create,創(chuàng)建一個znode節(jié)點 [zk: 192.168.1.201(CONNECTED) 2] create /node conan Created /node #ls,再查看/目錄 [zk: 192.168.1.201(CONNECTED) 3] ls / [node, zookeeper] #get,查看/node的數(shù)據(jù)信息 [zk: 192.168.1.201(CONNECTED) 4] get /node conan cZxid = 0x100000006 ctime = Mon Aug 12 05:32:49 CST 2013 mZxid = 0x100000006 mtime = Mon Aug 12 05:32:49 CST 2013 pZxid = 0x100000006 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 0 #set,修改數(shù)據(jù) [zk: 192.168.1.201(CONNECTED) 5] set /node fens.me cZxid = 0x100000006 ctime = Mon Aug 12 05:32:49 CST 2013 mZxid = 0x100000007 mtime = Mon Aug 12 05:34:32 CST 2013 pZxid = 0x100000006 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0 #get,再查看/node的數(shù)據(jù)信息,已改為fens.me [zk: 192.168.1.201(CONNECTED) 6] get /node fens.me cZxid = 0x100000006 ctime = Mon Aug 12 05:32:49 CST 2013 mZxid = 0x100000007 mtime = Mon Aug 12 05:34:32 CST 2013 pZxid = 0x100000006 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0 #delete,刪除/node [zk: 192.168.1.201(CONNECTED) 7] delete /node [zk: 192.168.1.201(CONNECTED) 8] ls / [zookeeper] #quit,退出客戶端連接 [zk: 192.168.1.201(CONNECTED) 19] quit Quitting... 2013-08-12 05:40:29,304 [myid:] - INFO [main:ZooKeeper@684] - Session: 0x1406f3c1ef90002 closed 2013-08-12 05:40:29,305 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@509] - EventThread shut down 5. Java編程現(xiàn)實命令行操作
package org.conan.zookeeper.demo; import java.io.IOException; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.ZooKeeper; public class BasicDemo1 { public static void main(String[] args) throws IOException, KeeperException, InterruptedException { // 創(chuàng)建一個與服務器的連接 ZooKeeper zk = new ZooKeeper("192.168.1.201:2181", 60000, new Watcher() { // 監(jiān)控所有被觸發(fā)的事件 public void process(WatchedEvent event) { System.out.println("EVENT:" + event.getType()); } }); // 查看根節(jié)點 System.out.println("ls / => " + zk.getChildren("/", true)); // 創(chuàng)建一個目錄節(jié)點 if (zk.exists("/node", true) == null) { zk.create("/node", "conan".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); System.out.println("create /node conan"); // 查看/node節(jié)點數(shù)據(jù) System.out.println("get /node => " + new String(zk.getData("/node", false, null))); // 查看根節(jié)點 System.out.println("ls / => " + zk.getChildren("/", true)); } // 創(chuàng)建一個子目錄節(jié)點 if (zk.exists("/node/sub1", true) == null) { zk.create("/node/sub1", "sub1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); System.out.println("create /node/sub1 sub1"); // 查看node節(jié)點 System.out.println("ls /node => " + zk.getChildren("/node", true)); } // 修改節(jié)點數(shù)據(jù) if (zk.exists("/node", true) != null) { zk.setData("/node", "changed".getBytes(), -1); // 查看/node節(jié)點數(shù)據(jù) System.out.println("get /node => " + new String(zk.getData("/node", false, null))); } // 刪除節(jié)點 if (zk.exists("/node/sub1", true) != null) { zk.delete("/node/sub1", -1); zk.delete("/node", -1); // 查看根節(jié)點 System.out.println("ls / => " + zk.getChildren("/", true)); } // 關閉連接 zk.close(); } }
運行結果:
2013-08-12 15:33:29,699 [myid:] - INFO [main:Environment@97] - Client environment:zookeeper.version=3.3.1-942149, built on 05/07/2010 17:14 GMT 2013-08-12 15:33:29,702 [myid:] - INFO [main:Environment@97] - Client environment:host.name=PC201304202140 2013-08-12 15:33:29,702 [myid:] - INFO [main:Environment@97] - Client environment:java.version=1.6.0_45 2013-08-12 15:33:29,702 [myid:] - INFO [main:Environment@97] - Client environment:java.vendor=Sun Microsystems Inc. 2013-08-12 15:33:29,702 [myid:] - INFO [main:Environment@97] - Client environment:java.home=D:toolkitjavajdk6jre 2013-08-12 15:33:29,703 [myid:] - INFO [main:Environment@97] - Client environment:java.class.path=D:workspacejavazkdemotargetclasses;C:UsersAdministrator.m2repositoryorgapachehadoopzookeeper3.3.1zookeeper-3.3.1.jar;C:UsersAdministrator.m2repositorylog4jlog4j1.2.15log4j-1.2.15.jar;C:UsersAdministrator.m2repositoryjavaxmailmail1.4mail-1.4.jar;C:UsersAdministrator.m2repositoryjavaxactivationactivation1.1activation-1.1.jar;C:UsersAdministrator.m2repositoryjlinejline?.9.94jline-0.9.94.jar;C:UsersAdministrator.m2repositoryjunitjunit3.8.1junit-3.8.1.jar 2013-08-12 15:33:29,703 [myid:] - INFO [main:Environment@97] - Client environment:java.library.path=D:toolkitjavajdk6bin;C:WindowsSunJavabin;C:Windowssystem32;C:Windows;D:toolkitRtoolsbin;D:toolkitRtoolsgcc-4.6.3bin;C:Program Files (x86)Common FilesNetSarang;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:toolkitGitcmd;D:toolkitGitbin;C:Program Files (x86)Microsoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100DTSBinn;c:Program Files (x86)Common FilesUlead SystemsMPEG;C:Program Files (x86)QuickTimeQTSystem;D:toolkitMiKTexmiktexbinx64;D:toolkitsshclient;D:toolkitant19bin;D:toolkiteclipse;D:toolkitgradle15bin;D:toolkitjavajdk6bin;D:toolkitmaven3bin;D:toolkitmysql56bin;D:toolkitpython27;D:toolkitputty;C:Program FilesRR-3.0.1binx64;D:toolkitmongodb243bin;D:toolkitphp54;D:toolkitnginx140;D:toolkitnodejs;D:toolkitnpm12bin;D:toolkitjavajdk6jrebinserver;. 2013-08-12 15:33:29,703 [myid:] - INFO [main:Environment@97] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp 2013-08-12 15:33:29,704 [myid:] - INFO [main:Environment@97] - Client environment:java.compiler= 2013-08-12 15:33:29,704 [myid:] - INFO [main:Environment@97] - Client environment:os.name=Windows 7 2013-08-12 15:33:29,704 [myid:] - INFO [main:Environment@97] - Client environment:os.arch=amd64 2013-08-12 15:33:29,705 [myid:] - INFO [main:Environment@97] - Client environment:os.version=6.1 2013-08-12 15:33:29,705 [myid:] - INFO [main:Environment@97] - Client environment:user.name=Administrator 2013-08-12 15:33:29,705 [myid:] - INFO [main:Environment@97] - Client environment:user.home=C:UsersAdministrator 2013-08-12 15:33:29,706 [myid:] - INFO [main:Environment@97] - Client environment:user.dir=D:workspacejavazkdemo 2013-08-12 15:33:29,707 [myid:] - INFO [main:ZooKeeper@373] - Initiating client connection, connectString=192.168.1.201:2181 sessionTimeout=60000 watcher=org.conan.zookeeper.demo.BasicDemo1$1@3dfeca64 2013-08-12 15:33:29,731 [myid:] - INFO [main-SendThread():ClientCnxn$SendThread@1000] - Opening socket connection to server /192.168.1.201:2181 2013-08-12 15:33:38,736 [myid:] - INFO [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@908] - Socket connection established to 192.168.1.201/192.168.1.201:2181, initiating session 2013-08-12 15:33:38,804 [myid:] - INFO [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@701] - Session establishment complete on server 192.168.1.201/192.168.1.201:2181, sessionid = 0x1406f3c1ef9000d, negotiated timeout = 60000 EVENT:None ls / => [zookeeper] EVENT:NodeCreated EVENT:NodeChildrenChanged create /node conan get /node => conan ls / => [node, zookeeper] EVENT:NodeCreated create /node/sub1 sub1 ls /node => [sub1] EVENT:NodeDataChanged get /node => changed EVENT:NodeDeleted EVENT:NodeChildrenChanged EVENT:NodeChildrenChanged ls / => [zookeeper] 2013-08-12 15:33:38,877 [myid:] - INFO [main:ZooKeeper@538] - Session: 0x1406f3c1ef9000d closed
pom.xml,maven配置文件
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.conan.zookeeper</groupId> <artifactId>zkdemo</artifactId> <version>0.0.1</version> <name>zkdemo</name> <description>zkdemo</description> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>zookeeper</artifactId> <version>3.3.1</version> <exclusions> <exclusion> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> </exclusion> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project>
基礎講完,接下來就讓我動手管理起,我們自己的分布式系統(tǒng)吧。
轉(zhuǎn)載請注明出處:
http://blog.fens.me/hadoop-zookeeper-intro/
分享名稱:ZooKeeper偽分布式集群安裝及使用
網(wǎng)站鏈接:http://www.rwnh.cn/article18/cpocdp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站排名、網(wǎng)頁設計公司、網(wǎng)站營銷、靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)