springboot集成redis报错

5,203 阅读1分钟

错误内容:org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException:

  • 错误原因分析为redis连接问题,主要排查下面几点

    • application.properties中配置的redis的属性是否正确

      #redis配置
      spring.redis.host=192.168.20.131
      spring.redis.database=0
      spring.redis.port=6379
      spring.redis.password=
      spring.redis.jedis.pool.max-active=8
      spring.redis.jedis.pool.max-wait=-1ms
      spring.redis.jedis.pool.max-idle=8
      spring.redis.jedis.pool.min-idle=0
      spring.redis.timeout=3000ms
      
    • redis本身的配置,主要是两处:是否进行默认ip的绑定和安全模式是否开启

      # bind 127.0.0.1
      protected-mode no
      需要绑定正确的ip
      关闭安全安全模式
      
    • 检查虚拟机的火墙和端口

      1、查看firewall服务状态
      systemctl status firewalld
      出现Active: active (running)切高亮显示则表示是启动状态。
      出现 Active: inactive (dead)灰色表示停止,看单词也行。
      
      2、查询、开放、关闭端口
      # 查询redis端口是否开放
      firewall-cmd --query-port=6379/tcp
      # 开放6379端口
      firewall-cmd --permanent --add-port=6379/tcp