redis sentinel 配置
1.環境資訊
在三臺主機上,ct6601為redis master,ct6602為redis slave,
ct6601,ct6602,ct6604各裝一個sentinel
redis version:2.8.20
hsot:ct6601 192.108.56.117
ct6602 192.108.56.119
ct6604 192.108.56.120
master: 192.108.56.117 6379
slave1: 192.108.56.119 6379
sentinel1: 192.108.56.117 26379
sentinel2: 192.108.56.119 26379
sentinel3: 192.108.56.120 26379
2.配置
#在ct6601,ct6602,ct6604安裝redis
[root@ct6601 ~]# tar -xzvf redis-2.8.20.tar.gz
[root@ct6601 ~]# cd /root/redis-2.8.20
[root@ct6601 ~]# make
[root@ct6601 ~]# make install
[root@ct6601 redis-2.8.20]# mkdir /usr/local/redis
#在ct6601,ct6602中複製預設的redis.conf檔案
[root@ct6601 redis-2.8.20]# cp /root/redis-2.8.20/redis.conf /usr/local/redis/redis.conf
#修改ct6601的redis.conf配置檔案
[root@ct6601 redis-2.8.20]# vi /usr/local/redis/redis.conf
修改:daemonize yes
#修改ct6602的redis.conf配置檔案
[root@ct6602 redis-2.8.20]# vim /usr/local/redis/redis.conf
修改:daemonize yes
修改:slaveof 192.108.56.117 6379
#在ct6601,ct6602上啟動redis服務
[root@ct6601 redis]# redis-server /usr/local/redis/redis.conf
#在ct6601,ct6602上檢視驗證master-slave
[root@ct6601 redis]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.108.56.119,port=6379,state=online,offset=225,lag=1
master_repl_offset:225
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:224
127.0.0.1:6379> set mykey hello,select~
OK
[root@ct6602 redis-2.8.20]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.108.56.117
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:334
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379> get mykey
"hello,select~"
#在ct6601,ct6602,ct6604上配置redis sentinel
[root@ct6601 redis]# cp /root/redis-2.8.20/sentinel.conf /usr/local/redis/sentinel.conf
[root@ct6601 redis]# vi /usr/local/redis/sentinel.conf
加入:daemonize yes
修改:sentinel monitor mymaster 192.108.56.117 6379 2
[root@ct6601 redis]# redis-sentinel /usr/local/redis/sentinel.conf
#檢視驗證redis sentinel
[root@ct6601 redis]# redis-cli -p 26379 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=192.108.56.117:6379,slaves=1,sentinels=3
#關閉ct6601的redis服務
[root@ct6601 redis]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.108.56.119,port=6379,state=online,offset=45753,lag=0
master_repl_offset:45896
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:45895
127.0.0.1:6379> shutdown
not connected> exit
#ct6602上的redis變為master角色
[root@ct6602 redis-2.8.20]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
#重新開啟ct6601上的redis服務,可以看到ct6601上的redis已經變為slave角色
[root@ct6601 redis]# redis-server /usr/local/redis/redis.conf
[root@ct6601 redis]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.108.56.119
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:2040
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
[root@ct6602 redis-2.8.20]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.108.56.117,port=6379,state=online,offset=9089,lag=0
master_repl_offset:9089
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:9088
3.備註
經測試,redis sentinel需要最少3個例項,否則如果一臺主機redis和redis sentinel都down掉,無法自動切換.
在三臺主機上,ct6601為redis master,ct6602為redis slave,
ct6601,ct6602,ct6604各裝一個sentinel
redis version:2.8.20
hsot:ct6601 192.108.56.117
ct6602 192.108.56.119
ct6604 192.108.56.120
master: 192.108.56.117 6379
slave1: 192.108.56.119 6379
sentinel1: 192.108.56.117 26379
sentinel2: 192.108.56.119 26379
sentinel3: 192.108.56.120 26379
2.配置
#在ct6601,ct6602,ct6604安裝redis
[root@ct6601 ~]# tar -xzvf redis-2.8.20.tar.gz
[root@ct6601 ~]# cd /root/redis-2.8.20
[root@ct6601 ~]# make
[root@ct6601 ~]# make install
[root@ct6601 redis-2.8.20]# mkdir /usr/local/redis
#在ct6601,ct6602中複製預設的redis.conf檔案
[root@ct6601 redis-2.8.20]# cp /root/redis-2.8.20/redis.conf /usr/local/redis/redis.conf
#修改ct6601的redis.conf配置檔案
[root@ct6601 redis-2.8.20]# vi /usr/local/redis/redis.conf
修改:daemonize yes
#修改ct6602的redis.conf配置檔案
[root@ct6602 redis-2.8.20]# vim /usr/local/redis/redis.conf
修改:daemonize yes
修改:slaveof 192.108.56.117 6379
#在ct6601,ct6602上啟動redis服務
[root@ct6601 redis]# redis-server /usr/local/redis/redis.conf
#在ct6601,ct6602上檢視驗證master-slave
[root@ct6601 redis]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.108.56.119,port=6379,state=online,offset=225,lag=1
master_repl_offset:225
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:224
127.0.0.1:6379> set mykey hello,select~
OK
[root@ct6602 redis-2.8.20]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.108.56.117
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:334
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379> get mykey
"hello,select~"
#在ct6601,ct6602,ct6604上配置redis sentinel
[root@ct6601 redis]# cp /root/redis-2.8.20/sentinel.conf /usr/local/redis/sentinel.conf
[root@ct6601 redis]# vi /usr/local/redis/sentinel.conf
加入:daemonize yes
修改:sentinel monitor mymaster 192.108.56.117 6379 2
[root@ct6601 redis]# redis-sentinel /usr/local/redis/sentinel.conf
#檢視驗證redis sentinel
[root@ct6601 redis]# redis-cli -p 26379 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=192.108.56.117:6379,slaves=1,sentinels=3
#關閉ct6601的redis服務
[root@ct6601 redis]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.108.56.119,port=6379,state=online,offset=45753,lag=0
master_repl_offset:45896
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:45895
127.0.0.1:6379> shutdown
not connected> exit
#ct6602上的redis變為master角色
[root@ct6602 redis-2.8.20]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
#重新開啟ct6601上的redis服務,可以看到ct6601上的redis已經變為slave角色
[root@ct6601 redis]# redis-server /usr/local/redis/redis.conf
[root@ct6601 redis]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.108.56.119
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:2040
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
[root@ct6602 redis-2.8.20]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.108.56.117,port=6379,state=online,offset=9089,lag=0
master_repl_offset:9089
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:9088
3.備註
經測試,redis sentinel需要最少3個例項,否則如果一臺主機redis和redis sentinel都down掉,無法自動切換.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1867591/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- redis sentinel配置啟動Redis
- Redis Sentinel哨兵模式原理及配置Redis模式
- Redis——SentinelRedis
- Redis-3.2.1 sentinel安裝和配置小記Redis
- Redis哨兵sentinelRedis
- Redis sentinel搭建Redis
- Redis高可用 SentinelRedis
- 【Redis】Sentinel 哨兵模式Redis模式
- redis sentinel哨兵 例項Redis
- Redis Sentinel哨兵模式部署Redis模式
- 聊聊Redis sentinel 機制Redis
- Redis 哨兵高可用(Sentinel)Redis
- Redis Sentinel實現原理Redis
- Redis sentinel主從切換Redis
- 用 docker 學習 redis 主從複製3.2 redis-sentinel「哨兵模式」核心配置-命令-原理DockerRedis模式
- 玩轉Redis叢集之SentinelRedis
- 分散式Redis深度歷險-Sentinel分散式Redis
- redis的sentinel模式故障演練Redis模式
- Redis服務之高可用元件sentinelRedis元件
- Redis for linux原始碼&叢集(cluster)&主從(master-slave)&哨兵(sentinel)安裝配置RedisLinux原始碼AST
- Redis docker 主從模式與哨兵sentinelRedisDocker模式
- Redis基礎知識(學習筆記19--Redis Sentinel)Redis筆記
- Redis | 第12章 Sentinel 哨兵模式《Redis設計與實現》Redis模式
- windows redis sentinel listen: Unknown error解決方案WindowsRedisError
- Redis學習筆記(十六) Sentinel(哨兵)(下)Redis筆記
- Redis安裝之叢集-哨兵模式(sentinel)模式Redis模式
- redis sentinel哨兵模式安裝部署和切換Redis模式
- Redis Sentinel-深入淺出原理和實戰Redis
- 用 docker 學習 redis 主從複製3 redis-sentinel(哨兵模式)DockerRedis模式
- 配置RedisRedis
- PHP 在redis-sentinel模式下的使用總結PHPRedis模式
- 第77篇 Redis中的Sentinel(哨兵模式)詳解Redis模式
- redis之 Redis持久化配置Redis持久化
- redis主從叢集搭建及容災部署(哨兵sentinel)Redis
- docker搭建redis叢集和Sentinel,實現故障轉移DockerRedis
- redis常用配置Redis
- Lumen配置RedisRedis
- SpringCloud使用Sentinel,Sentinel持久化,Sentinel使用nacos持久化SpringGCCloud持久化
- Redis主從配置Redis