Dubbo: 2.7.8 Redis元数据中心无法获取密码

Created on 29 Jul 2020  ·  4Comments  ·  Source: apache/dubbo

Environment

  • Dubbo version: 2.7.8
  • Java version: 1.8

项目使用的是redis元数据中心,配置了密码,发现启动的时候元数据没有上报。

经调试发现,RedisMetadataReport 构造函数里面没有解析 password , 奇怪的是 2.7.4.1 里面也有解析,是不是漏掉了?发现那2.7.7版本也没有

解决方法

在 RedisMetadataReport 构造函数加上

password = url.getParameter(PASSWORD_KEY, "");

Most helpful comment

@spilledyear
在配置 redis 作为 Dubbo 项目的元数据中心时, 我也遇到了同样的问题, 报错如下

redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.

我的项目环境是

  • SpringBoot : _2.3.1.RELEASE_
  • dubbo-spring-boot-starter : _2.7.8_
  • JDK : _1.8_

解决方法如下:

在配置文件里用下面这种格式

dubbo.metadata-report.address=redis://username:[email protected]:6379

或者

<dubbo:metadata-report address="redis://username:[email protected]:6379"/>

根据报错 debug 到 org.apache.dubbo.common.URL 这个类里

debug1

All 4 comments

It depends.
Precondition: redis-server auth enabled.

    <!-- Good -->
    <dubbo:metadata-report address="redis://username:[email protected]:6379"/>
    <!-- Bad -->
    <dubbo:metadata-report address="redis://127.0.0.1:6379" username="username" password="redis"/>

The bad one throws:

redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
    at redis.clients.jedis.Protocol.processError(Protocol.java:127)
    at redis.clients.jedis.Protocol.process(Protocol.java:161)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    at redis.clients.jedis.Jedis.set(Jedis.java:121)
        ...

It seems MetadataReportConfig#toUrl didn't set the username&password to the proper field of the url. Therefore the constructor of RedisMetadataReport gets no password with url.getPassword(), which hides in url.getParameter("password").

Replace implementation of MetadataReportConfig#toUrl with method UrlUtils.parseURL(address, map) from same situation in ConfigCenterConfig#toUrl should resolve this problem.

https://github.com/apache/dubbo/blob/043da6850b81dd03d5879b19f1c2a52b05426272/dubbo-common/src/main/java/org/apache/dubbo/config/MetadataReportConfig.java#L89-L108

https://github.com/apache/dubbo/blob/043da6850b81dd03d5879b19f1c2a52b05426272/dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java#L64-L77

I will add a redis client module to handle the interact with redis server, meanwhile solve the problem

@tswstarplanet Do you have time to work on this?

@spilledyear
在配置 redis 作为 Dubbo 项目的元数据中心时, 我也遇到了同样的问题, 报错如下

redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.

我的项目环境是

  • SpringBoot : _2.3.1.RELEASE_
  • dubbo-spring-boot-starter : _2.7.8_
  • JDK : _1.8_

解决方法如下:

在配置文件里用下面这种格式

dubbo.metadata-report.address=redis://username:[email protected]:6379

或者

<dubbo:metadata-report address="redis://username:[email protected]:6379"/>

根据报错 debug 到 org.apache.dubbo.common.URL 这个类里

debug1

Was this page helpful?
0 / 5 - 0 ratings