Dubbo學習筆記3:Dubbo管理控制檯與監控中心的搭建

Dubbo源碼下載與編譯git

本文來說下如何在Dubbo源碼編譯後,獲得用於搭建管理控制檯的war包和監控平臺的jar包。github

首先須要到Github上下載Dubbo的源碼,解壓後以下:web

 

在dubbo-2.5.x目錄執行 mvn clean package -Dmaven.test.skip=true 會生成以下結果:redis

[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。spring

進入/Users/xxx/Downloads/dubbo-2.5.x/dubbo-simple/dubbo-monitor-simple/target目錄,會發現生成了dubbo-monitor-simple-2.5.10-assembly.tar.gz。apache

管理控制檯的搭建api

開源的Dubbo的服務管理控制檯是阿里巴巴內部裁剪版本,開源部分主要包含:路由規則/動態配置/服務降級/訪問控制/權重調整/負載均衡等管理功能。tomcat

接着上面的操做,進入/Users/xxx/Downloads/dubbo-2.5.x/dubbo-admin/target目錄,會發現生成了dubbo-admin-2.5.10.war。app

 

而後解壓拷貝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搭建分佈式系統必須的組件,可是它用來統計服務的調用次數和調用時間的控制中心,這些數據有助於系統運維和調優。

相關文章
相關標籤/搜索