Rootop 服务器运维与web架构

Linux构建memcached加速web服务

| 暂无评论

libevent是一个事件触发的网络库,适用于windows、linux、bsd等多种平台,内部使用select、epoll、kqueue等系统调用管理事件机制。著名分布式缓存软件memcached也是libevent based,而且libevent在使用上可以做到跨平台,而且根据libevent官方网站上公布的数据统计,似乎也有着非凡的性能。

memcached官网下载:http://memcached.org/

[root@rhel6www ~]# rpm -qa | grep libevent
libevent-1.4.13-1.el6.i686

查看系统已经安装,但是在下面的编译过程中还需要libevent-devel,但是在rhel6.0以后没发现有此包,以后尽量使用centos,便于直接yum安装。
可以从http://rpm.pbone.net中寻找所需要的rpm包。
下载地址:
ftp://ftp.sunet.se/pub/Linux/distributions/scientific/6.0/i386/os/Packages/libevent-devel-1.4.13-1.el6.i686.rpm

这是编译memcached中出现的报错:
checking for libevent directory… configure: error: libevent is required.  You can get it from

http://www.monkey.org/~provos/libevent/

If it’s already installed, specify its path using –with-libevent=/dir/
这就是因为没有安装libevent-devel,安装,重新编译即可。

我这里将系统自带的libevent卸载,重新编译的。

[root@rhel6www ~]# wget -c https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
[root@rhel6www ~]#tar zxvf libevent-2.0.21-stable.tar.gz
[root@rhel6www ~]# cd libevent-2.0.21-stable
[root@rhel6www libevent-2.0.21-stable ~]# ./configure --prefix=/usr/local/libevent
[root@rhel6www libevent-2.0.21-stable ~]#make && make install
[root@rhel6www ~]# cd memcached-1.4.15
[root@rhel6www memcached-1.4.15]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
[root@rhel6www memcached-1.4.15]#make && make install
测试:
[root@rhel6www bin]# pwd
/usr/local/memcached/bin
[root@rhel6www bin]# ./memcached -d -u root -p 11211 -m 50 -P /tmp/memcached.pid

[root@rhel6www bin]# lsof -i:11211
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
memcached 21471 root   26u  IPv4  33972      0t0  TCP *:memcache (LISTEN)
memcached 21471 root   27u  IPv6  33973      0t0  TCP *:memcache (LISTEN)
memcached 21471 root   28u  IPv4  33976      0t0  UDP *:memcache
memcached 21471 root   29u  IPv6  33977      0t0  UDP *:memcache

已经运行了。

关闭进程:
[root@rhel6www ~]# kill -9 $(cat /tmp/memcached.pid)
加为开机启动,直接写到 /etc/rc.d/rc.local 即可。
可用参数:
-d 选项是启动一个守护进程
-m 是分配给Memcache使用的内存数量,单位是MB
-u 是运行Memcache的用户
-l 是监听的服务器IP地址
-p 是设置Memcache监听的端口
-c 选项是最大运行的并发连接数,默认是1024,按照服务器的负载设定
-P 是设置保存Memcache的pid文件

使用-h查看帮助。

然后编译memcache.so模块,加载到php中,参考:

https://www.rootop.org/pages/1662.html

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/1656.html

作者:Venus

服务器运维与性能优化

发表回复