1.安装

先安装 libevent(memcached depended)
下载libevent-1.3b.tar.gz 后解压:
tar -zxvf libevent-1.3b.tar.gz
cd libevent-1.3b
./configure && make
make install
make verify //验证安装
下载memcached-1.2.6.tar.gz
tar -zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure && make
make install

2.How it Works

First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you'll likely use:

# ./memcached -d -m 2048 -l 10.0.0.40 -p 11211

This starts memcached up as a daemon, using 2GB of memory, and listening on IP 10.0.0.40, port 11211. Because a 32-bit process can only address 4GB of virtual memory (usually significantly less, depending on your operating system), if you have a 32-bit server with 4-64GB of memory using PAE you can just run multiple processes on the machine, each using 2 or 3GB of memory.

eg:

/usr/local/bin/memcached -m 64m -l 127.0.0.1 -p 11211 -d -u root -P /var/run/memcached.pid -c128 -vv

注意:如果 -l 为127.0.0.1则只能在localhost访问memcache,如果想让其他ip的访问,-l需要设置为其实际的ip

选项

说明

-p

使用的TCP端口。默认为11211

-m

最大内存大小。默认为64M

-vv

用very vrebose模式启动,调试信息和错误输出到控制台

-d

作为daemon在后台启动

-c

最大运行的并发连接数,默认是1024,按照服务器的负载量来设定

-P

设置保存Memcache的pid文件

-l

监听的服务器IP地址,如果有多个地址的话

-u

运行Memcache的用户,默认不能用root启动,所以当前用户为root用户时,需要用-u参数来指定

更多的参数可以 /usr/local/bin/memcached -h 查看

关闭kill 'cat /var/run/memcached.pid'

3.问题解决

如果遇到 memcached:error while loading shared libraries:libevent-1.3b.so.1:cannot open shared object file:No such file or directory.

使用 LD_DEBUG=libs /usr/local/bin/memcached -v 查看其启动的时候,加载lib情况;具体的不列出;

执行:ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1问题可以解决;