Parsing Linux Install Memcacheq (MCQ) Full process notes

Source: Internet
Author: User
Tags message queue rar set time socket

Memcacheq is a simple distributed Message Queuing service.
first, the application background of Memcacheq
what is in Web applications
Would you need a message queue? The main reason is because in the high concurrency environment, because it is too late to synchronize, the request will often occur jams, for example, a large number of insert,update, such as requests to reach MySQL, directly lead to countless row lock table lock, or even the final request will accumulate too much, triggering too Manyconnections error. By using Message Queuing, we can handle requests asynchronously, thereby relieving system stress. In the Web2.0 era, high concurrency is becoming more common, which makes Message Queuing a must-have trend, and a number of implementations have emerged, like Twitter used RABBITMQ to implement Message Queuing services, and now instead use Kestrel to implement Message Queuing services, In addition, there are many other options, such as: Activemq,zeromq and so on.

Most of the above Message Queuing software has become extremely heavyweight in order to implement protocols such as AMQP,STOMP,XMPP, but in many Web applications the reality is that we just want to find a solution that alleviates high concurrent requests without the need for assorted functionality, A lightweight Message Queuing implementation is what we really need.

Second, the characteristics of Memcacheq
1 simple and easy to use
2 Fast processing speed
3-odd queues
4 Concurrency performance is good
5 is compatible with the Memcache protocol. This means that as long as the memcache extension can be installed, no additional plug-ins are required.

Third, install
Memcacheq relies on libevent and berkleydb.
Berkleydb the data used to persist the storage queue. So that when the Memcacheq crashes or the server hangs out,
Do not cause the loss of data. This is important and important.
Its installation relies on BerkeleyDB and libevent, so install the BerkeleyDB and Libevent first:
Where libevent if you have installed the memcached has been installed, if not sure, check it

1. Check libevent First, Libevent-devel is installed: rpm-qa|grep libevent output must contain libevent, Libevent-deve, if missing, Install using the following command:
yum install libevent yum
Install libevent-devel
considerations: libevent, Libevent-devel priority to use the Yum installation source, CD-ROM image of the RPM package installation, so that stability and compatibility can be guaranteed, online use of the source code installed Libevent method will have problems, because it is likely that the system has been installed Libevent, and then use the source code installation, Inevitably lead to conflict, causing unexpected problems, so be sure to use the above command to check whether the system has installed the appropriate library

2. Install berkleydb
1.tar zxvf bdb-5.3.3.tar.gz
2.cd db-5.3.3/
#需要进入特定操作系统编译环境, The compilation of more conventional software is somewhat different from
3.cd build_unix/
4 ... /dist/configure--prefix=/usr/local/berkeleydb
#如果没有指定特殊安装路径, the compilation completes, and the path to the Berkeley DB Runtime needs to be added to the system configuration
Echo/usr/ local/berkeleydb.5.3/lib/">>/etc/ld.so.conf
#重载系统Ld运行库
Ldconfig
5. Make & make install
Remember to change/e tc/ld.so.conf file, add/usr/local/berkeleydb.5.3/lib Ah, or the following MCQ will install errors.
and BerkeleyDB is going to download the
click Download Berkeley DB 5.3.21.rar
install Memcacheq below,
first download a Memcacheq-0.2.0.rar
extract, into directory
./configure–with-bdb=/usr/local/berkeleydb.5.1–with-libevent=/usr/local/lib–enable-threads
Make
Make install
key is the red font that step, must be entered correctly, otherwise make does not pass, cannot install

The following is the start
memcacheq-d-r-u root-p21201-h/data/memcacheq-n-v-l 1024-b 1024 >/data/mq_error . log 2>&1
The root user is not recommended here, some posts say no, I can test here, but it may not be safe.
1 The following is the parameter at startup
to view command-line options
2 using the memcacheq-h command the correct startup memcacheq:memcacheq-d-uroot-r-p1121 2-h/home/wwwroot/mcq-n-r-v L 1024-b 1024 >/home/wwwlogs/mq_error.log 2 > &1
3 This doesn't know why. No,/usr/local/memcacheq/bin/memcacheq-d-l 127.0.0.1-a 8192-h/data/memcacheq-b 65535-n-r-u root
-P <n Um> 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> Listening network adapter
-D Daemon
-r maximize core file limit
-u <USERNAME&G T Run as user (only when run as root)
-C <num> Maximum number of concurrent connections (default is 1024)
-v Verbose output (print errors/warnings while in Eve NT loop)
-VV more verbose output (also print client commands/reponses)
-i print license information
-P <file> pid file
-T <num> thread count (default 4)
--------------------BerkeleyDB Options-------------------------------
-M <num> berkeleydb memory cache size, default is 64MB
-A <num > Bottom 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, the default is 5 minutes
-T <nu M> How many seconds Memp_trickle once, 0 for disable, default is seconds
-s <num> how many seconds queue stats dump once, 0 for disable, def Ault is seconds
-e <num> The amount of cache required to be refreshed, the default is 60%
-e <num> How many pages a single DB file has, the default is 16*1024, 0 for Disable
-b <num> Specify the length of the message body, Unit bytes, default is 1024
-D <num> How many milliseconds to do deadlock detection (deadlock detecting), 0 for Disable, the default is 100ms
-N opens Db_txn_nosync for significant performance improvements, the default is off
-R automatically deletes log files that are no longer needed, default is off
test

Third, testing
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 the set time to fill the successful not_stored, check your start command bar, parameters are not set, if you are novice, dry cui more than a few posts, try to start the command, change the parameters, on the line

Four, use
after using the above command to start MQ, (note that the-b parameter above indicates that the body length of messag cannot exceed 1024 bytes), only two commands are required to use MQ: Set and get:
Set <queue name> <flags> 0 <message_len>rn
<put your message body HERE>RN
Storedrn
Get <queue Name>rn
VALUE <queue name> <flags> <message_len>rn
<your message body would come HERE>RN
Endrn
As you can see, the Memcache protocol is basically consistent, except that the key name is changed to queue name, and the Expire_time parameter is ignored in the set's command. After all, MQ data storage exists in BerkeleyDB, does the persistent storage, has no memory expiration time.
When the set command is used, a new message is written to the specified message queue, which is to insert a new data into the BerkeleyDB, and when the Get command is used, a new message is removed from the specified queue, that is, a data is delete from the berkeleydb. When you use stats to view a specified queue, you can see how many messages the queue received, and how many were taken out of it.
Example:

Copy Code code 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 above executed two sets of commands, using the Stats queue view, you can see Q4 queue 2, has been removed 0; When you use get to remove the first, then use the stats queue to view, Q4 message has 2, which has been removed 1.
PHP Test:

Copy Code code as follows:


session_start ();


$memcache _obj = new Memcache;


$memcache _obj-&gt;connect (' 127.0.0.1′, 11212) or Die ("error");


Memcache_set ($memcache _obj, ' K ', 10, 0, 0);


echo "Queue". Memcache_get ($memcache _obj, ' K ');


memcache_close ($memcache _obj);


Note:
This is the kind of problem that comes up.
Memcacheq:error while loading shared libraries:libdb-5.0.so:cannot open Shared object file:no such file or directory
Solution: Build a libdb-5.0.so soft chain under the/usr/lib, OK.
Ln-s/usr/local/berkeleydb.5.0/lib/libdb-5.0.so/usr/lib/ Five, close Memcacheq
Use the PS command to check the MEMCACHEQ process: Ps-ef|grep wuf, and then 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.