Complete process notes for installing memcacheq (mcq) in linux

Source: Internet
Author: User

MemcacheQ is a pure distributed Message Queue Service.
I. application background of MEMCACHEQ
What is Web Application
Will a Message Queue be required? The main reason is that in highly concurrent environments, requests are often blocked due to the lack of synchronization processing. For example, a large number of insert and update requests reach mysql at the same time, it directly leads to numerous row lock table locks, and even the last request will accumulate too much, triggering the too manyconnections error. By using message queues, we can process requests asynchronously to relieve system pressure. In the era of web, high concurrency is becoming more and more common, so that message queues have become an essential trend, and many implementation solutions have emerged, for example, Twitter used RabbitMQ to implement the Message Queue Service before, and now uses Kestrel to implement the Message Queue Service. In addition, there are many other options, such as ActiveMQ and ZeroMQ.

Most of the above message queue software has become extremely heavyweight in order to implement protocols such as AMQP, STOMP, and XMPP, but the actual situation in many Web applications is: we just want to find a solution to alleviate high-concurrency requests, without the need for miscellaneous functions. A lightweight Message Queue implementation method is what we really need.

Ii. Features of MEMCACHEQ
1. Easy to use
2. fast processing
3 + queues
4. Good concurrency Performance
5. compatible with the memcache protocol. This means that only the extension of memcache can be installed, and no additional plug-ins are required.

Iii. Installation
MEMCACHEQ depends on libevent and BerkleyDB.
BerkleyDB is used to persistently store data in a queue. In this way, when MEMCACHEQ crashes or the server crashes,
This prevents data loss. This is important.
Its Installation depends on BerkeleyDB and libevent. Therefore, you must first install the BerkeleyDB and libevent:
Here, libevent has been installed if you have installed memcached. If you are not sure, check it.

1. First check whether libevent and libevent-devel have been installed:Rpm-qa | the grep libevent output must contain libevent and libevent-deve. If the output is missing, run the following command to install it:
Yum install libevent yum
Install libevent-devel
Note:Libevent and libevent-devel use the yum installation source first and install the rpm package in the CD image to ensure stability and compatibility. problems may occur when the source code is circulated on the Internet to install libevent, it is very likely that the system has already installed libevent, and then installed with the source code will inevitably lead to conflicts and cause unexpected problems. Therefore, you must use the above command to check whether the system has installed the corresponding Library

2. Install BerkleyDB
1. tar zxvf bdb-5.3.3.tar.gz
2. cd db-5.3.3/
# You need to enter the compiling environment of a specific operating system. There are some differences in the compilation of more general software.
3. cd build_unix/
4 ../dist/configure -- prefix =/usr/local/berkeleydb
# If no special installation path is specified and compilation is complete, add the path of the Berkeley Db Runtime Library to the system configuration.
Echo "/usr/local/BerkeleyDB.5.3/lib/">/etc/ld. so. conf
# Reload the system Ld Runtime Library
Ldconfig
5. make & make install
Remember to change the/etc/ld. so. conf file and add/usr/local/BerkeleyDB.5.3/lib. Otherwise, mcq will be installed incorrectly.
BerkeleyDB is about to download
Click to download Berkeley DB 5.3.21.rar
Install memcacheq below,
Download oneMemcacheq-0.2.0.rar
Decompress and enter the Directory
./Configure-with-bdb =/usr/local/BerkeleyDB.5.1-with-libevent =/usr/local/lib-enable-threads
Make
Make install
The key is the step of the red font. It must be entered correctly. Otherwise, make will fail and cannot be installed.

Below is the startup
Memcacheq-d-r-u root-p21201-H/data/memcacheq-N-v-L 1024-B 1024>/data/mq_error.log 2> & 1
Root users are not recommended here. Some posts say no. I can test it here, but it may be insecure.
1. The following parameters are used at startup.
Run the memcacheq-h command to view the command line options.
2. It is correct to start memcacheq: memcacheq-d-uroot-r-p000012-H/home/wwwroot/mcq-N-R-v-L 1024-B 1024>/home/wwwlogs/mq_error.log 2> & 1
3. I don't know why./usr/local/memcacheq/bin/memcacheq-d-l 127.0.0.1-A 8192-H/data/memcacheq-B 65535-N-R-u root
-P <num> TCP listening port (default: 22201)
-U <num> UDP listening port (default: 0, off)
-S <file> unix socket path (network not supported)
-A <mask> unix socket access mask (default 0700)
-L <ip_addr> listens to NICs
-D daemon
-R: Limits on maximizing core files
-U <username> run as user (only when run as root)
-C <num> maximum number of concurrent connections (default is 1024)
-V detailed output (print errors/warnings while in event loop)
-Vv more detailed output (also print client commands/reponses)
-I print license information
-P <file> PID file
-T <num> Number of threads (default 4)
 -------------------- BerkeleyDB Options -------------------------------
