1. 程式人生 > >Zookeeper(五):單機版測試、叢集測試、建立根節點

Zookeeper(五):單機版測試、叢集測試、建立根節點

我們已經搭建好了zookeeper的單機版、偽叢集版、叢集版,現在啟動客戶端連上zkServer進行測試

一、單機版測試

1.1、命令測試

連線上zookeeper的server:zkCli.sh -server 192.168.133.149:2180

# 連線zookeeper單機版的server
[[email protected] bin]# ./zkCli.sh -server 192.168.133.149:2180

# 連線上的日誌
[[email protected] bin]# ./zkCli.sh -server localhost:2180
Connecting to localhost:2180
2018-02-06 13:54:53,970 [myid:] - INFO  [main:
[email protected]
] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT 2018-02-06 13:54:53,974 [myid:] - INFO [main:[email protected]] - Client environment:host.name=localhost 2018-02-06 13:54:53,974 [myid:] - INFO [main:[email protected]
] - Client environment:java.version=1.7.0_80 2018-02-06 13:54:53,977 [myid:] - INFO [main:[email protected]] - Client environment:java.vendor=Oracle Corporation 2018-02-06 13:54:53,977 [myid:] - INFO [main:[email protected]] - Client environment:java.home=/usr/java/jdk1.7.0_80/jre 2018-02-06 13:54:53,977 [myid:] - INFO [main:
[email protected]
] - Client environment:java.class.path=/usr/local/zookeeper-3.4.10/bin/../build/classes:/usr/local/zookeeper-3.4.10/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/usr/local/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.10/bin/../conf:.:/usr/java/jdk1.7.0_80/jre/lib/rt.jar:/usr/java/jdk1.7.0_80/lib/dt.jar:/usr/java/jdk1.7.0_80/lib/tools.jar 2018-02-06 13:54:53,977 [myid:] - INFO [main:[email protected]] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2018-02-06 13:54:53,977 [myid:] - INFO [main:[email protected]] - Client environment:java.io.tmpdir=/tmp 2018-02-06 13:54:53,977 [myid:] - INFO [main:[email protected]] - Client environment:java.compiler=<NA> 2018-02-06 13:54:53,977 [myid:] - INFO [main:[email protected]] - Client environment:os.name=Linux 2018-02-06 13:54:53,978 [myid:] - INFO [main:[email protected]] - Client environment:os.arch=amd64 2018-02-06 13:54:53,978 [myid:] - INFO [main:[email protected]] - Client environment:os.version=2.6.32-358.el6.x86_64 2018-02-06 13:54:53,978 [myid:] - INFO [main:[email protected]] - Client environment:user.name=root 2018-02-06 13:54:53,978 [myid:] - INFO [main:[email protected]] - Client environment:user.home=/root 2018-02-06 13:54:53,978 [myid:] - INFO [main:[email protected]] - Client environment:user.dir=/usr/local/zookeeper-3.4.10/bin 2018-02-06 13:54:53,979 [myid:] - INFO [main:[email protected]] - Initiating client connection, connectString=localhost:2180 sessionTimeout=30000 [email protected] Welcome to ZooKeeper! 2018-02-06 13:54:54,168 [myid:] - INFO [main-SendThread(localhost:2180):[email protected]] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2180. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2018-02-06 13:54:54,818 [myid:] - INFO [main-SendThread(localhost:2180):[email protected]] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2180, initiating session 2018-02-06 13:54:55,331 [myid:] - INFO [main-SendThread(localhost:2180):[email protected]] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2180, sessionid = 0x16168f11c140000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2180(CONNECTED) 0]


由上面日誌可以看出還沒有建立節點目錄,下面我們使用create /service /CEMS_SERVICE新增一個根節點目錄/CEMS_SERVICE

使用 get /service檢視是否新增成功

# 新增一個根節點目錄/CEMS_SERVICE
[zk: localhost:2180(CONNECTED) 0] create /service CEMS_SERVICE          
Created /service
# 檢視新增的節點
[zk: localhost:2180(CONNECTED) 1] get /service
CEMS_SERVICE
cZxid = 0x2
ctime = Tue Feb 06 14:07:41 CST 2018
mZxid = 0x2
mtime = Tue Feb 06 14:07:41 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 12
numChildren = 0
[zk: localhost:2180(CONNECTED) 2]

說明單機配置成功

1.2java程式碼測試

package com.vrv.linkdood_zookeeper;

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;

/**
 *      <B>說    明<B/>:
 * 
 * @author 作者名:馮龍淼
 *            E-mail:[email protected]
 * 
 * @version 版   本  號:1.0.<br/>
 *          建立時間:2018年2月8日 下午5:21:21
 */
public class ZKSingleTest {

    // 會話超時時間,設定為與系統預設時間一致
    private static final int SESSION_TIMEOUT = 30 * 1000;

    // 建立 ZooKeeper 例項
    private ZooKeeper zk;

