使用Jedis连接云服务器时遇到的问题

使用Jedis连接云服务器

	学习使用Jedis时,因为连接的是阿里云的服务器。然后一直连接失败。
	 Jedis jedis = new Jedis(主机地址,6379);
刚开始觉得是阿里云的安全组里面没有开启6379,于是我去打开了端口,还是报错

在这里插入图片描述
于是,我觉得可能是主机的防火墙没有开启这个端口,输入ufw status发现防火墙压根就没开。
然后打开Redis的配置文件看到protected-mode 默认是yes,改成no
在这里插入图片描述
然后把绑定端口哪里注释掉默认的 bind 127.0.0.1,他就会监听所有的可用的地址。也可以用bind绑定你要监听地址。

启动redis

redis-server config/config 

查看配置是否生效,改了配置文件需要重新启动redis

root@iZwz95hcen4u1xgrsl8iyaZ:/usr/local/bin# netstat -lnp |grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      1972/redis-server *
tcp6       0      0 :::6379                 :::*                    LISTEN      1972/redis-server *

我看到注释是这样解释的

By default, if no “bind” configuration directive is specified, Redis listens
for connections from all the network interfaces available on the server.
It is possible to listen to just one or multiple selected interfaces using
the “bind” configuration directive, followed by one or more IP addresses.

System.out.println(jedis.ping());  //输出pong

参考 https://blog.csdn.net/xc121566/article/details/96967155

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值