文章插图
sentinel配置文件
5、启动3台sentinel命令:
sentinel1
先:sudo docker run -it --name sentinel-26379 --net=host -v $PWD/sentinel-26379.conf:/usr/local/etc/redis/sentinel.conf -d redis:3.2 /bin/bash 再:sudo docker exec -it sentinel-26379 /bin/bash最后在容器里设置激活哨兵模式:redis-sentinel /usr/local/etc/redis/sentinel.conf sentinel2
先:sudo docker run -it --name sentinel-26380 --net=host -v $PWD/sentinel-26380.conf:/usr/local/etc/redis/sentinel.conf -d redis:3.2 /bin/bash 再:sudo docker exec -it sentinel-26380 /bin/bash最后在容器里设置激活哨兵模式:redis-sentinel /usr/local/etc/redis/sentinel.conf sentinel3
先:sudo docker run -it --name sentinel-26381 --net=host -v $PWD/sentinel-26381.conf:/usr/local/etc/redis/sentinel.conf -d redis:3.2 /bin/bash 再:sudo docker exec -it sentinel-26381 /bin/bash最后在容器里设置激活哨兵模式:redis-sentinel /usr/local/etc/redis/sentinel.conf 6、sentenel会根据master的数据自动把其他salve和sentenel找出来写到自己的配置文件
查看配置文件cat sentinel-26379.conf

文章插图
sentinel会自动找到配置
发现配置文件多了东西 。
五、springboot配置及运行1、新建springboot项目xml为:
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.Apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.1.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.eujian</groupId><artifactId>redis</artifactId><version>0.0.1-SNAPSHOT</version><name>redis</name><description>Demo project for Spring Boot</description><properties><JAVA.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>2、配置文件配置redis的方式spring.redis.sentinel.master=mymasterspring.redis.sentinel.nodes=192.168.197.24:26379,192.168.197.24:26380,192.168.197.24:263813、创建类用于访问@RequestMApping@RestControllerpublic class Controller {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@GetMapping("getkey")public String getkey(String key){String result = stringRedisTemplate.opsForValue().get(key);return result;}@GetMapping("setkey")public void setkey(String key, String value){stringRedisTemplate.opsForValue().set(key, value);}}}4、具体的代码目录为
文章插图
springboot项目代码
六、测试及演练启动springboot项目,即可以访问:
1、设置redis值:
http://localhost:8080/setkey?key=aa&value=https://www.isolves.com/it/sjk/Redis/2021-01-05/789
2、查询redis值:
http://localhost:8080/getkey?key=aa
返回

文章插图
设置一个值入去,就可以查到 。
推荐阅读
- Mac上,Docker运行GUI应用
- 携程Redis治理演进之路
- 还不懂Docker?一个故事安排的明明白白
- 烂大街的Nginx+Redis分布式锁+MQ+MDB架构设计
- 面试必问的 Redis:RDB、AOF、混合持久化
- 漫谈Gossip协议与其在Redis Cluster中的实现
- 10分钟自建企业级Docker镜像仓库!这个开源项目太顶了
- Docker 如何运行多个 Springboot?
- 不用Docker也能构建容器的4种方法
- 推荐一款神仙颜值的 Redis 客户端工具
