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
·