win10连接ubuntu1804上的redis报驱动器错误

时间:2024-04-02 19:02:52

win10连接ubuntu1804上的redis报驱动器错误
win10连接ubuntu1804上的redis报驱动器错误
原来的问题是WIN10不能连接虚拟机上的redis。关闭ubuntu的防火墙后,连上了。
$sudo ufw status
$sudu ufw disable
这里我先是下载了redis的WIN版,Redis-x64-3.2.100,进目录后执行D:\Redis-x64-3.2.100>redis-cli.exe -h 192.168.1.110 -p 6379
这个一直连不上。
win10连接ubuntu1804上的redis报驱动器错误
发现是redis配置文件中只bind 127.0.0.1,这样只能在虚拟机中访问。于是一开始将bind 127.0.0.1给注掉
win10连接ubuntu1804上的redis报驱动器错误
注掉后,WIN10可以连上,但是查看时就报:Error: 在驱动器 %1 上插入软盘。
win10连接ubuntu1804上的redis报驱动器错误
用JAVA写一个连接测试的程序:
package com.redis.test;

import redis.clients.jedis.Jedis;

/**

  • 2020年2月27日 下午4:52:03
    */
    public class TestPing {

    public static void main(String[] args) {
    Jedis jedis=new Jedis(“192.168.1.110”,6379);
    System.out.println(jedis.ping());
    }

}

运行后报错:
Exception in thread “main” redis.clients.jedis.exceptions.JedisDataException:
DENIED Redis is running in protected mode because protected mode is enabled,
no bind address was specified, no authentication password is requested to clients.
In this mode connections are only accepted from the loopback interface.
If you want to connect from external computers to Redis you may adopt one of the following solutions:

  1. Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface
    by connecting to Redis from the same host the server is running,
    however MAKE SURE Redis is not publicly accessible from internet if you do so.
    Use CONFIG REWRITE to make this change permanent.
  2. Alternatively you can just disable the protected mode by editing the Redis configuration file,
    and setting the protected mode option to ‘no’, and then restarting the server.
  3. If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option.
  4. Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
    at redis.clients.jedis.Protocol.processError(Protocol.java:132)
    at redis.clients.jedis.Protocol.process(Protocol.java:166)
    at redis.clients.jedis.Protocol.read(Protocol.java:220)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:318)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:236)
    at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:189)
    at com.ccb.redis.test.TestPing.main(TestPing.java:16)

看报错信息,可以知道如果redis没有bind任何地址的话,redis会运行在保护模式。
增加 bind ubuntu地址后,win10就可以正常查询redis了
win10连接ubuntu1804上的redis报驱动器错误
win10连接ubuntu1804上的redis报驱动器错误