ip地址正确,redis却始终连接失败

    今天测试人员测试项目的时候打开页面就一直报错,查看错误日志是Redis的连接失败的问题。但是测试发过来他在本地部署项目修改的配置IP端口都是正确的,远程也能ping通。

     之前没遇到过这种问题,后来发现他是连接的本机的redis的服务,而没有修改的Redis的默认绑定。

     Redis的默认绑定的IP为127.0.0.1,但如果想内网的机器都能访问,则需要设置内网的IP地址,如192.168.100.66,然后redis.host则可以设置为192.168.100.66访问Redis的。

          

Redis ip地址绑定默认说明:

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

# 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.
#
# 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 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

 主要是意思是,如果设置了绑定,只能通过绑定的地址访问的Redis。

如果不设置绑定,则所有地址都可以访问,如果在项目部署外网,所有人都可以访问到,所以这里也是个注意的地址,还是设置绑定比较安全。

绑定多个IP地址:

bind 127.0.0.1 192.168.100.66

 127.0.0.1和192.168.100.66之间通过空格分隔,不是逗号。

但如果Redis的是自启动的,没有加载配置文件(redis.windows.conf)启动,这里的设置也是无效的。

如果不绑定IP地址(192.168.100.66),直接设置redis.host = 192.168.100.66是访问不了的,出现以下的错误:

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

如果放开,直接注释掉bind配置,然后把protected-mode属性设置no,就可以访问了。

如果还不行,可能因为双击redis.server启动服务未加载配置文件,使用命令行启动就可以了

redis-server redis.windows.conf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值