I will not go into installing memcache and setting up multiple memcached instances on the same server but here are some guides if you need help with that.
I am currently placing memcache on the 2 apache nodes but keep in mind that the save paths are not weighted so the apache node will either go to the first or second node to look for the session. Do not put your application cache and session cache on the same instances!!
What to put in your moodle/config.php
// Memcache session handler (requires memcached server and memcache extension):
$CFG->session_handler_class = '\core\session\memcache';
$CFG->session_memcache_save_path = 'apache01.XXX.XXXX.com:11211,apache02.XXX.XXXX.com:11211';
$CFG->session_memcache_acquire_lock_timeout = 120;
What to put in your /etc/php.d/memcache.ini file:
memcache.allow_failover=1
memcache.session_redundancy=3
memcache.hash_strategy=consistent
Note: The integer will be the number of memcached instances + 1 for memcache.session_redundancy. If you use the count of memcache instances without +1 then you will get a redirect loop if one of the instances is unreachable (like the node went down).
restart memcached and apache.
Now test things out!
- Login to your Moodle instance on your browser.
- In command line on apache01: service memcached stop
- Navigate around your page. You are still logged in.
- In command line on apache01: service memcached start
- On your browser: refresh your page or navigate around. This is important as some kind of user action must occur for the session to be reloaded to the newly started instance!
- In command line on apache02: service memcached stop
- Navigate around your page. You are still logged in.
- In command line on apache02: service memcached start
- On your browser: refresh your page or navigate around.
So far I have not found any way to have it where a newly started memcache instance will contact the failover instances to reload the session/data. So if you restart one apache/memcached node, wait till it is back up, restart the other node, and a user has not done any action between the restarts he or she will be logged out!