发布于 3年前

Dubbo启动报错:qos-server can not bind localhost:22222

在同一台服务器上启动两个dubbo服务,第二个dubbo服务报错:

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)

大概的意思是qos用的22222端口已经被占用。

QOS是什么

在解决问题前,先要理解qos是什么。

Qos(Quality of Service)是Dubbo的在线运维命令,可以对服务进行动态的配置、控制及查询,Dubboo2.5.8新版本重构了telnet(telnet是从Dubbo2.0.5开始支持的)模块,提供了新的telnet命令支持,新版本的telnet端口与dubbo协议的端口是不同的端口,默认为22222。

QoS在dubbo.properties提供了以下启动参数:

  • qosEnable:是否启动QoS,默认是true
  • qosPort:启动QoS绑定的端口,默认是22222
  • qosAcceptForeignIp:是否允许远程访问。默认false 注意:从2.6.4/2.7.0开始,qosAcceptForeignIp默认配置改为false(拒绝远端主机发出的命令,只允许服务本机执行),如果qosAcceptForeignIp设置为true,有可能带来安全风险,请仔细评估后再打开。

QOS配置修改方式

Dubbo提供了以下几种方式修改QOS的参数:

  • JVM系统属性
  • dubbo.properties
  • XML方式
  • Spring-boot自动装配方式 其中,优先顺序自上而下,JVM系统属性 > dubbo.properties > XML/Spring-boot自动装配方式。

方式一、JVM系统属性

-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

方式三、Spring Boot配置

dubbo.application.qosEnable=true
dubbo.application.qosPort=33333
dubbo.application.qosAcceptForeignIp=false

方式四、xml配置

<?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>
</beans>

QOS启动报错解决方案

理解了qos以及它的启动配置,解决上述问题就简单了。

  • 方法一:禁用qos
  • 方法二:修改qos的默认端口22222
©2020 edoou.com   京ICP备16001874号-3