redis:Unable to connect to xxx.xx.xx.xx:6379

文章讲述了在项目中配置Redis时遇到的连接错误,提供了从检查防火墙端口开放、修改Redis配置、确认服务状态及检查项目配置文件等步骤来解决问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中配置了 redis,启动项目报错:Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.17.128:6379

从以下几个方面入手,查找问题:

1、防火墙没有开放端口

        执行 firewall-cmd --list-port 命令,查看服务器防火墙开放端口列表。如果没有redis端口,那么依次执行下面的添加防火墙开放端口和重新加载防火墙命令(以redis默认端口6379为例)。

# 查询防火墙开放端口列表
firewall-cmd --list-port

# 添加防火墙开放端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent

# 重新加载防火墙
firewall-cmd --reload

# 查询防火墙开放端口列表
firewall-cmd --list-port

2、修改 redis 配置文件

首先编辑 redis 配置:/usr/local/redis/etc/redis.conf

  • protected-mode yes 改为 protected-mode no
  • bin 127.0.0.1 改为 bin 0.0.0.0
  • timeout 改为大于0

修改配置文件保存后需要重启redis:

        如果是用apt-get或者yum install安装的redis,可以直接通过下面的命令停止/启动/重启redis:

                /etc/init.d/redis-server stop

                /etc/init.d/redis-server start

        如果是根据压缩包安装:

                1. redis 关闭

                        无密码:redis-cli -h 127.0.0.1 -p 6379 shutdown

                        有密码:redis-cli -h 127.0.0.1 -p 6379 -a password shutdown

                2. redis 启动

                        注意,需要进入到 /usr/local/redis/bin 文件夹执行下面的命令。

                        ./redis-server …/redis.conf

3、查看是否启动了 redis 服务

        执行查询 redis 进程命令,出现下面的 redis-server 0.0.0.0:6379 代表成功执行

# 查询 redis 进程
ps -ef | grep redis

root    xxxx    x    x    xxxx    xxxx    redis-server 0.0.0.0:6379

4、项目中 redis 配置文件

        一般是在 application.yml 这种配置文件中配置 redis 服务,保证 redis 配置的信息 host、port、password 没有问题。

        spring.redis.timeout 连接超时时间(毫秒)中不能设置为 0,一般设置 5000 。

"Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.5.103:6379" 这个错误提示表明无法连接到Redis数据库。具体的异常信息是 io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.5.103:6379。这可能是由于以下几个原因导致的: 1. Redis服务器未运行或未正常启动。请确保Redis服务器已经正确安装并正在运行,并且已经启动在指定的地址和端口上(192.168.5.103:6379)。 2. 网络连接问题。可能是由于网络故障或防火墙配置问题导致无法连接到Redis服务器,请检查网络连接是否正常,并确保防火墙允许与Redis服务器的通信。 3. Redis服务器配置问题。可能是由于Redis服务器的配置错误导致连接失败,请检查Redis服务器的配置文件,并确保地址和端口配置正确。 如果以上方法仍然无法解决问题,您可以尝试使用telnet命令或其他Redis客户端工具连接到Redis服务器,以进一步诊断连接问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [redis无法连接](https://blog.csdn.net/weixin_52238787/article/details/125294352)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [记录服务器上,不定时出现io.lettuce.core.RedisCommandTimeoutException: Command timed out after xxx ...](https://blog.csdn.net/jllion/article/details/124405570)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值