最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決Springboot集成Redis集群配置公網(wǎng)IP連接報(bào)私網(wǎng)IP連接失敗問題

 更新時(shí)間:2023年10月11日 09:27:21   作者:冰夜翎  
在Springboot 集成 Redis集群配置公網(wǎng)IP連接報(bào)私網(wǎng)IP連接失敗,一直報(bào)私有IP連接失敗,所以本文小編給大家介紹了如何解決報(bào)錯(cuò)問題,如果有遇到相同問題的同學(xué),可以參考閱讀本文

1、問題:

在Springboot 集成 Redis集群配置公網(wǎng)IP連接報(bào)私網(wǎng)IP連接失敗,一直報(bào)私有IP連接失敗

14 14:57:49.180  WARN 22012 --- [ioEventLoop-6-4] i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to [192.168.0.19:6384]: connection timed out: /192.168.0.19:6384
2020-08-14 14:57:49.180  WARN 22012 --- [ioEventLoop-6-3] i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to [192.168.0.19:6383]: connection timed out: /192.168.0.19:6383
2020-08-14 14:57:49.182  WARN 22012 --- [ioEventLoop-6-2] i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to [192.168.0.19:6382]: connection timed out: /192.168.0.19:6382
2020-08-14 14:57:49.182  WARN 22012 --- [ioEventLoop-6-1] i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to [192.168.0.19:6381]: connection timed out: /192.168.0.19:6381
2020-08-14 14:57:49.190  WARN 22012 --- [ioEventLoop-6-1] i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to [192.168.0.19:6385]: connection timed out: /192.168.0.19:6385
2020-08-14 14:57:49.191  WARN 22012 --- [ioEventLoop-6-2] i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to [192.168.0.19:6386]: connection timed out: /192.168.0.19:6386
2020-08-14 14:57:59.389  WARN 22012 --- [ioEventLoop-6-3] i.l.core.cluster.RedisClusterClient      : connection timed out: /192.168.0.19:6382
2020-08-14 14:58:09.391  WARN 22012 --- [ioEventLoop-6-4] i.l.core.cluster.RedisClusterClient      : connection timed out: /192.168.0.19:6381
2020-08-14 14:58:19.393  WARN 22012 --- [ioEventLoop-6-1] i.l.core.cluster.RedisClusterClient      : connection timed out: /192.168.0.19:6383
2020-08-14 14:58:29.396  WARN 22012 --- [ioEventLoop-6-2] i.l.core.cluster.RedisClusterClient      : connection timed out: /192.168.0.19:6384
2020-08-14 14:58:39.399  WARN 22012 --- [ioEventLoop-6-3] i.l.core.cluster.RedisClusterClient      : connection timed out: /192.168.0.19:6386
2020-08-14 14:58:49.402  WARN 22012 --- [ioEventLoop-6-4] i.l.core.cluster.RedisClusterClient      : connection timed out: /192.168.0.19:6385

2、配置文件

創(chuàng)建6個(gè)配置文件:redis-6381.conf,redis-6382.conf,redis-6383.conf,redis-6384.conf,redis-6385.conf,
redis-6386.conf。配置文件內(nèi)容如下:

# 配置文件進(jìn)行了精簡(jiǎn),完整配置可自行和官方提供的完整conf文件進(jìn)行對(duì)照。端口號(hào)自行對(duì)應(yīng)修改
#默認(rèn)是 protected-mode yes,即開啟保護(hù)模式, no=關(guān)閉
#在redis的配置文件中會(huì)遇到protected-mode,它直譯為保護(hù)模式。
#如果設(shè)置為yes,那么只允許我們?cè)诒緳C(jī)的回環(huán)連接,其他機(jī)器無(wú)法連接。
#線上Redis服務(wù),為了安全,我們建議將protected-mode設(shè)置為yes。
#protected-mode設(shè)置為yes的情況下,為了我們的應(yīng)用服務(wù)可以正常訪問Redis,我們需要設(shè)置Redis的bind參數(shù)或者密碼參數(shù)#requirepass。
protected-mode yes
#端口號(hào)
port 6381
# IP綁定,redis不建議對(duì)公網(wǎng)開放,這里綁定了服務(wù)器私網(wǎng)IP及環(huán)回地址
bind 192.168.0.19 127.0.0.1
requirepass 123456
# redis數(shù)據(jù)文件存放的目錄
dir /redis/workdata
# 日志文件
logfile "/redis/logs/cluster-node-6381.log"
# 開啟AOF
appendonly yes
#后臺(tái)啟動(dòng)
daemonize yes 
 # 開啟集群