    // 建立 Watcher 例項
    private Watcher wh = new Watcher() {
        /**
         * Watched事件
         */
        public void process(WatchedEvent event) {
            System.out.println("WatchedEvent >>> " + event.toString());
        }
    };

    // 初始化 ZooKeeper 例項
    private void createZKInstance() throws IOException {
        // 連線到ZK服務,多個可以用逗號分割寫
        zk = new ZooKeeper("192.168.133.149:2180", SESSION_TIMEOUT, wh);
    }

    private void ZKOperations() throws IOException, InterruptedException, KeeperException {
        System.out.println("\n1. 建立 ZooKeeper 節點 (znode : zoo2, 資料: myData2 ,許可權: OPEN_ACL_UNSAFE ,節點型別: Persistent");
        zk.create("/zoo2", "myData2".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

        System.out.println("\n2. 檢視是否建立成功: ");
        System.out.println(new String(zk.getData("/zoo2", this.wh, null)));// 新增Watch

        // 前面一行我們添加了對/zoo2節點的監視,所以這裡對/zoo2進行修改的時候,會觸發Watch事件。
        System.out.println("\n3. 修改節點資料 ");
        zk.setData("/zoo2", "shanhy20160310".getBytes(), -1);

        // 這裡再次進行修改,則不會觸發Watch事件,這就是我們驗證ZK的一個特性“一次性觸發”,也就是說設定一次監視,只會對下次操作起一次作用。
        System.out.println("\n3-1. 再次修改節點資料 ");
        zk.setData("/zoo2", "shanhy20160310-ABCD".getBytes(), -1);

        System.out.println("\n4. 檢視是否修改成功: ");
        System.out.println(new String(zk.getData("/zoo2", false, null)));

        System.out.println("\n5. 刪除節點 ");
        zk.delete("/zoo2", -1);

        System.out.println("\n6. 檢視節點是否被刪除: ");
        System.out.println(" 節點狀態: [" + zk.exists("/zoo2", false) + "]");
    }

    private void ZKClose() throws InterruptedException {
        zk.close();
    }

    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        ZKSingleTest dm = new ZKSingleTest();
        dm.createZKInstance();
        dm.ZKOperations();
        dm.ZKClose();
    }
}

單機版測試結果:

