redis-mmm 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +82 -0
- data/bin/redis_mmm +7 -6
- metadata +5 -5
- data/README +0 -32
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
redis-mmm - redis multi master replication manager
|
2
|
+
==================================================
|
3
|
+
|
4
|
+
This project is a port of a lot of ideas of mysql-mmm to redis. That also explains the name as an hommage to the mysql-mmm project
|
5
|
+
|
6
|
+
Multi-Master?
|
7
|
+
-------------
|
8
|
+
|
9
|
+
No. Not really.
|
10
|
+
|
11
|
+
|
12
|
+
What then?
|
13
|
+
----------
|
14
|
+
|
15
|
+
redis-mmm aims to provide automatic (and, to some extent, manual) failover functionality in case the redis master crashes or anything else happens.
|
16
|
+
This functionality does not exist in redis itself.
|
17
|
+
|
18
|
+
The whole idea behind that is having a virtual IP address to which all redis clients connect to reach the master. This IP is then migrated to the
|
19
|
+
current master machine, so that the client will always reach the master. There is a slave IP address, too, so you could even balance the reads off of
|
20
|
+
the master!
|
21
|
+
|
22
|
+
All work is done by a separate monitoring process (which, for obvious reasons, should reside on a completely different host).
|
23
|
+
|
24
|
+
|
25
|
+
How to make it work
|
26
|
+
-------------------
|
27
|
+
|
28
|
+
Before you start, you need to make sure you have the following prerequisites:
|
29
|
+
|
30
|
+
* a network where you can dynamically change IPs (should be a private network)
|
31
|
+
* 2 free IP addresses
|
32
|
+
* you are NOT on Amazon EC2, since you can't add / remove IPs there (that's a lesson I had to learn)
|
33
|
+
* a separate monitoring host on your network
|
34
|
+
* two redis servers on different machines (I'll call them db1 and db2)
|
35
|
+
* redis is listening on 0.0.0.0
|
36
|
+
* the monitoring host can access both redis instances (I'll call it mon)
|
37
|
+
* a redis-mmm user on all hosts
|
38
|
+
* redis-mmm@mon can ssh to redis-mmm@db1 and redis-mmm@db2 without entering a password
|
39
|
+
* redis-mmm@db{1,2} can use sudo to do the following commands
|
40
|
+
* /sbin/ip addr {show,add,del}
|
41
|
+
* /usr/bin/arping
|
42
|
+
|
43
|
+
|
44
|
+
Now, go to the monitoring host, install redis-mmm (`gem install redis-mmm`) and configure /etc/redis-mmm.conf
|
45
|
+
|
46
|
+
Example configuration:
|
47
|
+
|
48
|
+
master_ip = 192.168.10.70
|
49
|
+
cluster_interface = eth1
|
50
|
+
|
51
|
+
[db1]
|
52
|
+
address = 192.168.10.1
|
53
|
+
port = 6379
|
54
|
+
ssh_user = redis-mmm
|
55
|
+
ssh_port = 22
|
56
|
+
|
57
|
+
[db2]
|
58
|
+
address = 192.168.10.2
|
59
|
+
port = 6379
|
60
|
+
ssh_user = redis-mmm
|
61
|
+
ssh_port = 22
|
62
|
+
|
63
|
+
|
64
|
+
To start the monitoring, start `redis_mmm mon`. It's left as an excercise for the reader to use upstart, god or bluepill to keep that process running.
|
65
|
+
|
66
|
+
To view the cluster's status, call `redis_mmm status`
|
67
|
+
|
68
|
+
To view info about a node, use `redis_mmm info <node>`
|
69
|
+
|
70
|
+
To show help: `redis_mmm help`
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
Warning
|
75
|
+
=======
|
76
|
+
|
77
|
+
This is an experimental piece of software not yet ready for prime time. I can't guarantee
|
78
|
+
consistency for now, since there's no way to make a redis server read only and some redis clients
|
79
|
+
seem to ignore crashed servers
|
80
|
+
|
81
|
+
Nevertheless, play and try, fork and update and give feedback!
|
82
|
+
|
data/bin/redis_mmm
CHANGED
@@ -65,7 +65,7 @@ class RedisMMM < Thor
|
|
65
65
|
:master_link_status => info["master_link_status"],
|
66
66
|
:master_last_io_seconds_ago => info["master_last_io_seconds_ago"]
|
67
67
|
}
|
68
|
-
rescue Errno::ECONNREFUSED
|
68
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
69
69
|
{
|
70
70
|
:online => false
|
71
71
|
}
|
@@ -73,12 +73,11 @@ class RedisMMM < Thor
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def add_ip(ip, interface)
|
76
|
-
$log.debug ssh("ip addr show #{interface} | grep #{ip} || sudo ip addr add #{ip} dev #{interface}")
|
77
|
-
|
76
|
+
$log.debug ssh("ip addr show #{interface} | grep #{ip} || (sudo ip addr add #{ip}/32 dev #{interface}; sudo arping -c 5 -U -s #{ip} -I #{interface} #{ip})")
|
78
77
|
end
|
79
78
|
|
80
79
|
def remove_ip(ip, interface)
|
81
|
-
$log.debug ssh("ip addr show #{interface} | grep #{ip} && sudo ip addr del #{ip} dev #{interface}")
|
80
|
+
$log.debug ssh("ip addr show #{interface} | grep #{ip} && sudo ip addr del #{ip}/32 dev #{interface}")
|
82
81
|
end
|
83
82
|
|
84
83
|
def slaveof(host)
|
@@ -107,6 +106,8 @@ class RedisMMM < Thor
|
|
107
106
|
cmd = "/usr/bin/ssh -p #{ssh_port} #{ssh_user}@#{address} \"#{command}\""
|
108
107
|
$log.debug "Executing #{cmd}"
|
109
108
|
`#{cmd}`
|
109
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
110
|
+
'unreachable'
|
110
111
|
end
|
111
112
|
|
112
113
|
end
|
@@ -293,10 +294,10 @@ class RedisMMM < Thor
|
|
293
294
|
return
|
294
295
|
end
|
295
296
|
|
296
|
-
$log.info "Changing master from #{@current_master.name} to #{host.name}"
|
297
|
+
$log.info "Changing master from #{@current_master ? @current_master.name : "NONE"} to #{host.name}"
|
297
298
|
|
298
299
|
# remove master ip from old master
|
299
|
-
remove_master_ip_from(@current_master)
|
300
|
+
remove_master_ip_from(@current_master) if @current_master
|
300
301
|
# add master ip to new master
|
301
302
|
add_master_ip_to(host)
|
302
303
|
# let new master stop replication
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-mmm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Siebert
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-12-22 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -70,7 +70,7 @@ extensions: []
|
|
70
70
|
extra_rdoc_files: []
|
71
71
|
|
72
72
|
files:
|
73
|
-
- README
|
73
|
+
- README.md
|
74
74
|
- bin/redis_mmm
|
75
75
|
has_rdoc: true
|
76
76
|
homepage: http://github.com/siebertm/redis-mmm
|
data/README
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
== Moving parts ==
|
2
|
-
|
3
|
-
* redis_mmm_mond
|
4
|
-
checks connection to all hosts
|
5
|
-
checks replication state
|
6
|
-
assigns roles
|
7
|
-
emits SLAVEOF commands
|
8
|
-
connects via ssh to hosts and assigns the role ip's
|
9
|
-
|
10
|
-
* redis_mmm_ctl
|
11
|
-
CLI
|
12
|
-
display cluster status
|
13
|
-
ability to change active master
|
14
|
-
|
15
|
-
|
16
|
-
Example configuration:
|
17
|
-
|
18
|
-
master_ip = 192.168.10.70/24
|
19
|
-
cluster_interface = eth1
|
20
|
-
|
21
|
-
[db1]
|
22
|
-
address = 127.0.0.1
|
23
|
-
port = 6380
|
24
|
-
ssh_user = admin
|
25
|
-
ssh_port = 22277
|
26
|
-
|
27
|
-
[db2]
|
28
|
-
address = 127.0.0.1
|
29
|
-
port = 6381
|
30
|
-
ssh_user = admin
|
31
|
-
ssh_port = 22277
|
32
|
-
|