今天在使用redis搭建缓存集群的时候,一共启动了三个redis服务,端口号分别是6379、6380、6381。在进行redis配置时,将配置文件中bind 127.0.0.1注释掉了,protected-mode设置为no,daemonize 设置为yes。
在进行jedis连接端口号6379和端口号6380的服务时,jedis报异常,异常信息如下:
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: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) at Test.Test10.main(Test10.java:37) |
出现这种错误,6380和6381的配置文件都是6379复制过来的,为啥只有6380没事,而其他两个端口出现以上错误。
jedis的代码如下:
Jedis jedis=new Jedis("192.168.80.128", 6379); jedis.set("name", "z"); jedis.close(); |