您的位置:首页 > 其它

本机搭建dubbo服务并依赖zookeeper注册中心

2015-03-06 18:47 543 查看
搭建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与注册中心为长连接,注册中心挂掉之后会一直报错,直到注册中心重启之后服务竟然又能使用了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: