Jedis远程连接redis-server出现错误解决方法

本文介绍了在使用Jedis连接Redis时遇到的连接失败问题,分析了Redis配置文件中`bind`和`protected-mode`选项的影响。通过配置`bind`指定允许连接的IP地址和调整`protected-mode`来允许远程访问,同时提到了防火墙和安全组规则对端口开放的重要性。在完成配置并重启Redis后,成功实现了远程连接。

今天用jedis远程连接redis的时候报错:

redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host xxx.xxx.xxx.xxx:6379

连接失败,网上查到和配置文件里的某个配置有关系,所以打算去官网查看一下配置文件的官方文档

Redis is able to start without a configuration file using a built-in default configuration, however this setup is only recommended for testing and development purposes.

The proper way to configure Redis is by providing a Redis configuration file, usually called redis.conf.

The redis.conf file contains a number of directives that have a very simple format:

​ 刚开始先告诉我们,你启动redis不用配置文件也行,因为有一些自带的默认配置,但是这种方式呢仅推荐用于测试和开发。

​ 正确的方式是用配置文件redis.conf来启动redis 并给出了一些示例。

​ 我们直接在下面找到对应版本的redis配置文件,我的是5.0版本的,里面的说的非常详细,我选出了两个我们要用的参数。

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
默认情况下,如果不特别指定bid配置命令,redis会监听我网络上可以到达服务器的所有连接
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
 可以用bind配置命令跟上IP地址来选择监听一个或者多个接口
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# 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 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
如果redis直接暴露在网络上
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值