redis配置

今天初试了使用Java Redisson 客户端连接安装在CentOS上的Redis, 发现一直连接不了, 报错信息如下:
[html] view plain copy
Exception in thread “main” com.lambdaworks.redis.RedisException: Unable to connect
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:188)
at com.lambdaworks.redis.RedisClient.connectAsync(RedisClient.java:148)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:131)
at org.redisson.connection.ConnectionManager.connection(ConnectionManager.java:119)
at org.redisson.RedissonMap.put(RedissonMap.java:95)
at redis.RedisExample.main(RedisExample.java:25)
Caused by: java.net.ConnectException: Connection timed out: no further information: /xxx.xxx.xxx.xxx:6379
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:735)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:191)
at io.netty.channel.nio.AbstractNioChannel AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:241)atio.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:502)atio.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)atio.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)atio.netty.util.concurrent.SingleThreadEventExecutor 2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:744)

网上找了很多方法, 说关闭防火墙即可, 下面为操作防火墙的命令。
[html] view plain copy
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?
查看已启动的服务列表:systemctl list-unit-files|grep enabled
我们选择第二个, 可是怎么关闭也不好使。还是和以前一样的报错。忽然想到安装在CentOS上的redis有一个redis.conf配置文件(我是在/etc/redis文件夹下)
使用命令打开
[html] view plain copy
[root@zz /]# cd /etc/redis
[root@zz redis]# ll
总用量 48
-rw-r–r–. 1 root root 46736 3月 15 23:23 redis.conf
[root@zz redis]# vim redis.conf
进去之后直接敲 /bind 回车。这时候找到一段
[html] view plain copy

internet, binding to all the interfaces is dangerous and will expose the

instance to everybody on the internet. So by default we uncomment the

following bind directive, that will force Redis to listen only into

the IPv4 lookback interface address (this means Redis will be able to

accept connections only from clients running into the same computer it

is running).

IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES

JUST COMMENT THE FOLLOWING LINE.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bind 127.0.0.1
看最后一行, 将这个ip改成你们虚拟机的IP地址即可, 改完之后 按ESC, shift+:,wq+回车
查看虚拟机ip命令, 红色部分就是虚拟机的ip地址
[html] view plain copy
[root@zz redis]# ifconfig
ens33: flags=4163

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值