在上一篇文章中,我们已经成功运行了一个dubbo的demo.这一篇来搭建dubbo管理中心。

第一步搭建zookeeper环境



首先搭建zookeeper环境。直接下载解压就好。下载地址为 http://www.apache.org/dyn/closer.cgi/zookeeper/


解压之后,要修改一下配置文件,在conf目录下要把zoo_sample.cfg改名为zoo.cfg,因为zookeeper在启动时会找到这个文件作为默认配置文件。打开这个文件


# 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=D:\\zookeeper-3.4.6\\tmp  
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1



1.将dataDir=/tmp改为自己喜欢的路径,我改的是dataDir=D:\\zookeeper-3.4.6\\tmp


2.tickTime:这个时间是作为Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间就会发送一个心跳。


3.dataDir:就是Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。


4.dataLogDir:就是Zookeeper保存日志文件的目录


5.clientPort:这个端口就是客户端连接Zookeeper服务器的端口,Zookeeper会监听这个端口,接受客户端的访问请求。


当这些都配置好了之后,就可使使用zkServer.cmd来启动Zookeeper了。可以使用netstat -ano命令来查看是否有配置的端口号来验证是否启动成功。还可以在dos窗口输入jps,如果出现如下显示,就表示成功了。


C:\Users\Administrator>jps
13676 Jps
8960 QuorumPeerMain
13224 Bootstrap
2516


一定要注意,这个注册中心一定要在程序运行之前就打开,而且要一直开着。


第二步安装dubbo-admin管理平台




由于环境,停止更新等问题,在打包运行dubbo-admin的过程中,费了很多时间,我这里就只把最后正确的操作贴出来。


首先将从git上下载代码到本地 https://github.com/alibaba/dubbo ,再把dubbo-admin项目引入到本地工作空间,我们只需要关注这一个项目就好了。


我本地环境使用的是jdk1.7。接着要做如下修改


1.修改dubbo-admin/.settings/org.eclipse.wst.common.project.facet.core.xml中的java版本改为1.7


2. 修改pom.xmlcom.alibaba dubbo的版本号位2.5.3

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
        </dependency>


3.在pom.xml中添加跳过测试的配置


<plugin>
	        <groupId>org.apache.maven.plugins</groupId>
	        <artifactId>maven-surefire-plugin</artifactId>
	        <configuration>
	          <skip>true</skip>
	        </configuration>
	      </plugin>

全部配置好了之后就可以打包了。放到tomcat7下,启动成功,这里要注意tomcat的端口号不能用8080,因为zookeeper会用到。


来看看运行之后的界面

dubbo 管理后台 dubbo管理界面_dubbo 管理后台


最后要在部署的项目里面配置下zookeeper,路径是dubbo-admin-2.5.4-SNAPSHOT\WEB-INF\dubbo.properties

dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest




第三步运行服务提供者和消费者

我把上一篇中,provider.xml里面配置的zookeeper注册的注释打开。然后先后启动服务提供者和服务消费者,可以在管理里面看到提供者的信息


dubbo 管理后台 dubbo管理界面_dubbo_02