D
D
Dmitry Labutin2013-07-03 10:54:29
PHP
Dmitry Labutin, 2013-07-03 10:54:29

How to properly build a memcached failover cluster to store PHP sessions?

There are many articles on how to store PHP sessions well in memcached. This is exactly where we are going.
But I have not found a sane answer to the following question: How to properly organize the infrastructure so that it is fault-tolerant in the event of a crash of one of the servers on which memcached is running?
Obviously we need to have at least two memcached servers. Let's immediately complicate the task - we will set up 5 of them.
Let's assume that the session stores the ID of the logged in client. If the session dies/disappears/is erased, the client is not recognized by the server, i.e. The client logs out and has to re-authorize.
Goal (I remind you that we have 5 memcached servers): in the event of a failure of up to 4 memcached servers, clients should not experience difficulties with authorization.
Now I will state the course of my thoughts, and you, please, correct me and direct me to the true path
:) the system must continue to function even when only one (any of the 5) memcached servers is running, which means that the data stored in them must be duplicated.
Question: How to achieve this?
Rummaged with memcached and found interesting keys:
-x <ip_addr> hostname or IP address of peer repcached
-X <num:num> TCP port number for replication. <listen:connect> (default: 11212)
I even set up two memcached servers this way. -x set them to point to each other. And indeed - you can write the key to one server, and get the value from another. Haven't tested how fast replication is, but it does work.
Thus the task for two servers is solved simply.
But what if there are more than two servers? Building a chain? The first points to the second, the second to the third, and so on. But after all, if the second one falls, then the first one will not know anything about the third?
This is where I got stuck :)
Maybe I'm digging in the wrong direction?
Let me remind you that the goal is the following: to store PHP sessions on several memcached servers, so that even if only one of them remains alive, not a single session is lost.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
K
KEKSOV, 2013-07-03
@KEKSOV

Handlersocket for MySQL is faster than memcache. We use Galera Cluster for MySQL for data replication and get the required productive failover cluster.

N
Nikolai Vasilchuk, 2013-07-03
@Anonym

Why not try Redis?

L
luckyredhot, 2013-07-03
@luckyredhot

No way, except to duplicate data to different servers at the application level.
Or use another product (fortunately, sea alternatives).
Read here .

S
script88, 2013-07-03
@script88

www.kutukupret.com/2011/06/14/memcached-replication-on-server-clusters/

U
UUSER, 2013-07-03
@UUSER

www.couchbase.com

A
Alexey Zhurbitsky, 2013-07-03
@blo

There is a wonderful series of articles on memcached on Habré ( 1 , 2 , 3 , 4 , 5 , 6 ), among them there is also about building a failover cluster .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question