cluster-enabled yes
# 集群持久化配置文件,內(nèi)容包含其它節(jié)點(diǎn)的狀態(tài),持久化變量等,會(huì)自動(dòng)生成在上面配置的dir目錄下
cluster-config-file cluster-node-6381.conf
# 集群節(jié)點(diǎn)不可用的最大時(shí)間(毫秒),如果主節(jié)點(diǎn)在指定時(shí)間內(nèi)不可達(dá),那么會(huì)進(jìn)行故障轉(zhuǎn)移
cluster-node-timeout 5000

3、springboot集成redis集群有以下配置,二選一:

1:代碼配置

@Configuration
public class RedisClusterConfig {
  @Bean
  public RedisConnectionFactory redisConnectionFactory() {
    // 客戶端讀寫分離配置
    LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
            .readFrom(ReadFrom.REPLICA_PREFERRED)
            .build();
    RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(Arrays.asList(
            "42.192.119.238:6381",
            "42.192.119.238:6382",
            "42.192.119.238:6383",
            "42.192.119.238:6384",
            "42.192.119.238:6385",
            "42.192.119.238:6386"));
    return new LettuceConnectionFactory(redisClusterConfiguration, clientConfig);
  }
}

2:yml 配置

#集群模式
spring:
  redis:
    cluster:
      max-redirects: 3
      nodes:
        - 42.192.119.238:6381
        - 42.192.119.238:6382
        - 42.192.119.238:6383
        - 42.192.119.238:6384
        - 42.192.119.238:6385
        - 42.192.119.238:6386
    database: 0
#    host: 42.192.119.238
#    port: 6380
    password: 
    timeout: 5000s #連接超時(shí)時(shí)長(zhǎng)
    # 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)
    jedis:
      pool:
        max-active: 8 #連接池最大連接數(shù)量,負(fù)數(shù)表示無(wú)限,默認(rèn)為8
        max-idle: 8 #連接池最大空閑數(shù)量,默認(rèn)8
        min-idle: 0 #連接池最小空閑數(shù)量,默認(rèn)0

4、解決鏈接報(bào)錯(cuò)問題

讓Redis暴露公網(wǎng)IP其實(shí)在redis.conf配置文件里是能找到的,這里我們可以手動(dòng)指定Redis的公網(wǎng)IP、端口以及總線端口(默認(rèn)服務(wù)端口加10000)。

手動(dòng)指定了公網(wǎng)ip后,Redis集群中的節(jié)點(diǎn)會(huì)通過(guò)公網(wǎng)IP進(jìn)行通信,也就是外網(wǎng)訪問。因此相關(guān)的總線端口,如下面的16381等總線端口必須在云服務(wù)器中的安全組中放開

# 配置文件進(jìn)行了精簡(jiǎn),完整配置可自行和官方提供的完整conf文件進(jìn)行對(duì)照。端口號(hào)自行對(duì)應(yīng)修改
#默認(rèn)是 protected-mode yes,即開啟保護(hù)模式, no=關(guān)閉
#在redis的配置文件中會(huì)遇到protected-mode,它直譯為保護(hù)模式。
#如果設(shè)置為yes,那么只允許我們?cè)诒緳C(jī)的回環(huán)連接,其他機(jī)器無(wú)法連接。
#線上Redis服務(wù),為了安全,我們建議將protected-mode設(shè)置為yes。
#protected-mode設(shè)置為yes的情況下,為了我們的應(yīng)用服務(wù)可以正常訪問Redis,我們需要設(shè)置Redis的bind參數(shù)或者密碼參數(shù)#requirepass。
protected-mode yes
#端口號(hào)
port 6381
# IP綁定,redis不建議對(duì)公網(wǎng)開放,這里綁定了服務(wù)器私網(wǎng)IP及環(huán)回地址
bind 192.168.0.19 127.0.0.1
requirepass 123456
# redis數(shù)據(jù)文件存放的目錄
dir /redis/workdata
# 日志文件
logfile "/redis/logs/cluster-node-6381.log"
# 開啟AOF
appendonly yes
#后臺(tái)啟動(dòng)
daemonize yes 
 # 開啟集群
