java.net.SocketException: Broken pipe (Write failed)

springboot访问redis报这个错误:

org.springframework.dao.InvalidDataAccessApiUsageException: 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.; nested exception is 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 org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:64)
   at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
   at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
   at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
   at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)
   at org.springframework.data.redis.connection.jedis.JedisKeyCommands.keys(JedisKeyCommands.java:143)
   at org.springframework.data.redis.connection.DefaultedRedisConnection.keys(DefaultedRedisConnection.java:75)
   at org.springframework.data.redis.core.RedisTemplate.lambda$keys$10(RedisTemplate.java:840)
   at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
   at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
   at org.springframework.data.redis.core.RedisTemplate.keys(RedisTemplate.java:840)
   at com.boss.sysuser.bs.impl.UserRedisServiceImpl.getKeys(UserRedisServiceImpl.java:68)
   at com.boss.sysuser.bs.impl.UserRedisServiceImpl.removeByKey(UserRedisServiceImpl.java:84)
   at com.boss.sysuser.bs.impl.UserCacheService.cacheUser(UserCacheService.java:32)
   at com.boss.sysuser.listener.ApplicationContextListener.onApplicationEvent(ApplicationContextListener.java:26)
   at com.boss.sysuser.listener.ApplicationContextListener.onApplicationEvent(ApplicationContextListener.java:1)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354)
   at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:103)
   at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:78)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
   at com.boss.UserserviceApplication.main(UserserviceApplication.java:17)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
   at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: 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.getBinaryMultiBulkReply(Connection.java:276)
   at redis.clients.jedis.BinaryJedis.keys(BinaryJedis.java:357)
   at org.springframework.data.redis.connection.jedis.JedisKeyCommands.keys(JedisKeyCommands.java:141)
   ... 29 more                                                                                                            畃rex妯$虫ヨredis涓
2020-03-11 14:09:18.953  INFO [userservice,,,] 17736 --- [           main] com.boss.sysuser.bs.IUserRedisService    : 鏍规                        key,?
ュprex : userorg#
org.springframework.data.redis.RedisConnectionFailureException: java.net.SocketException: Broken pipe (Write failed); nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe (Write failed)
   at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
   at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
   at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
   at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
   at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)
   at org.springframework.data.redis.connection.jedis.JedisKeyCommands.keys(JedisKeyCommands.java:143)
   at org.springframework.data.redis.connection.DefaultedRedisConnection.keys(DefaultedRedisConnection.java:75)
   at org.springframework.data.redis.core.RedisTemplate.lambda$keys$10(RedisTemplate.java:840)
   at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
   at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
   at org.springframework.data.redis.core.RedisTemplate.keys(RedisTemplate.java:840)
   at com.boss.sysuser.bs.impl.UserRedisServiceImpl.getKeys(UserRedisServiceImpl.java:68)
   at com.boss.sysuser.bs.impl.UserRedisServiceImpl.removeByKey(UserRedisServiceImpl.java:84)
   at com.boss.sysuser.bs.impl.UserMgrBusinessImpl.initOrgCache(UserMgrBusinessImpl.java:85)
   at com.boss.sysuser.bs.impl.UserMgrBusinessImpl$$FastClassBySpringCGLIB$$7621e1f2.invoke(<generated>)
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
   at com.boss.sysuser.bs.impl.UserMgrBusinessImpl$$EnhancerBySpringCGLIB$$d05c5f2c.initOrgCache(<generated>)
   at com.boss.sysuser.listener.ApplicationContextListener.onApplicationEvent(ApplicationContextListener.java:27)
   at com.boss.sysuser.listener.ApplicationContextListener.onApplicationEvent(ApplicationContextListener.java:1)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354)
   at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:103)
   at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:78)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
   at com.boss.UserserviceApplication.main(UserserviceApplication.java:17)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
   at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe (Write failed)
   at redis.clients.jedis.Connection.flush(Connection.java:334)
   at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:274)
   at redis.clients.jedis.BinaryJedis.keys(BinaryJedis.java:357)
   at org.springframework.data.redis.connection.jedis.JedisKeyCommands.keys(JedisKeyCommands.java:141)
   ... 33 more
Caused by: java.net.SocketException: Broken pipe (Write failed)
   at java.net.SocketOutputStream.socketWrite0(Native Method)
   at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
   at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
   at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:52)
   at redis.clients.util.RedisOutputStream.flush(RedisOutputStream.java:216)
   at redis.clients.jedis.Connection.flush(Connection.java:331)
   ... 36 more

查了半天说是访问redis的参数设置问题,配置文件的 timeout 参数设置为0 同时配置testOnReturn,testWhileIdle,testOnBorrow为true  但是试了没有解决问题,其实我忽略了报错开始的信息:

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.

人家redis已经给了三个解决方法:SET protected-mode no  说的明明的,查了一下资料这个如下

Redis3.2版本后新增protected-mode配置,默认是yes,即开启。protected-mode设置为不同值时的效果如下:

protected-mode值    效果
no    关闭protected-mode模式,此时外部网络可以直接访问
yes    开启protected-mode保护模式,需配置bind ip或者设置访问密码
想要在外部访问服务器中的Redis 除了需要设置 protected-mode no ,还需将 redis.conf 文件中的bind:127.0.0.1语句注释

开发一直使用的是redis 3.0  这次服务器上用了redis 5.0.7就出现这个问题

将配置文件中protected-mode设置为no  问题解决,看来以后遇到问题要仔细看报错日志

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值