本文主要是介绍使用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
这篇关于使用Jedis连接云服务器时遇到的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!