카테고리 없음

Redis - Sentinel fail-over (windows)

springship 2017. 3. 3. 01:04

 

Redis - Sentinel fail-over

 

 

1. 준비

- Redis 설치 : 3.0.503

- node.js 설치 : 6.10

 

2. Redis 설치 :

- download : https://github.com/ServiceStack/redis-windows/tree/master/downloads

(download 받아 압축 해제 )

 

 

3. node.js

- download 받아 압축 해제

 

4. redis.windows.conf 파일을 copy 하여 config 파일 작성

 

 

5. sentinel.conf 파일을 download / copy 하여 config 파일 작성

- http://download.redis.io/redis-stable/sentinel.conf

 

6. conf 폴더 하위에 작성

- Redis config (Master, Slave)

- Sentinel conf (총 3개)

 

 

7. conf 파일 수정(Master 예)

 

 

 

[redis.master6379.conf]

port 6379 

bind 127.0.0.1 

 

[redis.slave6380.conf]

port 6380 

bind 127.0.0.1 

# slaveof <masterip> <masterport>

slaveof 127.0.0.1 6379

 

 

8. Master 기동 (port : 6379)

- 기동 : redis-server.exe .\conf\redis.master6379.conf

 

 

9. Redis client 로 key 저장

- mykey : Hello Redis

 

 

10. Sentinel config 설정

 

 

 

# 포트 변경(각각 26279, 26380, 26381 로 설정)

port 26379

 

#-->

sentinel monitor mymaster 127.0.0.1 6379 2

# Default is 30 seconds.

sentinel down-after-milliseconds mymaster 30000

sentinel parallel-syncs mymaster 1

# Default is 3 minutes.

sentinel failover-timeout mymaster 180000

#<-- 이부분(주요 설정)은

 

#dir /tmp

dir .\tmp

#폴더 생성 후 지정

 

 

11. Slave 기동 (port : 6380)

- 기동 :  redis-server.exe .\conf\redis.slave6380.conf

 

 

12. Master 의 Sync 메시지 확인 (port : 6379)

 

 

13. Sentinel 기동

 

redis-server.exe .\conf\sentinel.26379.conf --sentinel 

redis-server.exe .\conf\sentinel.26380.conf --sentinel 

redis-server.exe .\conf\sentinel.26381.conf --sentinel

 

 

 

 

14. node.js 테스트

 

 

npm 으로 ioredis install -> 소스작성 -> 실행

- (명령) npm install ioredis

 

 

var Redis = require('ioredis');

var redis = new Redis ( {

    sentinels: [     { host:  '127.0.0.1',  port: 26397 }

                    , { host:  '127.0.0.1',  port: 26380 }

                    , { host:  '127.0.0.1',  port: 26381 }

                ],

    name: 'mymaster'

    });

   

    redis.get('mykey' , function (err, result) {

        console.log(result);

    });

   

    redis.quit();

 

15. Master(port : 6379) shutdown

 

 

16. Sentinel (port : 26379) shutdown

 

 

17. Slave (port : 6380) 이 Master 로 승격

 

 

18. Sentinel (port : 26380, 26381) Master 를 투표/선출