问题
I want to use Redis as distributed cache in my application. One of the demands is to have Active Active availability meaning that I have one data center in one place and another one somewhere else. If one data center fails I want my user to feel nothing and to be able to have all the data from the first data center in the second site and continue working - to have a master on the second site as well. Is it possible?
回答1:
You're asking for an Active-Active, a.k.a. multi master, solution but your question suggests you may not need it.
If you only require one of the databases to be available for writes, i.e. all writes always go it, you can achieve that with Redis's standard master-slave replication. Direct your application to use the master for writes and (potentially) have your slave serve some of the reads as well. If the master fails, promote the slave in the 2ndary DC to be the new master and redirect your application/clients to use it. Monitoring and promoting can be achieved with Redis' Sentinel.
There are a few things you'll have to take into consideration when implementing this type of setup. First note that Redis' replication is asynchronous so depending on your master's load, the volume of writes and the replication's network link quality, you could loose some of the recent updates in case of a failover. Secondly and on the same topic, an inter-DC network link could be prone to limited bandwidth and increased latency - you should configure Redis to handle this and perhaps use compression for that traffic (e.g. via an SSH tunnel). Lastly, to accurately detect failures you'll want to have at least 3 Sentinels in different locations. But despite these challenges, that's all doable.
That said, a multi master setup in which writes can be arbitrarily done against any database isn't supported by Redis at the moment. If that's actually what you need, consider using a different solution.
Note: depending on your exact requirements, if you can guarantee that writes to different DCs are mutually exclusive (i.e. each DC gets writes only to a distinct subset of keys that's not shared by the other DC), you can use two databases with a master in each DC and the slave in the other one.
来源:https://stackoverflow.com/questions/27232522/using-redis-replication-on-different-machines-multi-master