在springboot中远程连接redis遇到的问题

在Linux上成功安装redis后,如果直接运行./redis-server命令启动,则为前台启动,效果如下

在springboot中远程连接redis遇到的问题_第1张图片

如果想以后台方式启动,则需要配置文件redis.conf,将redis.conf文件(此文件在自己下载的redis压缩包中可以找到)拷贝到reids安装目录下的bin文件下(目的是方便找到这个文件,因为redis-server命令在bin目录下),修改配置文件中的daemonize为yes,运行命令./redis-server redis.conf,即可以后台方式启动

启动效果如下,关闭命令为./redis-cli shutdown

成功启动redis后,使用springboot工程连接redis,出现如下连接异常

java.net.ConnectException: Connection refused: no further information
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_191]
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_191]
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325) ~[netty-transport-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) ~[netty-transport-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:633) ~[netty-transport-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[netty-transport-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[netty-transport-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[netty-transport-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) ~[netty-common-4.1.22.Final.jar:4.1.22.Final]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.22.Final.jar:4.1.22.Final]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

需要修改配置文件redis.conf两个地方,第一将protected-mode的值改为no,第二将bind 127.0.0.1注释掉

你可能感兴趣的:(redis)