前言
本篇算是个番外篇,因为主要内容为对上篇dubbo服务搭建和部署的一个测试。可以搭建也可以不搭建。中国有句话说得好:“你看,来都来了”。你看咱dubbo搭建都搭建完了,不差这么一哆嗦。
一、下载和安装 dubbo-admin
1.1 下载
首先从github上下载dubbo的整个包,做demo时用的是2.6.0,更高版本也应该没啥问题。
image.png
1.2 安装
将 dubbo-admin 解压后,导入idea
File > Open...
然后选中 dubbo-dubbo-2.6.0 的pom.xml,这样整个 dubbo 文件就全部导入了。
image.png
我们需要修改一下dubbo-admin 的配置文件,目的是配置zookeeper的地址。
image.png
此处默认的zookeeper的地址是本机,由于之前我是直接用本机来运行的zookeeper,所以此处不需要修改。
下面是两个登录的账号:
- username: root,password: root
- username: guest,password: guest
此时我们需要安装一下,安装的目的主要是为了生成 dubbo-admin 的war 包,最终目的是为了将这个 war包通过 tomcat来启动。
可以通过 idea 的 Terminal 来执行 maven 的命令:
D:\private\dubbo-dubbo-2.6.0>mvn install -Dmaven.test.skip=true
ps:此处我们跳过 test 阶段
执行完后,war包已经打好
image.png
二、部署 dubbo-admin
2.1 进行部署
我们将 war 包放到 tomcat 中:
image.png
ps:在这里我已经成功部署过一次,所以文件夹中包含 dubbo-admin-2.6.0 的文件夹。如果之前没有部署过,是没有这个文件夹的,只有war包。
然后我们启动 tomcat
image.png
image.pngps:启动 tomcat 有多种方式,我是使用的 cmd 启动,比较麻烦,也可以直接双击 startup.bat
2.2 进入 dubbo-admin
当tomcat启动完成时,我们访问这个地址:
image.png
输入用户名和密码,进入主界面:
image.png
我们随便搜一个之前的 orderService
image.png
2.3 修改 tomcat-user.xml 文件(番外内容)
tomcat 启动后,我们可以尝试的登录一下它的管理主界面:
发现同样是需要用户名和密码
image.png
如果我们点击取消,则会出现图中 401 的响应信息。此时我们需要修改一下 tomcat-user.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary. It is
strongly recommended that you do NOT use one of the users in the commented out
section below since they are intended for use with the examples web
application.
-->
<!--
NOTE: The sample user and role entries below are intended for use with the
examples web application. They are wrapped in a comment and thus are ignored
when reading this file. If you wish to configure these users for use with the
examples web application, do not forget to remove the <!.. ..> that surrounds
them. You will also need to set the passwords to something appropriate.
-->
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
<user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
<user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager-gui,manager-script"/>
</tomcat-users>
此处配置的是响应信息中提示的一些角色,我们配置一个 admin 用户,在登录时,用户名和密码都是 admin。
image.png登录成功。当然我们也可以在主界面中进入 dubbo-admin 的页面。点击dubbo-admin的应用名就可以进入。
image.png
三、部署 dubbo-monitor
之前刚刚打包好了 dubbo 下所有的包,其中就包含 dubbo-simple。
image.png
我们把这个包解压
image.png image.png
然后打开 conf 中的 dubbo.properties 配置文件,并进行修改
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
dubbo.container=log4j,spring,registry,jetty
dubbo.application.name=simple-monitor
dubbo.application.owner=
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://127.0.0.1:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.protocol.port=7070
dubbo.jetty.port=9090
dubbo.jetty.directory=${user.home}/monitor
dubbo.charts.directory=${dubbo.jetty.directory}/charts
dubbo.statistics.directory=${user.home}/monitor/statistics
dubbo.log4j.file=logs/dubbo-monitor-simple.log
dubbo.log4j.level=WARN
目前只需要将注册地址改为我们的 zk 地址即可。还要注意启动的端口,不要跟之前的程序冲突。保存后,打开bin 目录下的 start.bat
image.png
启动成功:
image.png image.png
ps:这回不用输密码了...
其实此时监控中并没有数据,因为我们还没有把dubbo的应用加入 dubbo-monitor 中。此时我们需要在 dubbo-order 和 dubbo-user 的xml 配置文件中(此处是 dubbo-register.xml)加入一行配置:
<!-- 应用名称 -->
<dubbo:application name="dubbo-order"/>
<!-- zookeeper注册中心地址 -->
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>
<!-- 协议名称(dubbo)和dubbo端口号 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- 监控服务的注册-->
<dubbo:monitor protocol="registry"></dubbo:monitor>
<dubbo:monitor protocol="registry"></dubbo:monitor>
我们重启一下两个dubbo服务,刷新一下页面
image.png
发现simple-monitor这个服务已经有连个 consumer 了,就说明是加入成功。查看 orderService 的统计数据:
image.png
发现已经开始对dubbo请求进行监控。
网友评论