Home > Article > Backend Development > Analysis of notes on the entire process of installing memcacheq (mcq) under Linux_PHP tutorial
memcacheQ是一个单纯的分布式消息队列服务。
一,MEMCACHEQ的应用背景
Web应用中为什
么会需要消息队列?主要原因是由于在高并发环境下,由于来不及同步处理,请求往往会发生堵塞,比如说,大量的insert,update之类的请求同时到达mysql,直接导致无数的行锁表锁,甚至最后请求会堆积过多,从而触发too manyconnections错误。通过使用消息队列,我们可以异步处理请求,从而缓解系统的压力。在Web2.0的时代,高并发的情况越来越常见,从而使消息队列有成为居家必备的趋势,相应的也涌现出了很多实现方案,像Twitter以前就使用RabbitMQ实现消息队列服务,现在又转而使用Kestrel来实现消息队列服务,此外还有很多其他的选择,比如说:ActiveMQ,ZeroMQ等。
上述消息队列的软件中,大多为了实现AMQP,STOMP,XMPP之类的协议,变得极其重量级,但在很多Web应用中的实际情况是:我们只是想找到一个缓解高并发请求的解决方案,不需要杂七杂八的功能,一个轻量级的消息队列实现方式才是我们真正需要的。
二,MEMCACHEQ的特性
1 简单易用
2 处理速度快
3 多条队列
4 并发性能好
5 与memcache的协议兼容。这就意味着只要装了memcache的extension就可以了,不需要额外的插件。
三,安装
MEMCACHEQ依赖于libevent和BerkleyDB。
BerkleyDB用于持久化存储队列的数据。 这样在MEMCACHEQ崩溃或者服务器挂掉的时候,
不至于造成数据的丢失。这一点很重要,很重要。
它的安装依赖于BerkeleyDB 和 libevent,所以要先安装这BerkeleyDB和libevent:
其中libevent如果你安装过memcached就已经安装了,如果不确定,就检查一下吧
1. 先检查libevent, libevent-devel是否已经安装: rpm -qa|grep libevent 输出中必须包含libevent, libevent-deve, 如果缺失,使用以下命令安装:
yum install libevent yum
install libevent-devel
注意事项:libevent, libevent-devel优先使用yum安装源,光盘镜像中的rpm包安装,这样稳定性和兼容性可得到保证,网上流传的使用源码安装libevent的方法会有问题,因为很可能系统已经安装libevent, 再使用源码安装, 必然导致冲突,造成意外问题,所以一定要使用上述命令检查系统是否已经安装相应的库
2. 安装BerkleyDB
1.tar zxvf bdb-5.3.3.tar.gz
2.cd db-5.3.3/
#需要进入特定操作系统编译环境,更常规软件的编译有些区别
3.cd build_unix/
4. ../dist/configure --prefix=/usr/local/berkeleydb
#如果没有指定特殊安装路径,编译完成,需要将Berkeley Db运行库的路径添加到系统配置里面
echo "/usr/local/BerkeleyDB.5.3/lib/" >> /etc/ld.so.conf
#重载系统Ld运行库
ldconfig
5. make & make install
记得改/etc/ld.so.conf文件,添加/usr/local/BerkeleyDB.5.3/lib啊,不然后面的mcq会安装错误。
而BerkeleyDB就要去下载了
点击下载Berkeley DB 5.3.21.rar
下面安装memcacheq,
先下载一个memcacheq-0.2.0.rar
解压,进目录
./configure –with-bdb=/usr/local/BerkeleyDB.5.1 –with-libevent=/usr/local/lib –enable-threads
make
make install
关键是红色字体那一步,一定输入正确,不然make不通过,无法安装
The following is startup
memcacheq -d -r -u root -p21201 -H /data/memcacheq -N -v -L 1024 -B 1024 > /data/mq_error.log 2> ;&1
It is not recommended to use the root user here. Some posts say it is not possible. I tested it here and it is OK, but it may be unsafe.
1 The following are the parameters at startup
Use the memcacheq -h command to view the command line options
2 This is the correct way to start memcacheq: memcacheq -d -uroot - r -p11212 -H /home/wwwroot/mcq -N -R -v -L 1024 -B 1024 > /home/wwwlogs/mq_error.log 2 > &1
3 I don’t know about this Why not /usr/local/memcacheq/bin/memcacheq -d -l 127.0.0.1 -A 8192 -H /data/memcacheq -B 65535 -N -R -u root
-p
-s
-a
-l
-d daemon
-r Maximize core file limit
-u
-c
-v Verbose output (print errors/warnings while in event loop)
- vv More detailed output (also print client commands/reponses)
-i Print license information
-P
-t
--------------------------BerkeleyDB Options-------------------------- -------
-m
-A
-H
-L
-C < num> How many seconds to checkpoint once, 0 for disable, default is 5 minutes
-T
-S
-e
-E
-B
-D
-N Turn on DB_TXN_NOSYNC to get huge performance improvements, default is off
-R Automatically delete log files no longer needed, default is off
Test
3. 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 successful during set, check your startup command. The parameters are not set properly. If you are a novice, Gan Cui Read a few more posts, try more startup commands, change the parameters, and it will be fine
Fourth, use
to start mq using the above command (note that the -B parameter above indicates that the body length of the message cannot exceed 1024 bytes), only two commands are needed when using mq :set and get:
set
STOREDrn
get
VALUE
ENDrn
As you can see, it is basically the same as the memcache protocol, except that The key name is replaced with the queue name, and the expire_time parameter is ignored in the set command. After all, mq's data storage is stored in BerkeleyDB, which is a persistent storage and has no memory expiration time.
When the set command is used, a new message is written to the specified message queue, that is, a new piece of data is inserted into BerkeleyDB. When the get command is used, a new message is taken out from the specified queue. That is, a piece of data is deleted from BerkeleyDB. When you use stats to view a specified queue, you can see how many messages the queue has received and how many have been taken out.
Example:
Fifth, close memcacheQ
Use the ps command to check the memcacheQ process: ps -ef|grep wuf, and then kill the process directly.