-M <num> BerkeleyDB memory cache size, default is 64 MB
-A <num> underlying page size, default is 4096, (512B ~ 64KB, power-of-two)
-H <dir> Database Home Directory, default is '/data1/memcacheq'
-L <num> log buffer size, default is 32KB
-C <num> how many seconds checkpoint once, 0 for disable, default is 5 minutes
-T <num> how many seconds memp_trickle once, 0 for disable, default is 30 seconds
-S <num> how many seconds queue stats dump once, 0 for disable, default is 30 seconds
-E <num> indicates the number of times the cache reaches. Refresh is required. default is 60%.
-E <num> how many pages does a single DB file have? default is 16*1024, 0 for disable
-B <num> specifies the length of the message body, in bytes. default is 1024
-D <num> How many milliseconds to perform a deadlock Detection (deadlock detecting), 0 for disable, default is 100 ms
-N enable DB_TXN_NOSYNC to achieve great performance improvement. default is off.
-R automatically deletes log files that are no longer needed, default is off
Test

Iii. Test
1. telnet 10.218.31.121 22201.
2. stats
2. stats queue
3. set q4 0 0 5
4 hello
5 get q4
6 stats queue
7 delete q4
If not_STORED is successfully completed during set, check your startup command. The parameters are not set. If you are a newbie, Gan Cui will read several more posts and try to start more commands, just change the parameter.

4. Use
After using the preceding command to start mq, (note that the length of the body of messag cannot exceed 1024 bytes). When using mq, you only need to use two Commands: set and get:
Set <queue name> <flags> 0 <message_len> \ r \ n
<Put your message body here> \ r \ n
STORED \ r \ n
Get <queue name> \ r \ n
VALUE <queue name> <flags> <message_len> \ r \ n
<Your message body will come here> \ r \ n
END \ r \ n
As you can see, the memcache protocol is basically the same, but the key name is changed to the queue name, And the expire_time parameter is ignored in the set command. After all, mq data storage is stored in the berkeleyDB and is stored persistently without memory expiration time.
When the set command is used, a new message is written to the specified message queue, that is, a new data is inserted into the BerkeleyDB. When the get command is used, A new message is taken from the specified queue, that is, a data record is deleted from the BerkeleyDB. When you use stats to view a specified queue, you can see how many and how many messages are received in the queue.
Example:

Copy codeThe Code is as follows: fengbo @ onlinegame-10-121 :~ $ Telnet 127.0.0.1 22202
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Set q4 0 0 5
Hello
STORED
Set q4 0 0 5
World
STORED
Stats queue
STAT q4 2/0
END
Get q4
VALUE q4 0 5
Hello
END
Stats queue
STAT q4 2/1
END

The set command is executed twice. When you use stats queue to view messages, you can see that there are two messages in the q4 queue and 0 messages have been taken out. When you use get to retrieve the first message, use stats queue to view the message. There are two messages in q4, of which one has been taken out.
PHP testing:Copy codeThe Code is as follows: session_start ();
$ Memcache_obj = new Memcache;
$ Memcache_obj-> connect ('192. 0.0.1 ', 127) or die ("error ");
Memcache_set ($ memcache_obj, 'k', 10, 0, 0 );
Echo "queue". memcache_get ($ memcache_obj, 'k ');
Memcache_close ($ memcache_obj );

Note:
This problem may occur at this time.
Memcacheq: error while loading shared libraries: libdb-5.0.so: cannot open shared object file: No such file or directory
Solution: in/usr/lib to build a libdb-5.0.so soft chain on OK
Ln-s/usr/local/BerkeleyDB.5.0/lib/libdb-5.0.so/usr/lib/

5. Disable memcacheQ.
Run the ps command to check the memcacheQ process: ps-ef | grep wuf, and kill the process directly.

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.