cluster-enabled yes
# 集群持久化配置文件,內(nèi)容包含其它節(jié)點(diǎn)的狀態(tài),持久化變量等,會(huì)自動(dòng)生成在上面配置的dir目錄下
cluster-config-file cluster-node-6381.conf
# 集群節(jié)點(diǎn)不可用的最大時(shí)間(毫秒),如果主節(jié)點(diǎn)在指定時(shí)間內(nèi)不可達(dá),那么會(huì)進(jìn)行故障轉(zhuǎn)移
cluster-node-timeout 5000
# 云服務(wù)器上部署需指定公網(wǎng)ip
cluster-announce-ip 42.192.119.238
# Redis總線端口,用于與其它節(jié)點(diǎn)通信
cluster-announce-bus-port 16381

根據(jù)以上配置修改每一個(gè)redis節(jié)點(diǎn)的配置,注意端口不能相同

在src 目錄下執(zhí)行命令:

./redis-cli -c -p 6381 -h 192.168.0.19 -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
6297ab04ff4bbfcad778b80315619defc2f6e513 42.192.119.238:6382@16382 master - 0 1696924087000 2 connected 5461-10922
19d3955d4bacd04892c13e7a05e13c7744085896 42.192.119.238:6381@16381 myself,master - 0 1696924087000 1 connected 0-5460
3a21d6c05255229741593340a781affbdcad6236 42.192.119.238:6385@16385 slave df0858e942b03f5b3c848d1acb2a4fde1f70e290 0 1696924088000 3 connected
546c8528a07abee29a1e383a3130d4f306447f0e 42.192.119.238:6386@16386 slave 19d3955d4bacd04892c13e7a05e13c7744085896 0 1696924086000 1 connected
56b730c5631515b2359bbf9b6d4306460da8502c 42.192.119.238:6384@16384 slave 6297ab04ff4bbfcad778b80315619defc2f6e513 0 1696924088460 2 connected
df0858e942b03f5b3c848d1acb2a4fde1f70e290 42.192.119.238:6383@16383 master - 0 1696924089469 3 connected 10923-16383

可以發(fā)現(xiàn),各節(jié)點(diǎn)暴露的IP全是公網(wǎng)IP了。

5、故障轉(zhuǎn)移期間Lettuce客戶端連接問題

解決方式:

1、yml指定使用jedis

2、代碼配置

1)、更換Redis客戶端

@Configuration
public class RedisClusterConfig {
  @Bean
  public RedisConnectionFactory redisConnectionFactory() {
    RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(Arrays.asList(
           "42.192.119.238:6381",
            "42.192.119.238:6382",
            "42.192.119.238:6383",
            "42.192.119.238:6384",
            "42.192.119.238:6385",
            "42.192.119.238:6386"));
    return new JedisConnectionFactory(redisClusterConfiguration);
  }
}

參考鏈接:

https://github.com/lettuce-io/lettuce-core/wiki/Redis-Cluster

https://github.com/lettuce-io/lettuce-core/wiki/Client-options#cluster-specific-options

2)、更改實(shí)現(xiàn)配置

@Configuration
public class RedisClusterConfig {
  @Bean
  public RedisConnectionFactory redisConnectionFactory() {
    // 開啟自適應(yīng)集群拓?fù)渌⑿潞椭芷谕負(fù)渌⑿?,不開啟相應(yīng)槽位主節(jié)點(diǎn)掛掉會(huì)出現(xiàn)服務(wù)不可用,直到掛掉節(jié)點(diǎn)重新恢復(fù)
    ClusterTopologyRefreshOptions clusterTopologyRefreshOptions =  ClusterTopologyRefreshOptions.builder()
            .enableAllAdaptiveRefreshTriggers() // 開啟自適應(yīng)刷新,自適應(yīng)刷新不開啟,Redis集群變更時(shí)將會(huì)導(dǎo)致連接異常
            .adaptiveRefreshTriggersTimeout(Duration.ofSeconds(30)) //自適應(yīng)刷新超時(shí)時(shí)間(默認(rèn)30秒),默認(rèn)關(guān)閉開啟后時(shí)間為30秒
            .enablePeriodicRefresh(Duration.ofSeconds(20))  // 默認(rèn)關(guān)閉開啟后時(shí)間為60秒 
            .build();
    ClientOptions clientOptions = ClusterClientOptions.builder()
            .topologyRefreshOptions(clusterTopologyRefreshOptions)
            .build();
    // 客戶端讀寫分離配置
    LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
            .clientOptions(clientOptions)
            .build();
    RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(Arrays.asList(
           "42.192.119.238:6381",
            "42.192.119.238:6382",
            "42.192.119.238:6383",
            "42.192.119.238:6384",
            "42.192.119.238:6385",
            "42.192.119.238:6386"));
    return new LettuceConnectionFactory(redisClusterConfiguration, clientConfig);
  }
}

