今天用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.conffile 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直接暴露在网络上

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





