本機搭建dubbo服務並依賴zookeeper註冊中心


搭建dubbo服務的方式是參照這篇博客上編輯做的。

http://blog.csdn.net/qduningning/article/details/41445937


其中替換內容爲zookeeper中心。此處分享pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>dubbo-customer</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>war</packaging>

    <properties>
        <org.springframework.version>3.1.4.RELEASE</org.springframework.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>17.0</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.slf4j</artifactId>
                    <groupId>slf4j-api</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.slf4j</artifactId>
                    <groupId>slf4j-log4j12</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty</artifactId>
                    <groupId>org.jboss.netty</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
            <version>3.4.6</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty</artifactId>
            <version>3.9.6.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>org.springframework.web.servlet</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>
        </dependency>
    </dependencies>
</project>


此結構爲下圖去掉monitor結構。





搭建zookeeper環境可參考http://www.cnblogs.com/Javame/p/3632708.html 前半段


貼配置:此處,server.x後面得跟ip, 或者在hosts裏面有對應。127.0.0.1不行

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/home/q/sourceforge/zookeeper-3.4.6/data
# the port at which the clients will connect
clientPort=3456
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
server.1=192.168.236.65:3457:3458
server.2=192.168.236.171:3457:3458
server.3=192.168.237.253:3457:3458




中間遇到一個極致的問題是:

EndOfStreamException: Unable to read additional data from client sessionid 0x13e6ea9db2c0034, likely client has closed socket at 


這個很有可能是啓動的角色不對或者是權限不對。改定即可。並且初始啓動的時候data目錄不能有除了myid之外的其他文件。

正確的結果是這樣的:

2015-03-06 19:00:18,913 [myid:] - INFO  [main:Environment@100] - Server environment:java.io.tmpdir=/tmp
2015-03-06 19:00:18,913 [myid:] - INFO  [main:Environment@100] - Server environment:java.compiler=<NA>
2015-03-06 19:00:18,916 [myid:] - INFO  [main:Environment@100] - Server environment:os.name=Linux
2015-03-06 19:00:18,916 [myid:] - INFO  [main:Environment@100] - Server environment:os.arch=amd64
2015-03-06 19:00:18,916 [myid:] - INFO  [main:Environment@100] - Server environment:os.version=3.13.0-24-generic
2015-03-06 19:00:18,916 [myid:] - INFO  [main:Environment@100] - Server environment:user.name=
2015-03-06 19:00:18,916 [myid:] - INFO  [main:Environment@100] - Server environment:user.home=/home/
2015-03-06 19:00:18,916 [myid:] - INFO  [main:Environment@100] - Server environment:user.dir=/opt/zookeeper-3.4.6
2015-03-06 19:00:18,927 [myid:] - INFO  [main:ZooKeeperServer@755] - tickTime set to 4000
2015-03-06 19:00:18,927 [myid:] - INFO  [main:ZooKeeperServer@764] - minSessionTimeout set to -1
2015-03-06 19:00:18,927 [myid:] - INFO  [main:ZooKeeperServer@773] - maxSessionTimeout set to -1
2015-03-06 19:00:18,942 [myid:] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2181
2015-03-06 19:00:19,335 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /127.0.0.1:52913
2015-03-06 19:00:19,343 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@841] - Refusing session request for client /127.0.0.1:52913 as it has seen zxid 0x16 our last zxid is 0x0 client must try another server
2015-03-06 19:00:19,343 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1007] - Closed socket connection for client /127.0.0.1:52913 (no session established for client)
2015-03-06 19:00:19,368 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /127.0.0.1:52914
2015-03-06 19:00:19,369 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@841] - Refusing session request for client /127.0.0.1:52914 as it has seen zxid 0x16 our last zxid is 0x0 client must try another server
2015-03-06 19:00:19,369 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1007] - Closed socket connection for client /127.0.0.1:52914 (no session established for client)
2015-03-06 19:00:20,698 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /127.0.0.1:52915


此處分享一個dubbo特牛的地方:


dubbo server與註冊中心爲長連接,註冊中心掛掉之後會一直報錯,直到註冊中心重啓之後服務竟然又能使用了!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章