(3)Dubbo启动时qos-server can not bind localhost:22222错误解决 【注意:我本地测试时发现在xml中配置无效,在消费者端添加dubbo.properties文件的方式有效】 转: (3)Dubbo启动时qos-server can not bind localhost:22222错误解决
转:
(3)Dubbo启动时qos-server can not bind localhost:22222错误解决
没头脑遇到不高兴 2018-11-26 00:22:07 24602 收藏 15
展开
本节介绍
上一节中consumer启动时报了"Fail to start qos server"、"qos-server can not bind localhost:22222" 的异常,这节将会解释一下为什么会出现这个错误,怎么去解决它,还有qos中的一些Dubbo 内建的telnet命令的使用方法。
启动的错误
上一节Dubbo入门案例中,consumer工程启动时的报错信息如下:
2018-11-25 22:10:32,642 main [server.Server] 102 [ERROR] [DUBBO] qos-server can not bind localhost:22222, dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:498)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1271)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:413)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:399)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:349)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:748)
2018-11-25 22:10:32,650 main [protocol.QosProtocolWrapper] 101 [WARN ] [DUBBO] Fail to start qos server: , dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:498)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1271)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:413)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:399)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:349)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:748)
最关键的就是这两句:
[DUBBO] qos-server can not bind localhost:22222, dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
[DUBBO] Fail to start qos server: , dubbo version: 2.6.4, current host: 169.254.68.252
java.net.BindException: Address already in use: bind
什么是QoS
Qos=Quality of Service,qos是Dubbo的在线运维命令,可以对服务进行动态的配置、控制及查询,Dubboo2.5.8新版本重构了telnet(telnet是从Dubbo2.0.5开始支持的)模块,提供了新的telnet命令支持,新版本的telnet端口与dubbo协议的端口是不同的端口,默认为22222,可以通过配置文件dubbo.properties修改。telnet 模块现在同时支持 http 协议和 telnet 协议,方便各种情况的使用。
QoS提供了一些启动参数,来对启动进行配置,他们主要包括:
参数 说明 默认值
qosEnable 是否启动QoS true
qosPort 启动QoS绑定的端口 22222
qosAcceptForeignIp 是否允许远程访问 false
注意,从2.6.4/2.7.0开始,qosAcceptForeignIp默认配置改为false(拒绝远端主机发出的命令,只允许服务本机执行),如果qosAcceptForeignIp设置为true,有可能带来安全风险,请仔细评估后再打开。
QoS参数可以通过如下方式进行配置
JVM系统属性
dubbo.properties
XML方式
Spring-boot自动装配方式
其中,上述方式的优先顺序为JVM系统属性 > dubbo.properties > XML/Spring-boot自动装配方式。
使用系统属性方式进行配置
-Ddubbo.application.qos.enable=true
-Ddubbo.application.qos.port=33333
-Ddubbo.application.qos.accept.foreign.ip=false
使用dubbo.properties文件进行配置
在项目的src/main/resources目录下添加dubbo.properties文件,内容如下:
dubbo.application.qos.enable=true
dubbo.application.qos.port=33333
dubbo.application.qos.accept.foreign.ip=false
使用XML方法进行配置
如果要通过XML配置响应的QoS相关的参数,可以进行如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="demo-provider">
<dubbo:parameter key="qos.enable" value="true"/>
<dubbo:parameter key="qos.accept.foreign.ip" value="false"/>
<dubbo:parameter key="qos.port" value="33333"/>
</dubbo:application>
<dubbo:registry address="multicast://224.5.6.7:1234"/>
<dubbo:protocol name="dubbo" port="20880"/>
<dubbo:service interface="org.apache.dubbo.demo.provider.DemoService" ref="demoService"/>
<bean ,说明不允许远程连接。
然后我们修改simple-provider.xml中 qos.accept.foreign.ip 的值为 true ,再次尝试访问provider。
[root@wkp5 ~]# telnet 192.168.74.1 22222
Trying 192.168.74.1...
Connected to 192.168.74.1.
Escape character is '^]'.
___ __ __ ___ ___ ____
/ _ / / / // _ ) / _ ) / __
/ // // /_/ // _ |/ _ |/ /_/ /
/____/ \____//____//____/ \____/
dubbo>help
+---------+----------------------------------------------------------------------------------+
| help | help command |
+---------+----------------------------------------------------------------------------------+
| ls | ls service |
+---------+----------------------------------------------------------------------------------+
| offline | offline dubbo |
+---------+----------------------------------------------------------------------------------+
| online | online dubbo |
+---------+----------------------------------------------------------------------------------+
| quit | quit telnet console |
+---------+----------------------------------------------------------------------------------+
dubbo>help online
+--------------+----------------------------------------------------------------------------------+
| COMMAND NAME | online |
+--------------+----------------------------------------------------------------------------------+
| EXAMPLE | online dubbo |
| | online xx.xx.xxx.service |
+--------------+----------------------------------------------------------------------------------+
dubbo>help offline
+--------------+----------------------------------------------------------------------------------+
| COMMAND NAME | offline |
+--------------+----------------------------------------------------------------------------------+
| EXAMPLE | offline dubbo |
| | offline xx.xx.xxx.service |
+--------------+----------------------------------------------------------------------------------+
dubbo>ls
As Provider side:
+------------------------------------+---+
| Provider Service Name |PUB|
+------------------------------------+---+
|com.wkp.service.simple.SimpleService| Y |
+------------------------------------+---+
As Consumer side:
+---------------------+---+
|Consumer Service Name|NUM|
+---------------------+---+
dubbo>offline
OK
dubbo>ls
As Provider side:
+------------------------------------+---+
| Provider Service Name |PUB|
+------------------------------------+---+
|com.wkp.service.simple.SimpleService| N |
+------------------------------------+---+
As Consumer side:
+---------------------+---+
|Consumer Service Name|NUM|
+---------------------+---+
dubbo>online
OK
dubbo>ls
As Provider side:
+------------------------------------+---+
| Provider Service Name |PUB|
+------------------------------------+---+
|com.wkp.service.simple.SimpleService| Y |
+------------------------------------+---+
As Consumer side:
+---------------------+---+
|Consumer Service Name|NUM|
+---------------------+---+
dubbo>quit
BYE!
Connection closed by foreign host.
[root@wkp5 ~]#
上面我们演示了五个命令:help,ls,online,offline,quit。
help 列出所有命令, help online:列出某个命令的使用方法
quit 退出命令
ls 列出消费者和提供者列表
online 上线服务命令
当使用延迟发布功能的时候(通过设置 com.alibaba.dubbo.config.AbstractServiceConfig#register 为 false),后续需要上线的时候,可通过 Online 命令
//上线所有服务
dubbo>online
OK
//根据正则,上线部分服务
dubbo>online com.*
OK
常见使用场景:
当线上的 QPS 比较高的时候,当刚重启机器的时候,由于没有进行JIT 预热或相关资源没有预热,可能会导致大量超时,这个时候,可通过分批发布服务,逐渐加大流量
当由于某台机器由于某种原因,需要下线服务,然后又需要重新上线服务
offline下线服务
由于故障等原因,需要临时下线服务保持现场,可以使用 Offline 下线命令。
//下线所有服务
dubbo>offline
OK
//根据正则,下线部分服务
dubbo>offline com.*
OK
————————————————
版权声明:本文为****博主「没头脑遇到不高兴」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.****.net/u012988901/article/details/84503672