Redis部署哨兵集群

发布 : 2017-06-14 分类 : 大数据 浏览 :
1
2
3
192.168.31.231 matrix-cache01(redis主节点)
192.168.31.232 matrix-cache02(redis从节点)
192.168.31.233 matrix-cache03(redis从节点)

1.启动Reids上的server服务

1
2
3
[root@matrix-cache01 ~]# cd /etc/init.d
[root@matrix-cache01 init.d]# ./redis_6379 start
Starting Redis server...
1
2
3
[root@matrix-cache02 ~]# cd /etc/init.d
[root@matrix-cache02 init.d]# ./redis_6379 start
Starting Redis server...
1
2
3
[root@matrix-cache03 ~]# cd /etc/init.d
[root@matrix-cache03 init.d]# ./redis_6379 start
Starting Redis server...

2.部署哨兵集群

1
2
3
4
5
6
7
8
哨兵默认用26379端口,默认不能跟其他机器在指定端口连通,只能在本地访问

[root@matrix-cache01 ~]# mkdir -p /etc/sentinel
[root@matrix-cache01 ~]# mkdir -p /var/sentinel/5000
[root@matrix-cache02 ~]# mkdir -p /etc/sentinel
[root@matrix-cache03 ~]# mkdir -p /var/sentinel/5000
[root@matrix-cache03 ~]# mkdir -p /etc/sentinel
[root@matrix-cache03 ~]# mkdir -p /var/sentinel/5000
1
2
3
4
5
6
7
8
9
[root@matrix-cache01 ~]# vi /etc/sentinel/5000.conf
port 5000
bind 192.168.31.231
dir /var/sentinel/5000
sentinel monitor mymaster 192.168.31.231 6379 2
sentinel auth-pass mymaster redis-pass
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 5000
sentinel parallel-syncs mymaster 1

Markdown

1
2
3
4
5
6
7
8
9
[root@matrix-cache02 ~]# vi /etc/sentinel/5000.conf
port 5000
bind 192.168.31.232
dir /var/sentinel/5000
sentinel monitor mymaster 192.168.31.231 6379 2
sentinel auth-pass mymaster redis-pass
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 5000
sentinel parallel-syncs mymaster 1

Markdown

1
2
3
4
5
6
7
8
9
[root@matrix-cache03 ~]# vi /etc/sentinel/5000.conf
port 5000
bind 192.168.31.233
dir /var/sentinel/5000
sentinel monitor mymaster 192.168.31.231 6379 2
sentinel auth-pass mymaster redis-pass
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 5000
sentinel parallel-syncs mymaster 1

Markdown

3.启动哨兵进程

1
2
3
4
5
6
7
8
在matrix-cache01、matrix-cache02、matrix-cache03三台机器上
分别启动三个哨兵进程,组成一个集群,观察一下日志的输出

使用
redis-sentinel /etc/sentinel/5000.conf

redis-server /etc/sentinel/5000.conf --sentinel
启动哨兵进程
1
[root@matrix-cache01 ~]# redis-sentinel /etc/sentinel/5000.conf

Markdown

1
[root@matrix-cache02 ~]# redis-sentinel /etc/sentinel/5000.conf

Markdown

1
[root@matrix-cache03 ~]# redis-sentinel /etc/sentinel/5000.conf

Markdown

1
2
3
4
5
日志里会显示出来,每个哨兵都能去监控到对应的redis master
并能够自动发现对应的slave

哨兵之间,互相会自动进行发现,用的就是之前说的pub/sub
消息发布和订阅channel消息系统和机制

4.检查哨兵状态

连接哨兵

1
[root@matrix-cache01 ~]# redis-cli -h 192.168.31.231 -p 5000

Markdown

查看监控的某个redis master信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
192.168.31.231:5000> sentinel master mymaster
1) "name"
2) "mymaster"
3) "ip"
4) "192.168.31.231"
5) "port"
6) "6379"
7) "runid"
8) "2d26fc699ea79c1e07293b7b4ba400a41464a609"
9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "290"
19) "last-ping-reply"
20) "290"
21) "down-after-milliseconds"
22) "1000"
23) "info-refresh"
24) "3402"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "394899"
29) "config-epoch"
30) "0"
31) "num-slaves"
32) "2"
33) "num-other-sentinels"
34) "2"
35) "quorum"
36) "2"
37) "failover-timeout"
38) "5000"
39) "parallel-syncs"
40) "1"

查看监控的某个redis集群的所有slave节点信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
192.168.31.231:5000> sentinel slaves mymaster
1) 1) "name"
2) "192.168.31.232:6379"
3) "ip"
4) "192.168.31.232"
5) "port"
6) "6379"
7) "runid"
8) "01d8340152c3a295cfb77a3362dccdb99178463d"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "220"
19) "last-ping-reply"
20) "220"
21) "down-after-milliseconds"
22) "1000"
23) "info-refresh"
24) "3784"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "475711"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "192.168.31.231"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "99598"
2) 1) "name"
2) "192.168.31.233:6379"
3) "ip"
4) "192.168.31.233"
5) "port"
6) "6379"
7) "runid"
8) "65ed4a4c33f45364329675271c69d52ec4c3bf0a"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "220"
19) "last-ping-reply"
20) "220"
21) "down-after-milliseconds"
22) "1000"
23) "info-refresh"
24) "3784"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "475709"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "192.168.31.231"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "99598"

查看所有sentinel实例信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
192.168.31.231:5000> sentinel sentinels mymaster
1) 1) "name"
2) "707fb3721cfa9fd1edd4059da134614a41840745"
3) "ip"
4) "192.168.31.233"
5) "port"
6) "5000"
7) "runid"
8) "707fb3721cfa9fd1edd4059da134614a41840745"
9) "flags"
10) "sentinel"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "113"
19) "last-ping-reply"
20) "113"
21) "down-after-milliseconds"
22) "1000"
23) "last-hello-message"
24) "874"
25) "voted-leader"
26) "?"
27) "voted-leader-epoch"
28) "0"
2) 1) "name"
2) "61e7c8a7ba924ee22fab0d611f928139e4c9dbbf"
3) "ip"
4) "192.168.31.232"
5) "port"
6) "5000"
7) "runid"
8) "61e7c8a7ba924ee22fab0d611f928139e4c9dbbf"
9) "flags"
10) "sentinel"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "113"
19) "last-ping-reply"
20) "113"
21) "down-after-milliseconds"
22) "1000"
23) "last-hello-message"
24) "877"
25) "voted-leader"
26) "?"
27) "voted-leader-epoch"
28) "0"

通过哨兵查看master的ip地址和端口号

1
2
3
192.168.31.231:5000> sentinel get-master-addr-by-name mymaster
1) "192.168.31.231"
2) "6379"

Markdown

本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2017/06/14/Redis部署哨兵集群/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