以上就是解決Springboot集成Redis集群配置公網(wǎng)IP連接報(bào)私網(wǎng)IP連接失敗問題的詳細(xì)內(nèi)容,更多關(guān)于Springboot私網(wǎng)IP連接失敗的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java中Easyexcel?實(shí)現(xiàn)批量插入圖片功能

    Java中Easyexcel?實(shí)現(xiàn)批量插入圖片功能

    這篇文章主要介紹了Easyexcel?實(shí)現(xiàn)批量插入圖片,本文通過(guò)實(shí)例代碼給大家介紹了easyexcel文檔處理工具、自定義圖片處理器的相關(guān)知識(shí),需要的朋友可以參考下
    2022-04-04
  • SpringBoot @ComponentScan掃描的局限性方式

    SpringBoot @ComponentScan掃描的局限性方式

    文章總結(jié):SpringBoot的@ComponentScan注解在掃描組件時(shí)存在局限性,只能掃描指定的包及其子包,無(wú)法掃描@SpringBootApplication注解自動(dòng)配置的組件,使用@SpringBootApplication注解可以解決這一問題,它集成了@Configuration、@EnableAutoConfiguration
    2025-01-01
  • 深入理解java final不可變性

    深入理解java final不可變性

    本文主要介紹了講講java final不可變性,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • SpringBoot整合Freemarker的基本步驟

    SpringBoot整合Freemarker的基本步驟

    這篇文章主要介紹了SpringBoot整合Freemarker的基本步驟,添加依賴及添加相關(guān)配置的實(shí)例代碼詳解,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • java 實(shí)現(xiàn)Comparable接口排序,升序、降序、倒敘

    java 實(shí)現(xiàn)Comparable接口排序,升序、降序、倒敘

    這篇文章主要介紹了java 實(shí)現(xiàn)Comparable接口排序,升序、降序、倒敘,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • SpringBoot基于Sentinel在服務(wù)上實(shí)現(xiàn)接口限流

    SpringBoot基于Sentinel在服務(wù)上實(shí)現(xiàn)接口限流

    這篇文章主要介紹了SpringBoot基于Sentinel在服務(wù)上實(shí)現(xiàn)接口限流,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Spring Batch批處理框架使用解析

    Spring Batch批處理框架使用解析

    這篇文章主要介紹了Spring Batch批處理框架使用解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • SpringBoot中的Bean的初始化與銷毀順序解析

    SpringBoot中的Bean的初始化與銷毀順序解析

    這篇文章主要介紹了SpringBoot中的Bean的初始化與銷毀順序,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java實(shí)現(xiàn)寵物商店管理

    Java實(shí)現(xiàn)寵物商店管理

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)寵物商店管理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Java GZIPOutputStream流壓縮文件的操作

    Java GZIPOutputStream流壓縮文件的操作

    這篇文章主要介紹了Java GZIPOutputStream流壓縮文件的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-02-02

最新評(píng)論

东宁县| 论坛| 吉木乃县| 凉山| 永仁县| 吴堡县| 南召县| 肇源县| 确山县| 九寨沟县| 隆尧县| 平凉市| 东乡县| 京山县| 仲巴县| 汤原县| 全椒县| 永川市| 宣城市| 广水市| 永登县| 东城区| 青河县| 武邑县| 克山县| 丰宁| 余庆县| 高要市| 通化县| 昌黎县| 鄂托克旗| 龙泉市| 柳河县| 北川| 恩施市| 廊坊市| 兴仁县| 崇义县| 兴文县| 南康市| 长顺县|