memcached High-Availability Act for persistent session connections

Source: Internet
Author: User

For the session persistent connection, most of us use memcached as the cache server. But it is well known that memcached has the risk of a single point of failure. A brief description of the last company update code for this issue:

The early hours of development executed several SQL statements followed by updated code. The test encountered a problem when verifying the payment. Is that we have entered a verification code when the user wants to log in. Hundred percent confirmed that there is no wrong, but is not even, after a while good. Busy for a long day. Think it is not the problem of the session, originally there is memcached temporary information, but memcached there is a problem. Read directly from the back-end database and read the new data. Then re-make a memcached, verify that there is no problem. (But I do not understand that is to join the definition of the growth factor is not caused, memcached not enough, supposedly memcached should be full of automatic cleaning, unless the growth factor is too large, and the data is too high, but this is resolved, I do not understand the idea of hope that you can advise)

So I think memcached high availability is still necessary, after reviewing the document, the following environment is built:

I. Environment description (use repcached to copy the memcached value):

memcached Master: 192.168.63.129 centos64

Memcached from: 192.168.63.132 contos64

Second, installation steps:

1, generally based on the things we will install Libevent:

[Email protected] libevent-1.4.14b-stable]#/configure--PREFIX=/USR

[[email protected] libevent-1.4.14b-stable]# make && make install

2, installation memcached:

[Email protected] memcached-1.4.20]#/configure--WITH-LIBEVENT=/USR

[[email protected] memcached-1.4.20]# make && make install

3, installation repcached:

[[email protected] src] # wget http://downloads.sourceforge.net/repcached/memcached-1.2.8-repcached-2.2.tar.gz [[email protected] src] # tar zxf memcached-1.2.8-repcached-2.2.tar.gz [[email protected] src] # cd memcached-1.2.8-repcached-2.2

[[email protected] memcached-1.2.8-repcached-2.2] # wget http://downloads.sourceforge.net/repcached/repcached-2.2-1.2.8.patch.gz

[[email protected] memcached-1.2.8-repcached-2.2] # gzip -cd ../repcached-2.2-1.2.8.patch.gz | patch -p1 [[email protected] memcached-1.2.8-repcached-2.2] # ./configure --enable-replication [[email protected] memcached-1.2.8-repcached-2.2] #  make [[email protected] memcached-1.2.8-repcached-2.2] #  make install [[email protected] memcached-1.2.8-repcached-2.2] # cd ..

#主和从的安装步骤是一样的, this is done only on the master node:

Iv. startup settings Master and slave:

1. Start Master:

[Email protected] ~]# memcached-v-d-p 11211-l 192.168.63.129-u root-p/tmp/memcached1.pid

[Email protected] ~]# Replication:listen

2. Start Backup:

[Email protected] ~]# memcached-v-d-p 11211-l 192.168.63.132-u root-x 192.168.6

3.129-p/tmp/memcached1.pid

[Email protected] ~]# Replication:connect (peer=192.168.63.129:11212)

3. To see if the master is connected successfully:

[Email protected] ~]# Replication:listen

Replication:accept #accept已经是master

Five, test:

1. The primary node inserts data:

[[Email protected] ~]# telnet 192.168.63.129 11211

Trying 192.168.63.129 ...

Connected to 192.168.63.129.

Escape character is ' ^] '.

Set Key 0 0 2

Xi

STORED

Quit

Connection closed by foreign host.

2. View from node:

[[Email protected] ~]# telnet 192.168.63.132 11211

Trying 192.168.63.132 ...

Connected to 192.168.63.132.

Escape character is ' ^] '.

Get key

VALUE Key 0 2

Xi

END

3, disconnect the master node, automatically listen from the node, and then rise to the main node.

[Email protected] ~]# Ps-ef | grep memcached | awk ' {print $} ' | Xargs kill-9

Kill 2222:no Such process

From node to listener State:

[Email protected] ~]# Replication:close

Replication:listen

4. Login Node Test:

[[Email protected] ~]# telnet 192.168.63.132 11211

Trying 192.168.63.132 ...

Connected to 192.168.63.132.

Escape character is ' ^] '.

Get key

VALUE Key 0 2

Xi

END

The data is completely copied over.

5, the principle of the main node repair, we start it. Make him from the node *

[Email protected] ~]# memcached-v-d-p 11211-l 192.168.63.129-u root-x 192.168.63.132-p/tmp/memcached.pid

[Email protected] ~]# Replication:connect (peer=192.168.63.132:11212)

Replication:marugoto copying

Replication:start

Now 129 up from the node. Log in and see if the data is copied. No:

[[Email protected] ~]# telnet 192.168.63.129 11211

Trying 192.168.63.129 ...

Connected to 192.168.63.129.

Escape character is ' ^] '.

Get key

VALUE Key 0 2

Xi

END

Here you can see that the data is fully recovered. You can see that this is almost consistent with MySQL master-slave synchronization steps.

This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1595971

memcached High-Availability Act for persistent session connections

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.