您好,登錄后才能下訂單哦!
操作系統:centOS-6.8 2.6.32-642.el6.x86_64【虛擬機環境】 節點主機:10.0.55.3、10.0.55.5、10.0.55.6 目錄結構: /opt/ 軟件版本: jdk-7u67-linux-x64.rpm zookeeper-3.5.0-alpha.tar.gz
$ rpm -ivh jdk-7u67-linux-x64.rpm $ cat /etc/profile export JAVA_HOME=/usr/java/jdk1.7.0_67 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin 立即生效 $ source /etc/profile
$ wget http://archive.apache.org/dist/zookeeper/zookeeper-3.5.0-alpha/zookeeper-3.5.0-alpha.tar.gz $ ln -s /opt/zookeeper-3.5.0-alpha /opt/zookeeper $ mkdir /opt/zookeeper/data $ echo "1" > /opt/zookeeper/data/myid
$ cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg --- 查看zoo.cfg內容 --- tickTime=2000 initLimit=10 syncLimit=5 dataDir=/opt/zookeeper/data clientPort=2181 server.1=10.0.55.3:2888:3888 server.2=10.0.55.5:2888:3888 server.3=10.0.55.6:2888:3888
--- 啟動服務 --- $ /opt/zookeeper/bin/zkServer.sh start JMX enabled by default Using config: /opt/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED --- 檢查端口 --- netstat -lnpt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22678 0.0.0.0:* LISTEN 1074/sshd tcp 0 0 :::2181 :::* LISTEN 121685/java tcp 0 0 :::55369 :::* LISTEN 121685/java tcp 0 0 ::ffff:10.0.55.3:3888 :::* LISTEN 121685/java tcp 0 0 :::8080 :::* LISTEN 121685/java tcp 0 0 :::22678 :::* LISTEN 1074/sshd
這里只介紹如何使用ansible的命令組件模塊進行節點部署
為了節省篇幅,這里不介紹ansible的部署安裝
$ ansible webservers -m copy -a 'src=zookeeper-3.5.0-alpha.tar.gz dest=/opt/ owner=root group=root mode=0644' $ ansible webservers -m shell -a 'tar fxz /opt/zookeeper-3.5.0-alpha.tar.gz -C /opt/' $ ansible webservers -m shell -a 'ln -s /opt/zookeeper-3.5.0-alpha /opt/zookeeper' $ ansible webservers -m shell -a 'mkdir /opt/zookeeper/data' $ ansible webservers -m shell -a 'echo "2" >/opt/zookeeper/data/myid'
$ ansible webservers -m copy -a 'src=/opt/zookeeper/conf/zoo.cfg dest=/opt/zookeeper/conf/zoo.cfg owner=root group=root mode=0644'
$ ansible webservers -m shell -a '/opt/zookeeper/bin/zkServer.sh stats' $ ansible webservers -m shell -a 'netstat -lnpt'
$ ansible webservers -m shell -a '/opt/zookeeper/bin/zkServer.sh status' 10.0.55.5 | SUCCESS | rc=0 >> Client port found: 2181 Mode: leaderJMX enabled by default ## 這里面的mode信息中,該主機被選舉為 Leader Using config: /opt/zookeeper/bin/../conf/zoo.cfg 10.0.55.3 | SUCCESS | rc=0 >> Client port found: 2181 Mode: followerJMX enabled by default ## 這里面的mode信息中,該主機被選舉為 follower Using config: /opt/zookeeper/bin/../conf/zoo.cfg 10.0.55.6 | SUCCESS | rc=0 >> Client port found: 2181 Mode: followerJMX enabled by default ## 這里面的mode信息中,該主機被選舉為 follower Using config: /opt/zookeeper/bin/../conf/zoo.cfg
[root@lbl opt]# ./zookeeper/bin/zkCli.sh
znode
--- 創建一個/workers路徑的znode --- [zk: localhost:2181(CONNECTED) 0] create /workers helloworld Created /workers --- 使用get -s命令查看znode數據 --- [zk: localhost:2181(CONNECTED) 1] get -s /workers helloworld cZxid = 0x500000006 ctime = Sat Apr 22 10:33:42 CST 2017 mZxid = 0x500000006 mtime = Sat Apr 22 10:33:42 CST 2017 pZxid = 0x500000006 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 6 numChildren = 0 --- 使用get -w選項,進行監聽/factory的變化 --- [zk: localhost:2181(CONNECTED) 11] get -w /workers strong --- 在 follower節點上啟動客戶端,并修改/workers --- [root@lbl bin]# ./zkCli.sh [zk: localhost:2181(CONNECTED) 2] set /workers weakness ---查看監聽那臺主機,返回的通知信息如下: --- [zk: localhost:2181(CONNECTED) 12] WATCHER:: WatchedEvent state:SyncConnected type:NodeDataChanged path:/workers --- 刪除workers的znode --- [zk: localhost:2181(CONNECTED) 7] delete /workers
[zk: localhost:2181(CONNECTED) 13] create -s /workers/worker- Created /workers/worker-0000000000 [zk: localhost:2181(CONNECTED) 14] create -s /workers/worker- Created /workers/worker-0000000001 [zk: localhost:2181(CONNECTED) 15] create -s /workers/worker- Created /workers/worker-0000000002 [zk: localhost:2181(CONNECTED) 16] create -s /workers/worker- Created /workers/worker-0000000003
[zk: localhost:2181(CONNECTED) 18] stat /workers cZxid = 0x500000006 ctime = Sat Apr 22 10:33:42 CST 2017 mZxid = 0x500000008 mtime = Sat Apr 22 10:35:25 CST 2017 pZxid = 0x50000000c cversion = 4 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 8 numChildren = 4
--- 從zookeeper-3.5.0版本以上,可以使用http接口提交4字命令的請求; --- 在zookeeper服務中嵌入了Jetty server作為AdminServer管理服務器,其默認端口為8080; --- 服務訪問的URL格式是"/commands/[command name]",例如:訪問stats命令 --- 服務器返回的結果是以JSON格式顯示 http://10.0.55.3:8080/commands http://10.0.55.3:8080/commands/stats
【分布式協調系統zookeeper】基礎篇
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。