[18/02/08 17:56:48:854][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
[18/02/08 17:56:48:857][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:host.name=PC-201707281439
[18/02/08 17:56:48:857][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.version=1.7.0_60
[18/02/08 17:56:48:857][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.vendor=Oracle Corporation
[18/02/08 17:56:48:860][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.home=D:\Develop\Java\jdk1.7.0_60\jre
[18/02/08 17:56:48:860][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.class.path=D:\workspace_2018\linkdood-disruptor\target\classes;C:\Users\Administrator\.m2\repository\org\apache\logging\log4j\log4j-api\2.6.2\log4j-api-2.6.2.jar;C:\Users\Administrator\.m2\repository\org\apache\logging\log4j\log4j-core\2.6.2\log4j-core-2.6.2.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-context\3.2.17.RELEASE\spring-context-3.2.17.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-aop\4.3.6.RELEASE\spring-aop-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-beans\4.3.6.RELEASE\spring-beans-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-core\4.3.6.RELEASE\spring-core-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-expression\4.3.6.RELEASE\spring-expression-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-webmvc\3.2.17.RELEASE\spring-webmvc-3.2.17.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-web\4.3.6.RELEASE\spring-web-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\com\lmax\disruptor\3.3.6\disruptor-3.3.6.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\core\jersey-client\2.25.1\jersey-client-2.25.1.jar;C:\Users\Administrator\.m2\repository\javax\ws\rs\javax.ws.rs-api\2.0.1\javax.ws.rs-api-2.0.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\core\jersey-common\2.25.1\jersey-common-2.25.1.jar;C:\Users\Administrator\.m2\repository\javax\annotation\javax.annotation-api\1.2\javax.annotation-api-1.2.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\bundles\repackaged\jersey-guava\2.25.1\jersey-guava-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\osgi-resource-locator\1.0.1\osgi-resource-locator-1.0.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\hk2-api\2.5.0-b32\hk2-api-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\hk2-utils\2.5.0-b32\hk2-utils-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\external\aopalliance-repackaged\2.5.0-b32\aopalliance-repackaged-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\external\javax.inject\2.5.0-b32\javax.inject-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\hk2-locator\2.5.0-b32\hk2-locator-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\javassist\javassist\3.21.0-GA\javassist-3.21.0-GA.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\containers\jersey-container-servlet\2.25.1\jersey-container-servlet-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\containers\jersey-container-servlet-core\2.25.1\jersey-container-servlet-core-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\core\jersey-server\2.25.1\jersey-server-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\media\jersey-media-jaxb\2.25.1\jersey-media-jaxb-2.25.1.jar;C:\Users\Administrator\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\media\jersey-media-moxy\2.25.1\jersey-media-moxy-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\ext\jersey-entity-filtering\2.25.1\jersey-entity-filtering-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.moxy\2.6.0\org.eclipse.persistence.moxy-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.core\2.6.0\org.eclipse.persistence.core-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.asm\2.6.0\org.eclipse.persistence.asm-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\glassfish\javax.json\1.0.4\javax.json-1.0.4.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\media\jersey-media-multipart\2.25.1\jersey-media-multipart-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\jvnet\mimepull\mimepull\1.9.6\mimepull-1.9.6.jar;C:\Users\Administrator\.m2\repository\javax\javaee-api\7.0\javaee-api-7.0.jar;C:\Users\Administrator\.m2\repository\com\sun\mail\javax.mail\1.5.6\javax.mail-1.5.6.jar;C:\Users\Administrator\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\Administrator\.m2\repository\org\apache\zookeeper\zookeeper\3.4.10\zookeeper-3.4.10.jar;C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-api\1.7.22\slf4j-api-1.7.22.jar;C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-log4j12\1.7.22\slf4j-log4j12-1.7.22.jar;C:\Users\Administrator\.m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar;C:\Users\Administrator\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\Administrator\.m2\repository\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.library.path=D:\Develop\Java\jdk1.7.0_60\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/Develop/Java/jdk1.7.0_60/bin/../jre/bin/server;D:/Develop/Java/jdk1.7.0_60/bin/../jre/bin;D:/Develop/Java/jdk1.7.0_60/bin/../jre/lib/amd64;C:\Program Files (x86)\Common Files\NetSarang;D:\Develop\apache-tomcat-7.0.54\bin;D:\Develop\maven\bin;D:\Develop\Java\jdk1.7.0_60\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\Develop\SVN\bin;E:\Python\Scripts\;E:\Python\;D:\Develop\eclipse4.3_x86_64;;.
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.compiler=<NA>
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:os.name=Windows 7
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:os.arch=amd64
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:os.version=6.1
[18/02/08 17:56:48:861][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:user.name=Administrator
[18/02/08 17:56:48:862][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:user.home=C:\Users\Administrator
[18/02/08 17:56:48:862][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:user.dir=D:\workspace_2018\linkdood-disruptor
[18/02/08 17:56:48:863][ INFO][org.apache.zookeeper.ZooKeeper.<init>(ZooKeeper.java:438)] Initiating client connection, connectString=192.168.133.149:2180 sessionTimeout=30000 [email protected]
[18/02/08 17:56:48:869][DEBUG][org.apache.zookeeper.ClientCnxn.<clinit>(ClientCnxn.java:117)] zookeeper.disableAutoWatchReset is false

1. 建立 ZooKeeper 節點 (znode : zoo2, 資料: myData2 ,許可權: OPEN_ACL_UNSAFE ,節點型別: Persistent
[18/02/08 17:56:48:901][ INFO][org.apache.zookeeper.ClientCnxn$SendThread.logStartConnect(ClientCnxn.java:1032)] Opening socket connection to server 192.168.133.149/192.168.133.149:2180. Will not attempt to authenticate using SASL (unknown error)
[18/02/08 17:56:48:904][ INFO][org.apache.zookeeper.ClientCnxn$SendThread.primeConnection(ClientCnxn.java:876)] Socket connection established to 192.168.133.149/192.168.133.149:2180, initiating session
[18/02/08 17:56:48:906][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.primeConnection(ClientCnxn.java:949)] Session establishment request sent on 192.168.133.149/192.168.133.149:2180
[18/02/08 17:56:49:041][ INFO][org.apache.zookeeper.ClientCnxn$SendThread.onConnected(ClientCnxn.java:1299)] Session establishment complete on server 192.168.133.149/192.168.133.149:2180, sessionid = 0x16168f11c140023, negotiated timeout = 30000
WatchedEvent >>> WatchedEvent state:SyncConnected type:None path:null
[18/02/08 17:56:49:048][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 1,1  replyHeader:: 1,195,0  request:: '/zoo2,#6d794461746132,v{s{31,s{'world,'anyone}}},0  response:: '/zoo2 

2. 檢視是否建立成功: 
[18/02/08 17:56:49:054][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 2,4  replyHeader:: 2,195,0  request:: '/zoo2,T  response:: #6d794461746132,s{195,195,1518082914037,1518082914037,0,0,0,0,7,0,195} 
myData2

3. 修改節點資料 
[18/02/08 17:56:49:057][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:766)] Got notification sessionid:0x16168f11c140023
[18/02/08 17:56:49:058][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:788)] Got WatchedEvent state:SyncConnected type:NodeDataChanged path:/zoo2 for sessionid 0x16168f11c140023
[18/02/08 17:56:49:059][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 3,5  replyHeader:: 3,196,0  request:: '/zoo2,#7368616e68793230313630333130,-1  response:: s{195,196,1518082914037,1518082914048,1,0,0,0,14,0,195} 
WatchedEvent >>> WatchedEvent state:SyncConnected type:NodeDataChanged path:/zoo2

3-1. 再次修改節點資料 
[18/02/08 17:56:49:071][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 4,5  replyHeader:: 4,197,0  request:: '/zoo2,#7368616e687932303136303331302d41424344,-1  response:: s{195,197,1518082914037,1518082914055,2,0,0,0,19,0,195} 

4. 檢視是否修改成功: 
[18/02/08 17:56:49:090][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 5,4  replyHeader:: 5,197,0  request:: '/zoo2,F  response:: #7368616e687932303136303331302d41424344,s{195,197,1518082914037,1518082914055,2,0,0,0,19,0,195} 
shanhy20160310-ABCD

5. 刪除節點 
[18/02/08 17:56:49:092][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 6,2  replyHeader:: 6,198,0  request:: '/zoo2,-1  response:: null

6. 檢視節點是否被刪除: 
[18/02/08 17:56:49:096][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 7,3  replyHeader:: 7,198,-101  request:: '/zoo2,F  response::  
 節點狀態: [null]
[18/02/08 17:56:49:099][DEBUG][org.apache.zookeeper.ZooKeeper.close(ZooKeeper.java:673)] Closing session: 0x16168f11c140023
[18/02/08 17:56:49:099][DEBUG][org.apache.zookeeper.ClientCnxn.close(ClientCnxn.java:1370)] Closing client for session: 0x16168f11c140023
[18/02/08 17:56:49:102][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x16168f11c140023, packet:: clientPath:null serverPath:null finished:false header:: 8,-11  replyHeader:: 8,199,0  request:: null response:: null
[18/02/08 17:56:49:102][DEBUG][org.apache.zookeeper.ClientCnxn.disconnect(ClientCnxn.java:1354)] Disconnecting client for session: 0x16168f11c140023
[18/02/08 17:56:49:102][ INFO][org.apache.zookeeper.ZooKeeper.close(ZooKeeper.java:684)] Session: 0x16168f11c140023 closed


二、叢集版測試

192.168.133.149三個偽叢集、192.168.133.148、192.168.133.158

2.1 命令測試

149狀態資訊

# 149 a
[[email protected] conf]# ../bin/zkServer.sh status ./zoo_flma.cfg 
ZooKeeper JMX enabled by default
Using config: ./zoo_flma.cfg
Mode: follower
# 149 b
[[email protected] conf]# ../bin/zkServer.sh status ./zoo_flmb.cfg 
ZooKeeper JMX enabled by default
Using config: ./zoo_flmb.cfg
Mode: follower
#149 c
[[email protected] conf]# ../bin/zkServer.sh status ./zoo_flmc.cfg 
ZooKeeper JMX enabled by default
Using config: ./zoo_flmc.cfg
Mode: follower


148狀態資訊

[root]:/usr/local/zookeeper-3.4.10/bin# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower

158狀態資訊

[root]:/usr/local/zookeeper-3.4.10/bin# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader


同步測試:

148上執行:

# 連線到zookeeper叢集上的148server
[root]:/usr/local/zookeeper-3.4.10/bin# ./zkCli.sh -server 192.168.133.148:2181
# 執行create /service /CEMS_SERVICE 建立目錄
[zk: 192.168.133.148:2181(CONNECTED) 0] create /service /CEMS_SERVICE
Created /service
# 檢視建立的目錄
[zk: 192.168.133.148:2181(CONNECTED) 1] get /service
/CEMS_SERVICE
cZxid = 0x700000002
ctime = Tue Feb 06 14:55:37 CST 2018
mZxid = 0x700000002
mtime = Tue Feb 06 14:55:37 CST 2018
pZxid = 0x700000002
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
[zk: 192.168.133.148:2181(CONNECTED) 2]
158上檢視同步結果

檢視149a的同步結果


檢視149b同步結果


檢視149c同步結果

五臺叢集資料同步正常,zookeeper叢集沒毛病

2.2 Java程式碼測試

package com.vrv.linkdood_zookeeper;

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;

/**
 * 	 <B>說	明<B/>:
 * 
 * @author 作者名:馮龍淼
 * 		   E-mail:[email protected]
 * 
 * @version 版   本  號:1.0.<br/>
 *          建立時間:2018年2月8日 下午5:21:21
 */
public class ZKClusterTest {

    // 會話超時時間,設定為與系統預設時間一致
    private static final int SESSION_TIMEOUT = 30 * 1000;

    // 建立 ZooKeeper 例項
    private ZooKeeper zk;

    // 建立 Watcher 例項
    private Watcher wh = new Watcher() {
        /**
         * Watched事件
         */
        public void process(WatchedEvent event) {
            System.out.println("WatchedEvent >>> " + event.toString());
        }
    };

    // 初始化 ZooKeeper 例項
    private void createZKInstance() throws IOException {
        // 連線到ZK服務,多個可以用逗號分割寫
        zk = new ZooKeeper("192.168.133.148:2181,192.168.133.148:2182,192.168.133.148:2183,192.168.133.149:2181,192.168.133.158:2181", ZKClusterTest.SESSION_TIMEOUT, this.wh);

    }

    private void ZKOperations() throws IOException, InterruptedException, KeeperException {
        System.out.println("\n1. 建立 ZooKeeper 節點 (znode : zoo2, 資料: myData2 ,許可權: OPEN_ACL_UNSAFE ,節點型別: Persistent");
        zk.create("/zoo2", "myData2".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

        System.out.println("\n2. 檢視是否建立成功: ");
        System.out.println(new String(zk.getData("/zoo2", this.wh, null)));// 新增Watch

        // 前面一行我們添加了對/zoo2節點的監視,所以這裡對/zoo2進行修改的時候,會觸發Watch事件。
        System.out.println("\n3. 修改節點資料 ");
        zk.setData("/zoo2", "shanhy20160310".getBytes(), -1);

        // 這裡再次進行修改,則不會觸發Watch事件,這就是我們驗證ZK的一個特性“一次性觸發”,也就是說設定一次監視,只會對下次操作起一次作用。
        System.out.println("\n3-1. 再次修改節點資料 ");
        zk.setData("/zoo2", "shanhy20160310-ABCD".getBytes(), -1);

        System.out.println("\n4. 檢視是否修改成功: ");
        System.out.println(new String(zk.getData("/zoo2", false, null)));

        System.out.println("\n5. 刪除節點 ");
        zk.delete("/zoo2", -1);

        System.out.println("\n6. 檢視節點是否被刪除: ");
        System.out.println(" 節點狀態: [" + zk.exists("/zoo2", false) + "]");
    }

    private void ZKClose() throws InterruptedException {
        zk.close();
    }

    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
    	ZKClusterTest dm = new ZKClusterTest();
        dm.createZKInstance();
        dm.ZKOperations();
        dm.ZKClose();
    }
}

測試結果:

[18/02/08 17:51:41:071][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
[18/02/08 17:51:41:074][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:host.name=PC-201707281439
[18/02/08 17:51:41:074][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.version=1.7.0_60
[18/02/08 17:51:41:074][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.vendor=Oracle Corporation
[18/02/08 17:51:41:077][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.home=D:\Develop\Java\jdk1.7.0_60\jre
[18/02/08 17:51:41:077][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.class.path=D:\workspace_2018\linkdood-disruptor\target\classes;C:\Users\Administrator\.m2\repository\org\apache\logging\log4j\log4j-api\2.6.2\log4j-api-2.6.2.jar;C:\Users\Administrator\.m2\repository\org\apache\logging\log4j\log4j-core\2.6.2\log4j-core-2.6.2.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-context\3.2.17.RELEASE\spring-context-3.2.17.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-aop\4.3.6.RELEASE\spring-aop-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-beans\4.3.6.RELEASE\spring-beans-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-core\4.3.6.RELEASE\spring-core-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-expression\4.3.6.RELEASE\spring-expression-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-webmvc\3.2.17.RELEASE\spring-webmvc-3.2.17.RELEASE.jar;C:\Users\Administrator\.m2\repository\org\springframework\spring-web\4.3.6.RELEASE\spring-web-4.3.6.RELEASE.jar;C:\Users\Administrator\.m2\repository\com\lmax\disruptor\3.3.6\disruptor-3.3.6.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\core\jersey-client\2.25.1\jersey-client-2.25.1.jar;C:\Users\Administrator\.m2\repository\javax\ws\rs\javax.ws.rs-api\2.0.1\javax.ws.rs-api-2.0.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\core\jersey-common\2.25.1\jersey-common-2.25.1.jar;C:\Users\Administrator\.m2\repository\javax\annotation\javax.annotation-api\1.2\javax.annotation-api-1.2.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\bundles\repackaged\jersey-guava\2.25.1\jersey-guava-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\osgi-resource-locator\1.0.1\osgi-resource-locator-1.0.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\hk2-api\2.5.0-b32\hk2-api-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\hk2-utils\2.5.0-b32\hk2-utils-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\external\aopalliance-repackaged\2.5.0-b32\aopalliance-repackaged-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\external\javax.inject\2.5.0-b32\javax.inject-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\glassfish\hk2\hk2-locator\2.5.0-b32\hk2-locator-2.5.0-b32.jar;C:\Users\Administrator\.m2\repository\org\javassist\javassist\3.21.0-GA\javassist-3.21.0-GA.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\containers\jersey-container-servlet\2.25.1\jersey-container-servlet-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\containers\jersey-container-servlet-core\2.25.1\jersey-container-servlet-core-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\core\jersey-server\2.25.1\jersey-server-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\media\jersey-media-jaxb\2.25.1\jersey-media-jaxb-2.25.1.jar;C:\Users\Administrator\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\media\jersey-media-moxy\2.25.1\jersey-media-moxy-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\ext\jersey-entity-filtering\2.25.1\jersey-entity-filtering-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.moxy\2.6.0\org.eclipse.persistence.moxy-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.core\2.6.0\org.eclipse.persistence.core-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\eclipse\persistence\org.eclipse.persistence.asm\2.6.0\org.eclipse.persistence.asm-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\glassfish\javax.json\1.0.4\javax.json-1.0.4.jar;C:\Users\Administrator\.m2\repository\org\glassfish\jersey\media\jersey-media-multipart\2.25.1\jersey-media-multipart-2.25.1.jar;C:\Users\Administrator\.m2\repository\org\jvnet\mimepull\mimepull\1.9.6\mimepull-1.9.6.jar;C:\Users\Administrator\.m2\repository\javax\javaee-api\7.0\javaee-api-7.0.jar;C:\Users\Administrator\.m2\repository\com\sun\mail\javax.mail\1.5.6\javax.mail-1.5.6.jar;C:\Users\Administrator\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\Administrator\.m2\repository\org\apache\zookeeper\zookeeper\3.4.10\zookeeper-3.4.10.jar;C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-api\1.7.22\slf4j-api-1.7.22.jar;C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-log4j12\1.7.22\slf4j-log4j12-1.7.22.jar;C:\Users\Administrator\.m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar;C:\Users\Administrator\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\Administrator\.m2\repository\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar
[18/02/08 17:51:41:078][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.library.path=D:\Develop\Java\jdk1.7.0_60\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/Develop/Java/jdk1.7.0_60/bin/../jre/bin/server;D:/Develop/Java/jdk1.7.0_60/bin/../jre/bin;D:/Develop/Java/jdk1.7.0_60/bin/../jre/lib/amd64;C:\Program Files (x86)\Common Files\NetSarang;D:\Develop\apache-tomcat-7.0.54\bin;D:\Develop\maven\bin;D:\Develop\Java\jdk1.7.0_60\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\Develop\SVN\bin;E:\Python\Scripts\;E:\Python\;D:\Develop\eclipse4.3_x86_64;;.
[18/02/08 17:51:41:078][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
[18/02/08 17:51:41:078][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:java.compiler=<NA>
[18/02/08 17:51:41:078][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:os.name=Windows 7
[18/02/08 17:51:41:078][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:os.arch=amd64
[18/02/08 17:51:41:078][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:os.version=6.1
[18/02/08 17:51:41:079][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:user.name=Administrator
[18/02/08 17:51:41:079][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:user.home=C:\Users\Administrator
[18/02/08 17:51:41:079][ INFO][org.apache.zookeeper.Environment.logEnv(Environment.java:100)] Client environment:user.dir=D:\workspace_2018\linkdood-disruptor
[18/02/08 17:51:41:081][ INFO][org.apache.zookeeper.ZooKeeper.<init>(ZooKeeper.java:438)] Initiating client connection, connectString=192.168.133.149:2181,192.168.133.149:2182,192.168.133.149:2183,192.168.133.148:2181,192.168.133.158:2181 sessionTimeout=30000 [email protected]
[18/02/08 17:51:41:088][DEBUG][org.apache.zookeeper.ClientCnxn.<clinit>(ClientCnxn.java:117)] zookeeper.disableAutoWatchReset is false

1. 建立 ZooKeeper 節點 (znode : zoo2, 資料: myData2 ,許可權: OPEN_ACL_UNSAFE ,節點型別: Persistent
[18/02/08 17:51:41:119][ INFO][org.apache.zookeeper.ClientCnxn$SendThread.logStartConnect(ClientCnxn.java:1032)] Opening socket connection to server 192.168.133.158/192.168.133.158:2181. Will not attempt to authenticate using SASL (unknown error)
[18/02/08 17:51:41:122][ INFO][org.apache.zookeeper.ClientCnxn$SendThread.primeConnection(ClientCnxn.java:876)] Socket connection established to 192.168.133.158/192.168.133.158:2181, initiating session
[18/02/08 17:51:41:124][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.primeConnection(ClientCnxn.java:949)] Session establishment request sent on 192.168.133.158/192.168.133.158:2181
[18/02/08 17:51:41:170][ INFO][org.apache.zookeeper.ClientCnxn$SendThread.onConnected(ClientCnxn.java:1299)] Session establishment complete on server 192.168.133.158/192.168.133.158:2181, sessionid = 0x4616cb835ff0001, negotiated timeout = 30000
WatchedEvent >>> WatchedEvent state:SyncConnected type:None path:null
[18/02/08 17:51:41:190][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 1,1  replyHeader:: 1,47244640294,0  request:: '/zoo2,#6d794461746132,v{s{31,s{'world,'anyone}}},0  response:: '/zoo2 

2. 檢視是否建立成功: 
[18/02/08 17:51:41:194][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 2,4  replyHeader:: 2,47244640294,0  request:: '/zoo2,T  response:: #6d794461746132,s{47244640294,47244640294,1518083390801,1518083390801,0,0,0,0,7,0,47244640294} 
myData2

3. 修改節點資料 
[18/02/08 17:51:41:217][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:766)] Got notification sessionid:0x4616cb835ff0001
[18/02/08 17:51:41:219][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:788)] Got WatchedEvent state:SyncConnected type:NodeDataChanged path:/zoo2 for sessionid 0x4616cb835ff0001
WatchedEvent >>> WatchedEvent state:SyncConnected type:NodeDataChanged path:/zoo2
[18/02/08 17:51:41:220][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 3,5  replyHeader:: 3,47244640295,0  request:: '/zoo2,#7368616e68793230313630333130,-1  response:: s{47244640294,47244640295,1518083390801,1518083390824,1,0,0,0,14,0,47244640294} 

3-1. 再次修改節點資料 
[18/02/08 17:51:41:238][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 4,5  replyHeader:: 4,47244640296,0  request:: '/zoo2,#7368616e687932303136303331302d41424344,-1  response:: s{47244640294,47244640296,1518083390801,1518083390848,2,0,0,0,19,0,47244640294} 

4. 檢視是否修改成功: 
[18/02/08 17:51:41:240][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 5,4  replyHeader:: 5,47244640296,0  request:: '/zoo2,F  response:: #7368616e687932303136303331302d41424344,s{47244640294,47244640296,1518083390801,1518083390848,2,0,0,0,19,0,47244640294} 
shanhy20160310-ABCD

5. 刪除節點 
[18/02/08 17:51:41:267][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 6,2  replyHeader:: 6,47244640297,0  request:: '/zoo2,-1  response:: null

6. 檢視節點是否被刪除: 
[18/02/08 17:51:41:270][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 7,3  replyHeader:: 7,47244640297,-101  request:: '/zoo2,F  response::  
 節點狀態: [null]
[18/02/08 17:51:41:272][DEBUG][org.apache.zookeeper.ZooKeeper.close(ZooKeeper.java:673)] Closing session: 0x4616cb835ff0001
[18/02/08 17:51:41:273][DEBUG][org.apache.zookeeper.ClientCnxn.close(ClientCnxn.java:1370)] Closing client for session: 0x4616cb835ff0001
[18/02/08 17:51:41:278][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:843)] Reading reply sessionid:0x4616cb835ff0001, packet:: clientPath:null serverPath:null finished:false header:: 8,-11  replyHeader:: 8,47244640298,0  request:: null response:: null
[18/02/08 17:51:41:279][DEBUG][org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1146)] An exception was thrown while closing send thread for session 0x4616cb835ff0001 : Unable to read additional data from server sessionid 0x4616cb835ff0001, likely server has closed socket
[18/02/08 17:51:41:279][DEBUG][org.apache.zookeeper.ClientCnxn.disconnect(ClientCnxn.java:1354)] Disconnecting client for session: 0x4616cb835ff0001
[18/02/08 17:51:41:279][ INFO][org.apache.zookeeper.ZooKeeper.close(ZooKeeper.java:684)] Session: 0x4616cb835ff0001 closed


當主節點down掉從節點主動升級和接管成為主節點

停掉是leader的158 發現148由follower被選舉成為了leader


相關推薦

Zookeeper()單機測試叢集測試建立節點

我們已經搭建好了zookeeper的單機版、偽叢集版、叢集版,現在啟動客戶端連上zkServer進行測試一、單機版測試1.1、命令測試連線上zookeeper的server:zkCli.sh -server 192.168.133.149:2180# 連線zookeeper單

【Hadoop 分布式部署 分布式部署之分發基本測試及監控】

conda -s 啟動 上啟 res 點擊 mon web頁面 mapr 1.對 hadoop 進行格式化     到 /opt/app/hadoop-2.5.0 目錄下  執行命令: bin/hdfs namenode -format       執行的效果圖

Zookeeper的安裝單機叢集

自己寫部落格,很大一部分原因是因為自己安裝過的軟體也老是忘記安裝步驟,每次都是百度的,寫下來供自己參考,當然,有什麼不足的地方,請大神批評指正!!!!!都是搞技術的,有錯指出來就行,歡迎各位騷擾!!!! Zookeeper的單機版安裝 從官網上下載zookeeper的安裝

Docker 也是本地開發的一神器部署單機 Pulsar 和叢集架構 Redis

# 原文連結:[Docker 也是本地開發的一神器:部署單機版 Pulsar 和叢集架構 Redis](https://blog.csdn.net/Howinfun/article/details/109240374) # 一、前言: 現在網際網路的技術架構中,不斷出現各種各樣的中介軟體,例如 MQ、Re

Zookeeper技術分布式架構詳解分布式技術詳解分布式事務

cas 序列號 隔離性 googl 管理系 實現 分布式數據庫 備份 分布式文件系 一、分布式架構詳解 1、分布式發展歷程 1.1 單點集中式 特點:App、DB、FileServer都部署在一臺機器上。並且訪問請求量較少 1.2? 應用服務和數據服務拆分 ?特點:App、

zookeeper概念應用場景資料組織叢集搭建客戶端操作Java客戶端curator

  一、zookeeper簡介      1.1 zookeeper簡介      Apache的很多專案以動物來命令,比如Hadoop(大象)、Hive(小蜜蜂)、Pig(豬豬),這些專案都是hadoop生態系統的成員。Hadoop生態系統是為了解決大資料儲存、大資料計算和大資料資料分析的,解決大

轉載mongodb單機安裝及叢集安裝

一,mongodb單機版安裝 1,下載linux版本的mongodb https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.6.tgz 2,通過ftp上傳,我這邊是傳到/data/program/soft

Docker安裝單機redis5和叢集redis5

轉載請表明出處 https://blog.csdn.net/Amor_Leo/article/details/85147086 謝謝 Docker安裝單機版redis5和叢集版redis5 單機Redis 搜尋redis 拉取r

Redis5.0.3單機安裝以及叢集安裝

轉載請表明出處 https://blog.csdn.net/Amor_Leo/article/details/85143011 謝謝 Redis單機版安裝以及叢集版安裝 Redis單機安裝 建立一個目錄 進入建立的目錄

redis單機偽分散式叢集搭建

    繼上一篇redis單機伺服器搭建成功之後,按如下方式進行叢集搭建。    搭建一個最小的叢集需要6臺機器(由節點投票機制決定至少需要3臺主節點,另外為了高可用每個主節點至少要備一個從節點,所以總共需要6個節點。這裡6個節點全部設在一臺機上,通過埠號來分別。實現偽分散式

spring整合redis單機與redis叢集

前言: 有時候我們部署了叢集版的redis,還希望開發的時候使用單機版(畢竟省事兒),但是比較常用的Java客戶端(Jedis和Lettuce)的單機和叢集api是不統一的。經過調研,發現spring-data-redis可以實現這個需求,本文就是將spring-data-

mongodb單機安裝及叢集安裝

一,mongodb單機版安裝1,下載linux版本的mongodbhttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.6.tgz2,通過ftp上傳,我這邊是傳到/data/program/software這個目錄

zookeeper安裝單點叢集搭建開機自啟動

1下載Zookeeper http://mirror.bit.edu.cn/apache/zookeeper/ http://mirror.bit.edu.cn/apache/zookeeper/stable/wwget wget http://mirror.bit.edu.cn/

SpringBoot系列SpringBoot錯誤處理(資料驗證處理錯誤頁全域性異常)

1、概念: SpringBoot 錯誤處理 2、具體內容 在之前的程式裡面如果一旦出現了錯誤之後就會出現一堆的大白板,這個白板會有一些錯誤資訊(雖然這些錯誤資訊你可能 看不懂,但是這些錯誤資訊依然要告訴給使用者)。在 SpringBoot 裡面針對於錯誤的處理一共提供有

一個簡單的java桌面應用單機IFTTT

1.專案背景: ifttt是“if this then that”的縮寫,事實上是讓你的網路行為能夠引發連鎖反應、讓你使用更為方便。ifttt旨在幫助人們利用各網站的開放API,將各個網站或應用銜接,完成任務。ifttt通過流程將各種資訊串聯起來

Liunx下安裝Redis單機,以及叢集

Redis單機版安裝 第一步:安裝gcc編譯環境 yum install gcc-c++ 第二步:把redis的原始碼上傳到linux伺服器。 第三步:解壓縮。 tar -zxvf redis-3.0.0.tar.gz 第四步:make 第五步:makeinstall P

Postman系列Postman中電商網站cookietoken檢驗與引數傳遞實戰

一:Postman中電商網站cookie實戰   Postman介面請求使用cookie兩種方式:     1.直接在header(頭域)中新增cookie,適用於已知請求cookie頭域的情況     2.使用Postman的cookie管理機制,即可以手動新增,同時Postman也會將操作流程中獲取的引數

devtmpfs檔案系統 建立裝置節點

轉載來自:http://blog.chinaunix.net/uid-27717694-id-3574368.html一、devtmpfs概述1.devtmpfs 的功用是在 Linux 核心 啟動早期建立一個初步的 /dev,令一般啟動程式不用等待 udev,縮短 GNU/Linux 的開機時間。2.重要解

redis cluster 叢集配置示例: 建立, 新增節點, 重新分片, 刪除節點

1 redis叢集搭建 Redis 從3.0.0正式版開始官方支援叢集,  下面開始做一個叢集配置的示例. [[email protected] ~]# tar xf redis-3.2.0.tar.gz [[email protected]