Redis Sentinelãåããã¦ã¿ã
以åãRedis Sentinelã試ãã¨ããã¨ã³ããªã¼ãæ¸ãã¾ããã
ããå°ãå
¥ãè¾¼ãã§æ¤è¨¼ãã¦ã¿ãã
æ®´ãæ¸ãã®åãåºã¦ããªãã®ã§é©æã¢ãããã¼ããã¦ããããã
æ¤è¨¼ç°å¢
- DATE: 2013/01/25
- CentOS 6.3
- Redis 2.6.9(remi)
ããã¥ã¡ã³ã
http://redis.io/topics/sentinel
ãã¡ããåèã«è¡ãã¾ãã
Sentinelã®è¨å®ãããã³èµ·åæ¹æ³
$ /usr/local/bin/redis-server /etc/sentinel.conf --sentinel [28498] 25 Jan 01:28:24.447 * Max number of open files set to 10032 _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.6.9 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in sentinel mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 26379 | `-._ `._ / _.-' | PID: 28498 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [28498] 25 Jan 01:28:24.451 * +slave slave 192.168.2.102:6379 192.168.2.102 6379 @ mymaster 192.168.2.101 6379 [28498] 25 Jan 01:28:25.358 * +sentinel sentinel 192.168.2.101:26379 192.168.2.101 26379 @ mymaster 192.168.2.101 6379
ãããªæãã§èµ·åãã¾ãã
è¨å®ãã¡ã¤ã«
åè: http://download.redis.io/redis-stable/sentinel.conf
sentinel monitor mymaster 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 60000 sentinel failover-timeout mymaster 900000 sentinel can-failover mymaster yes sentinel parallel-syncs mymaster 1
ãªãã£ã·ã£ã«ã®è¨å®ãã¡ã¤ã«ãåèã«ã
è¨å®ã®æå³
sentinel monitor <master-name> <ip> <redis-port> <quorum>
ãã®<quorum>
ã¯Redis-Sentinelã®æ°ãæãã¾ãã
Redis-Sentinelã¯ãä»ã®Redis-Sentinelãæ¥ç¶ãã¦ããå ´åã«
ç¸äºã«çè§£ããåããããã¾ãã
ãã®æ©è½ã«ãã£ã¦Split-brain-syndromeãé²ããã¨ãå¯è½ã§ãã
Redisã®ã¬ããªã±ã¼ã·ã§ã³ãæ£å¸¸ã«è¡ãã¦ããç¶æ
Redisã®ã¬ããªã±ã¼ã·ã§ã³ã®åç·ã«é害ãçºçããå ´å
ä¸è¨ã®ããã«ãã¬ããªã±ã¼ã·ã§ã³ã®çµè·¯ã«ç°å¸¸ãçºçããå ´å
Split-brain-syndromeãèµ·ãã
ã¬ããªã±ã¼ã·ã§ã³æ å ±ã¯ä¿ã¦ãªããªãããäºããMasterã¨èªèãã¦ãã¾ãåé¡ãããã¾ãã
ä¸è¨ã®ãããªç¶æ³ãé¿ããçºã«<quorum>
ã®è¨å®ãããã¾ãã
ãã®quorumã®å¤ã¯ãç£è¦ãã¦ããRedis-Sentinelã®æ°ã表ãã¦ãã¾ãã
ä¸è¨ã®ããã«ã¬ããªã±ã¼ã·ã§ã³ã®çµè·¯ã«ç°å¸¸ããã£ãå ´åã§ãã£ã¦ã
<quorum>
ã§è¨å®ããæ°ã®Sentinelãç°å¸¸ãæ¤ç¥ãã¦åãã¦ãã§ã¤ã«ãªã¼ãã¼ãå§ã¾ãã¾ãã
Sentinelã¯Sentinelå士ã§çè§£ãåãæ©è½ãæè¼ããã¦ãããã§ããã
人éã«ããããªæ©è½ããã£ããäºãã¨ããªããªãã¾ãããã
Redis-Sentinelã®é£çµ¡ãè¡ããªããªããSplit-brain-syndromeã¯èµ·ãããªã
ã¨ãããã¨ã§ã<quorum>
ã2å°ä»¥ä¸è¨å®ãããã¨ã§ã
äºæããªããã§ã¤ã«ãªã¼ãã¼ãäºé²ãããã¨ãå¯è½ã§ãã
sentinel down-after-milliseconds mymaster 60000
SentinelãDOWNãæ¤ç¥ãã¦ããã®ãã§ã¤ã«ãªã¼ãã¼ãå§ããã¾ã§ã®ã¢ã¤ãã«æéã
DOWNã¨èªããæ¡ä»¶ã¯ããã¥ã¡ã³ããåç §ã
ODOWNã¨SDOWNã«ã¤ãã¦ãããå°ãæ¸ãããã
æ¤è¨¼æã§ã¯ 5000milliseconds ããããåé¡ãªãåä½ããã
ã¹ããã¯ãç°å¢ã«ãã£ã¦ã¯ãã£ã¨ã¹ãã¤ãã¯ãªè¨å®ãå¯è½ã
ãªããå®éã«Masterãåãæ¿ããã¾ã§ 5~15ç§ ã®éã§ã©ã³ãã ãªå¾ ã¡æéãçºçããã
Sentinel Rule #14: A Sentinel detects a failover as an Observer (that is, the Sentinel just follows the failover generating the appropriate events in the log file and Pub/Sub interface, but without actively reconfiguring instances) if the following conditions are true at the same time: * There is no failover already in progress. * A slave instance of the monitored master turned into a master. However the failover will NOT be sensed as started if the slave instance turns into a master and at the same time the runid has changed from the previous one. This means the instance turned into a master because of a restart, and is not a valid condition to consider it a slave election.
Sentinel Rule #15: A Sentinel starting a failover as leader does not immediately starts it. It enters a state called wait-start, that lasts a random amount of time between 5 seconds and 15 seconds. During this time Sentinel Rule #14 still applies: if a valid slave promotion is detected the failover as leader is aborted and the failover as observer is detected.
詳細ã¯ããã¥ã¡ã³ãã® Sentinel Rule #14,#15 ãåç §ã
ãªã®ã§ããã§ã¤ã«ãªã¼ãã¼ãéå§ãããã¿ã¤ãã³ã°ã¯
down-after-milliseconds + 5~15ç§ ã®æéã«ãªãã¾ãã
sentinel failover-timeout mymaster 900000
ãã§ã¤ã«ãªã¼ãã¼ãéå§ãã¦ãããã¬ã¹ãã³ã¹ãè¿ã£ã¦ããã¾ã§ã®
å¾
ã¡æéã詳細ã¯ãã¯ãããã¥ã¡ã³ããèªãã§ã»ããã
æ¤è¨¼æã« "10 milliseconds" ãªã©ã¹ãã¤ãã¯ãªè¨å®ãè¡ãªã£ã¦ã¿ãã ã¿ã¤ã ã¢ã¦ãã«å¼ã£ããããã¬ããªã±ã¼ã·ã§ã³ãéå§ãããã¨ã¯ãªãã£ã... ãã¡ãããã¯ã "5000 milliseconds" ããããå®å ¨ã§ãã£ã
sentinel can-failover mymaster yes
mymasterã®ãã¦ã³æã«ããã§ã¤ã«ãªã¼ãã¼ãå®è¡ãããå¦ãã®è¨å®ã
sentinel parallel-syncs mymaster 1
ãã§ã¤ã«ãªã¼ãã¼ãå®è¡ãããå¾ãæ°ãããã¹ã¿ã¼ã
使ç¨ããããã«ä¸¦åã§åæ§æãããã¨ãã§ããã¹ã¬ã¼ãã®æ°ã®æå®ã
Slaveãµã¼ããå¤ãããã®è¨å®æ°ãä½ãã»ã©ã
ãã§ã¤ã«ãªã¼ãã¼ã®å¦çã«æéããããã¨ã®ãã¨ã
(æªæ¤è¨¼)
ãã¾ãï¼ã¬ããªã±ã¼ã·ã§ã³ã®æ§ç¯æé
Slave(192.168.2.102)
$ echo "slaveof 192.168.2.101 6379" | redis-cli -h 192.168.2.102 OK $ $ redis-cli -h 192.168.2.102 info | grep -E 'mas|sla' role:slave master_host:192.168.2.101 master_port:6379 master_link_status:up master_last_io_seconds_ago:5 master_sync_in_progress:0 slave_priority:100 slave_read_only:1 connected_slaves:0 $
Master(192.168.2.101)
$ redis-cli -h 192.168.2.101 info | grep -E 'mas|sla' role:master connected_slaves:1 slave0:192.168.2.102,6379,online $
ã¬ããªã±ã¼ã·ã§ã³ã®æ å ±
master_host:192.168.2.101
Masterã®IPã¢ãã¬ã¹æ å ±master_port:6379
Masterã®Portçªå·æ å ±master_link_status:up
Masterã®ç¶æ ã®æ å ±master_last_io_seconds_ago
Slaveã¯10ç§ééã§Masterã¸PINGãéä¿¡ãã¦ããã
ãã®"æ£å¸¸ãª"ãã¼ã¿ãåä¿¡ãã¦ããã®çµéæéã®æ å ±
monitor
ã³ãã³ãã§ç¢ºèªãããã¨ãã§ããã
$ redis-cli -h 192.168.2.102 monitor OK 1359037270.075903 [0 192.168.2.101:6379] "PING" 1359037280.274001 [0 192.168.2.101:6379] "PING" 1359037290.464774 [0 192.168.2.101:6379] "PING"
master_sync_in_progress
Masterãããã¼ã¿ãåä¿¡ç¶æ³(SYNC)ã®æ å ±
SYNCä¸ã§ããã° 1 ã®ãã©ã°ãç«ã¡ãç¶æ³ã®è©³ç´°ã表示ãããã
詳細ã¯ãã¡ã : INFO / Redis
Masterãè½ã¡ã¦ããå ´åã®ç¶æ
master_link_status:down master_last_io_seconds_ago:-1 master_sync_in_progress:0 master_link_down_since_seconds:N
PINGã®ééã10ç§ééãªã®ã§ãçéãã§ãã¯ã10ç§ééãã¨æãã
ããã§ã¯ãªã(ããå°ã調ã¹ã)ã
ãã¾ãã®ãã¾ã
Slaveã®Slaveãè¨å®å¯è½
101.slave(Master) <= 102.6379(Slave) <= 102.6380(Slave)
$ redis-cli -h 192.168.2.102 info | grep -E 'mas|sla' role:slave master_host:192.168.2.101 master_port:6379 master_link_status:up master_last_io_seconds_ago:7 master_sync_in_progress:0 slave_priority:100 slave_read_only:1 connected_slaves:1 slave0:192.168.2.102,6380,online $
ã¾ããMasterã¨Slaveã®æ¥ç¶ãåããå ´åã
Slave <=> Slaveã®åæã¯åæ¢ããã(æ¤è¨¼æ¸ã¿)
master_last_io_seconds_ago ã Sentinelç«ã¡ä¸ããäºã«ééãçãããªã
3å°ä¸ãããã»ã¨ãã©1ç§ééã«ãªã£ãã
ã¨ãããã¨ã§
Sentinelãããèãããã¦ãããªã¨ããå°è±¡ã§ãã
以ä¸ããã®æ
å ±ãä½ãã®ãå½¹ã«ç«ã¦ãã°å¹¸ãã§ãã
This HOWTO is a work in progress, more information will be added in the near future.
https://github.com/antirez/redis-doc/blob/master/topics/sentinel.md
ã¨ãããã¨ã§ãæ´»çºçã«éçºãè¡ããã¦ããã®ã§
驿ãã§ãã¯ããã®ãè¯ãããã§ããã