SpringBoot集成Redis集群


Redis6.x

SpringBoot2.x

阿里雲服務器CentOS7.X

 

redis事先安裝

配置集群 http://www.redis.cn/topics/cluster-tutorial.html

創建6個文件夾7000 - 7005

在里面新建redis.conf,並且啟動6個實例

## 端口7000 - 7005
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
## 允許遠程訪問
protected-mode  no
## 守護進程啟動
daemonize yes

 在src目錄下創建集群,IP為公網IP

./redis-cli --cluster create 120.79.176.119:7000 120.79.176.119:7001 120.79.176.119:7002 120.79.176.119:7003 120.79.176.119:7004 120.79.176.119:7005 --cluster-replicas 1

 查看進程

ps -ef | grep redis

 kill -9 這6個進程

把7000-7005里面的nodes.conf全部改成公網IP,不然會以內網IP訪問

重新啟動6個實例,啟動就行了,不需要再搭建啦

集群搭建完成

 

導入依賴

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency

 

添加配置

spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.min-idle=0
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.timeout=3000ms
spring.redis.cluster.nodes=120.79.176.119:7000,120.79.176.119:7001,120.79.176.119:7002,120.79.176.119:7003,120.79.176.119:7004,120.79.176.119:7005

 

 

 

 

 ·

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM