Dubbo学习笔记3:Dubbo管理控制台与监控中心的搭建

Dubbo源码下载与编译

本文来讲下如何在Dubbo源码编译后,得到用于搭建管理控制台的war包和监控平台的jar包。

首先需要到Github上下载Dubbo的源码,解压后如下:

 

在dubbo-2.5.x目录执行 mvn clean package -Dmaven.test.skip=true 会生成如下结果:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] dubbo-parent ...................................... SUCCESS [2.857s]
[INFO] Hessian Lite(Alibaba embed version) ............... SUCCESS [6.518s]
[INFO] dubbo-common ...................................... SUCCESS [7.706s]
[INFO] dubbo-container ................................... SUCCESS [0.057s]
[INFO] dubbo-container-api ............................... SUCCESS [3.398s]
[INFO] dubbo-container-spring ............................ SUCCESS [1.099s]
[INFO] dubbo-container-jetty ............................. SUCCESS [1.164s]
[INFO] dubbo-container-log4j ............................. SUCCESS [1.196s]
[INFO] dubbo-container-logback ........................... SUCCESS [1.138s]
[INFO] dubbo-remoting .................................... SUCCESS [0.045s]
[INFO] dubbo-remoting-api ................................ SUCCESS [3.615s]
[INFO] dubbo-remoting-netty .............................. SUCCESS [1.959s]
[INFO] dubbo-remoting-mina ............................... SUCCESS [1.602s]
[INFO] dubbo-remoting-grizzly ............................ SUCCESS [1.752s]
[INFO] dubbo-remoting-p2p ................................ SUCCESS [2.148s]
[INFO] dubbo-remoting-http ............................... SUCCESS [2.154s]
[INFO] dubbo-remoting-zookeeper .......................... SUCCESS [2.165s]
[INFO] dubbo-remoting-netty4 ............................. SUCCESS [2.721s]
[INFO] dubbo-rpc ......................................... SUCCESS [0.060s]
[INFO] dubbo-rpc-api ..................................... SUCCESS [3.397s]
[INFO] dubbo-rpc-default ................................. SUCCESS [3.278s]
[INFO] dubbo-rpc-injvm ................................... SUCCESS [1.706s]
[INFO] dubbo-rpc-rmi ..................................... SUCCESS [1.373s]
[INFO] dubbo-rpc-hessian ................................. SUCCESS [1.791s]
[INFO] dubbo-rpc-http .................................... SUCCESS [1.210s]
[INFO] dubbo-rpc-webservice .............................. SUCCESS [1.816s]
[INFO] dubbo-cluster ..................................... SUCCESS [2.690s]
[INFO] dubbo-registry .................................... SUCCESS [0.033s]
[INFO] dubbo-registry-api ................................ SUCCESS [2.548s]
[INFO] dubbo-monitor ..................................... SUCCESS [0.020s]
[INFO] dubbo-monitor-api ................................. SUCCESS [1.309s]
[INFO] dubbo-filter ...................................... SUCCESS [0.023s]
[INFO] dubbo-filter-validation ........................... SUCCESS [1.474s]
[INFO] dubbo-filter-cache ................................ SUCCESS [1.395s]
[INFO] dubbo-registry-default ............................ SUCCESS [1.402s]
[INFO] dubbo-monitor-default ............................. SUCCESS [1.258s]
[INFO] dubbo-registry-multicast .......................... SUCCESS [1.336s]
[INFO] dubbo-config ...................................... SUCCESS [0.018s]
[INFO] dubbo-config-api .................................. SUCCESS [3.498s]
[INFO] dubbo-config-spring ............................... SUCCESS [3.326s]
[INFO] dubbo-rpc-thrift .................................. SUCCESS [2.115s]
[INFO] dubbo-rpc-memcached ............................... SUCCESS [1.476s]
[INFO] dubbo-rpc-redis ................................... SUCCESS [1.367s]
[INFO] dubbo-registry-zookeeper .......................... SUCCESS [1.597s]
[INFO] dubbo-registry-redis .............................. SUCCESS [2.111s]
[INFO] dubbo-plugin ...................................... SUCCESS [0.027s]
[INFO] dubbo-qos ......................................... SUCCESS [2.574s]
[INFO] dubbo ............................................. SUCCESS [2.662s]
[INFO] dubbo-simple ...................................... SUCCESS [0.017s]
[INFO] dubbo-registry-simple ............................. SUCCESS [5.246s]
[INFO] dubbo-monitor-simple .............................. SUCCESS [11.301s]
[INFO] dubbo-admin ....................................... SUCCESS [11.472s]
[INFO] dubbo-demo ........................................ SUCCESS [0.034s]
[INFO] dubbo-demo-api .................................... SUCCESS [1.097s]
[INFO] dubbo-demo-provider ............................... SUCCESS [1.892s]
[INFO] dubbo-demo-consumer ............................... SUCCESS [1.473s]
[INFO] dubbo-test ........................................ SUCCESS [0.022s]
[INFO] dubbo-test-benchmark .............................. SUCCESS [5.324s]
[INFO] dubbo-test-compatibility .......................... SUCCESS [0.017s]
[INFO] dubbo-test-spring3 ................................ SUCCESS [1.719s]
[INFO] dubbo-test-integration ............................ SUCCESS [0.149s]
[INFO] dubbo-test-examples ............................... SUCCESS [3.413s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:16.562s
[INFO] Finished at: Wed Mar 14 17:19:06 CST 2018
[INFO] Final Memory: 38M/654M
[INFO] ------------------------------------------------------------------------

进入/Users/xxx/Downloads/dubbo-2.5.x/dubbo-admin/target目录,会发现生成了dubbo-admin-2.5.10.war。

进入/Users/xxx/Downloads/dubbo-2.5.x/dubbo-simple/dubbo-monitor-simple/target目录,会发现生成了dubbo-monitor-simple-2.5.10-assembly.tar.gz。

管理控制台的搭建

开源的Dubbo的服务管理控制台是阿里巴巴内部裁剪版本,开源部分主要包含:路由规则/动态配置/服务降级/访问控制/权重调整/负载均衡等管理功能。

接着上面的操作,进入/Users/xxx/Downloads/dubbo-2.5.x/dubbo-admin/target目录,会发现生成了dubbo-admin-2.5.10.war。

 

然后解压拷贝dubbo-admin-2.5.10.war后拷贝到一个Servlet容器,本文使用Tomcat容器,可以在Tomcat 官网下载Tomcat的二进制包,然后拷贝dubbo-admin-2.5.10到apache-tomcat-7.0.10/webapps 目录下:

然后进入 dubbo-admin-2.5.10/WEB-INF目录修改dubbo.properties文件:

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

这里的dubbo.registry.address为Zookeeper的地址。

最后在 apache-tomcat-7.0.10/bin 下执行 sh catalina.sh run 启动Tomcat。

启动后访问 http://127.0.0.1:8080/dubbo-admin-2.5.10/ 会出现下面界面:

用户名和密码都输入root后,单机登陆,进入下面界面:

至此说明管理控制台搭建完毕了。

现在你就可以使用管理控制台管理和查看服务信息了。

比如你可以搜索一个服务:dubbo/com.test.UserServiceBo:1.0.0。

单机搜索后页面跳转到:

比如你可以查看服务提供者:

比如比可以查看服务消费者:

比如你可以查看当前都有哪些应用:

注:管理控制台不是使用Dubbo搭建分布式系统必须的,但是有了它我们可以对服务进行很好的治理和监控。

监控平台搭建

Dubbo-Monitor主要用来统计服务的调用次数和调用时间,服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心,监控中心则使用数据绘制图表来显示。

服务消费方和提供方需要显示开启Monitor。

如果使用Spring配置的服务消费方和提供方,则需要在对应xml添加下面配置:

<dubbo:monitor protocol="registry"/>

其中protocol为“registry”,表示服务提供方和消费方从服务注册中心发现监控中心(Monitor)地址。

如果使用的Dubbo API方式需要首先创建一个MonitorConfig对象。

MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setProtocol("registry");

然后调用 reference.setMonitor(monitorConfig);设置到消费配置对象里面。

进入 /Users/zhuizhumengxiang/Downloads/dubbo-2.5.x/dubbo-simple/dubbo-monitor-simple/target 目录,会发现生成了 dubbo-monitor-simple-2.5.10-assembly.tar.gz:

'

解压 dubbo-monitor-simple-2.5.10-assembly.tar.gz,进入 dubbo-monitor-simple-2.5.10/conf/ 目录修改dubbo.properties:

dubbo.container=log4j,spring,registry,jetty
dubbo.application.name=simple-monitor
dubbo.application.owner=jiaduo
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.port=7070
dubbo.jetty.port=8081
dubbo.jetty.directory=/Users/zhuizhumengxiang/Downloads/dubbo-2.5.x/dubbo-simple/dubbo-monitor-simple/target/dubbo-monitor-simple-2.5.10/monitor
dubbo.charts.directory=/Users/zhuizhumengxiang/Downloads/dubbo-2.5.x/dubbo-simple/dubbo-monitor-simple/target/dubbo-moniotr-simple-2.5.10/charts
dubbo.statistics.directory=/Users/zhuizhumengxiang/Downloads/dubbo-2.5.x/dubbo-simple/dubbo-monitor-simple/target/dubbo-monitor-simple-2.5.10/monitor/statistics
dubbo.log4j.file=logs/dubbo-monitor-simple.log
dubbo.log4j.level=WARN

其中 dubbo.registry.address=zookeeper://127.0.0.1:2181 设置注册中心地址,这里设置为Zookeeper的地址。

dubbo.protocol.port=7070,是Monitor提供的远程服务监听端口,服务提供者和消费者会调用这个端口提供的服务,发送统计信息到Monitor。

dubbo.charts.directory和dubbo.statistics.directory为Monitor本地存放的监控数据文件的位置。

dubbo.jetty.port=8081,设置Jetty容器的监听地址,类似于Tomcat的8080端口,这里设置为8081。

然后进入dubbo-monitor-simple-2.5.10/bin,执行 sh start.sh 启动Monitor:

至此Monitor启动了,访问 http://127.0.0.1:8081/ 会出现下面界面:

然后我们就可以使用监控平台做一些事情了。

比如服务查看:

比如应用程序查看:

比如调用情况统计:

注:Dubbo-Monitor也不是使用Dubbo搭建分布式系统必须的组件,但是它用来统计服务的调用次数和调用时间的控制中心,这些数据有助于系统运维和调优。

posted @ 2018-05-01 11:12  徐浩进  阅读(19009)  评论(2编辑  收藏  举报