同事问我如何在Linux下安装Memcache,并告诉我从昨天折腾到现在一直没有安装成功。以前记得安装Memcache时好像没有那么复杂,今天远程连接了他的机器看了下,开始先安装libevent,我怕他的版本太旧就给上传了个最新版本2.0,不过居然编译不通过,但是编译之前的1.4版本能通过。好了,先不纠结在这里,安装完libevent后,再次安装Memcach,执行:
./configure –prefix=/usr/local/memcached –with-event=/usr ---成功
make ---报出如下错误:
.deps/testapp.Tpo -c -o testapp.o testapp.c cc1: warnings being treated as errors testapp.c: In function `test_safe_strtoul': testapp.c:166: warning: decimal constant is so large that it is unsigned make[2]: *** [testapp.o] Error 1 make[2]: Leaving directory `/data/memcached-1.4.5' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/data/memcached-1.4.5' make: *** [all] Error 2
上网查找原因,最后找到如下解释:
(http://code.google.com/p/memcached/issues/detail?id=133)
Comment 2 by project member dorma...@rydia.net, Apr 22, 2010
That looks like RedHat enterprise linux version 3 (RHEL3)?
If so, we're sorry but the toolchains on there are simply too old to run a modern
version of memcached. You may try running a very old version of the 1.2 or 1.1
series, but we rely on C99 support now.
I'm assuming this from your kernel version, if this is wrong let us know.
Status: WontFix
Comment 3 by hzi...@gmail.com, Apr 26, 2010
Think you for your comments
Yes you 're right i succes to install memcached 1.4.5 when i changed my OS to Linux
2.6.18-8.el5PAE i686 athlon i3 86 GNU/Linux. The problem is that i get this error
when i try to get a value from my memcached <
net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for
operation - failing node: /xx.xxx.x.xx:11211 >>
指出导致这种错误的原因是Linux的内核版本过低,查了下朋友的linux内核版本,果真如此,是2.4,换成2.6就ok了。
附Memcache的安装步骤:
去官网下载libevent和Memcache
1.安装libevent:
# tar zxvf ibevent-2.0.10-stable.tar.gz
# cd ibevent-2.0.10-stable
# ./configure –prefix=/usr
# make
# make install
测试libevent是否安装成功:
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 Mar 24 20:09 libevent-2.0.so.5 -> libevent-2.0.so.5.0.1
-rwxr-xr-x 1 root root 943520 Mar 24 20:09 libevent-2.0.so.5.0.1
-rw-r--r-- 1 root root 1532186 Mar 24 20:09 libevent.a
lrwxrwxrwx 1 root root 26 Mar 24 20:09 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.0.1
-rwxr-xr-x 1 root root 554374 Mar 24 20:09 libevent_core-2.0.so.5.0.1
-rw-r--r-- 1 root root 927994 Mar 24 20:09 libevent_core.a
-rwxr-xr-x 1 root root 971 Mar 24 20:09 libevent_core.la
。。。
2.安装memcached,注意要指明libevent的位置
# tar zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure—prefix=/usr/local/memcached –with-libevent=/usr
# make
# make install
测试是否成功安装memcached:
# ls -al /usr/local/memcached/
total 24
drwxr-xr-x 5 root root 4096 Mar 24 20:58 .
drwxr-xr-x 27 root root 4096 Mar 24 20:11 ..
drwxr-xr-x 2 root root 4096 Mar 24 20:11 bin
drwxr-xr-x 3 root root 4096 Mar 24 20:11 include
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_core-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_extra-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_openssl-2.0.so.5.0.1
-rw-r--r-- 1 root root 0 Mar 24 20:58 libevent_pthreads-2.0.so.5.0.1
drwxr-xr-x 3 root root 4096 Mar 24 20:11 share
memcached的基本使用:
1.启动Memcache的服务器端:
# /usr/local/memcached/bin/memcached -d -m 100 -u root -l 192.168.1.131 -p 6717 -c 500 -P /tmp/memcached.pid
参数说明:
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,这里是100MB
-u是运行Memcache的用户,这里是root
-l是监听的服务器IP地址,这里指定服务器的IP地址192.168.1.131
-p是设置Memcache监听的端口,这里设置为6717,最好设置1024以上的端口
-c选项是最大运行的并发连接数,默认是1024,这里设置为500,要根据服务器的负载量来设定
-P是保存Memcache的pid文件,这里保存在 /tmp/memcached.pid
2.如何结束Memcache进程:
# kill `cat /tmp/memcached.pid`
关于Memcache的基本说明:Memcache是什么
Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。
它可以应对任意多个连接,使用非阻塞的网络IO。由于它的工作机制是在内存中开辟一块空间,然后建立一个HashTable,Memcached自管理这些HashTable。
为什么会有Memcache和memcached两种名称?
其实Memcache是这个项目的名称,而memcached是它服务器端的主程序文件名,知道我的意思了把~~~~。一个是项目名称,一个是主程序文件名,在网上看到了很多人不明白,于是混用了。
Memcache的安装
分为两个过程:memcache服务器端的安装和memcached客户端的安装。
所谓服务器端的安装就是在服务器(一般都是linux系统)上安装Memcache实现数据的存储
所谓客户端的安装就是指php(或者其他程序,Memcache还有其他不错的api接口提供)去使用服务器端的Memcache提供的函数,需要php添加扩展。