一 主從配置
1.1 master、slave
master
mkdir -p /mydata/redis/6379/conf mkdir -p /mydata/redis/6379/data touch /mydata/redis/6379/conf/redis.conf echo "appendonly yes" >> /mydata/redis/6379/conf/redis.conf docker run --network host --name redis6379 -v /mydata/redis/6379/data:/data -v /mydata/redis/6379/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf --port 6379
slave
#slave1 mkdir -p /mydata/redis/6380/conf mkdir -p /mydata/redis/6380/data touch /mydata/redis/6380/conf/redis.conf echo "appendonly yes" >> /mydata/redis/6380/conf/redis.conf docker run --network host --name redis6380 -v /mydata/redis/6380/data:/data -v /mydata/redis/6380/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf --port 6380 --slaveof 192.168.243.4 6379 #slave2 mkdir -p /mydata/redis/6381/conf mkdir -p /mydata/redis/6381/data touch /mydata/redis/6381/conf/redis.conf echo "appendonly yes" >> /mydata/redis/6381/conf/redis.conf docker run --network host --name redis6381 -v /mydata/redis/6381/data:/data -v /mydata/redis/6381/conf/redis.conf:/etc/redis/redis.conf -d redis redis-server /etc/redis/redis.conf --port 6381 --slaveof 192.168.243.4 6379
1.2 配置查看
主
docker exec -it redis6379 redis-cli >info replication
從
docker exec -it redis6380 redis-cli -p 6380 >info replication
二 哨兵配置
master
mkdir /mydata/redis/6379/sentinel mkdir /mydata/redis/6379/sentinel/log vi /mydata/redis/6379/sentinel/sentinel.conf #輸入 port 26379 dir "/var/log/sentinel" logfile "/var/log/sentinel/26379.log" sentinel monitor mymaster 192.168.243.4 6379 1 ![在這里插入圖片描述](https://img-blog.csdnimg.cn/9a303b239fec467385d2c8990cb3e629.png#pic_center) sentinel down-after-milliseconds mymaster 5000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 #end docker run -d --name sentinel26379 -v /mydata/redis/6379/sentinel/sentinel.conf:/conf/sentinel.con
測試
docker exec -it redis6379 redis-cli > SHUTDOWN > exit cat /mydata/redis/6379/sentinel/log/26379.log
再次啟動docker start redis6379,可以看到6379是slave了
三 修改配置文件
slave
#slave1 mkdir /mydata/redis/6380/sentinel mkdir /mydata/redis/6380/sentinel/log vi /mydata/redis/6380/sentinel/sentinel.conf #輸入 port 26380 dir "/var/log/sentinel" logfile "/var/log/sentinel/26380.log" sentinel monitor mymaster 192.168.243.4 6380 2 sentinel down-after-milliseconds mymaster 5000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 #end docker run -d --name sentinel26380 -v /mydata/redis/6380/sentinel/sentinel.conf:/conf/sentinel.conf -v /mydata/redis/6380/sentinel/log:/var/log/sentinel --network host redis redis-sentinel /conf/sentinel.conf #slave2 mkdir /mydata/redis/6381/sentinel mkdir /mydata/redis/6381/sentinel/log vi /mydata/redis/6381/sentinel/sentinel.conf #輸入 port 26381 dir "/var/log/sentinel" logfile "/var/log/sentinel/26381.log" sentinel monitor mymaster 192.168.243.4 6381 2 sentinel down-after-milliseconds mymaster 5000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 #end docker run -d --name sentinel26381 -v /mydata/redis/6381/sentinel/sentinel.conf:/conf/sentinel.conf -v /mydata/redis/6381/sentinel/log:/var/log/sentinel --network host redis redis-sentinel /conf/sentinel.conf
四 連接SpringBoot
application.yml
spring: redis: timeout: 5000 sentinel: master: mymaster nodes: 192.168.243.4:26379,192.168.243.4:26380,192.168.243.4:26381
controller
@Autowired private StringRedisTemplate redisTemplate; @RequestMapping("/redis") public String redis() { redisTemplate.opsForValue().set("test", "121323123"); String test = redisTemplate.opsForValue().get("test"); return "RESULT: " + test; }
訪問localhost:8080/redis
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/127640.html
摘要:時間年月日星期二說明基于,開始本教程前,請確保您的系統已安裝。為了保證集群的高可用,下面開始配置哨兵模式。 時間:2017年07月11日星期二 說明:基于Ubuntu16.04-64bit,開始本教程前,請確保您的Linux系統已安裝Docker。 步驟一:Redis鏡像安裝 1、下載Redis鏡像 鏡像中心 推薦使用網易蜂巢的鏡像中心 地址:https://c.163.com/hub...
閱讀 1168·2022-09-27 09:47
閱讀 1064·2022-09-27 09:28
閱讀 1528·2022-09-27 09:16
閱讀 835·2022-09-27 08:21
閱讀 1005·2022-09-27 08:08
閱讀 1152·2022-09-18 12:33
閱讀 816·2022-09-16 08:01
閱讀 869·2022-09-15 12:27