Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,libevent的最新版本是libevent-1.3。(如果你的系统已经安装了libevent,可以不用安装)
下载:http://www.monkey.org/~provos/libevent-1.3.tar.gz
下载:http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
1.先安装libevent。这个东西在配置时需要指定一个安装路径,即./configure –prefix=/usr/local/libevent/ (./configure --prefix=/home/admin/edu-cms/cache/libevent );然后make;然后make install;
2.再安装memcached,只是需要在配置时需要指定libevent的安装路径即
./configure --with-libevent=/usr/local/libevent
(./configure --prefix=/home/admin/edu-cms/cache/memcached --with-libevent=/home/admin/edu-cms/cache/libevent)
然后make;然后make install;
这样就完成了Linux下Memcache服务器端的安装。
如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。
安装完成后会memcached的工作目录是/usr/local/memcached/
检查服务:
1、查看启动的memcache服务:
netstat -lp | grep memcached
2、查看memcache的进程号(根据进程号,可以结束memcache服务:“kill -9 进程号”)
ps -ef | grep memcached
memcached的基本设置:
1.启动Memcache的服务器端:
# /usr/local/memcached/bin/memcached -d -m 10 -u root -l 10.0.0.204 -p 12000 -c 256 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.51.207,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,
2.如果要结束Memcache进程,执行:
# kill `cat /tmp/memcached.pid`
也可以启动多个守护进程,不过端口不能重复。
最后,设置下开始启动:
#echo "/usr/local/memcached/bin/memcached -d -m 10 -u root -l 10.0.0.204 -p 12000 -c 256 -P /tmp/memcached.pid" >> /etc/rc.local
启动memcache可能会发生的问题:
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file
#一般对于这种依赖的库找不到的情况,在linux中可以通过设置LD_DEBUG环境变量来获得更多的信息
#LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are:
libs display library search paths
reloc display relocation processing
files display progress for input file
symbols display symbol table processing
bindings display information about symbol binding
versions display version dependencies
all all previous options combined
statistics display relocation statistics
unused determined unused DSOs
help display this help message and exit
To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.
#这里由于是库文件依赖有问题,则使用libs参数
#LD_DEBUG=libs /usr/local/memcached/bin/memcached -h
13293: find library=libevent-2.0.so.5 [0]; searching
13293: search cache=/etc/ld.so.cache
13293: search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/l)
13293: trying file=/lib/tls/i686/sse2/libevent-2.0.so.5
13293: trying file=/lib/tls/i686/libevent-2.0.so.5
13293: trying file=/lib/tls/sse2/libevent-2.0.so.5
13293: trying file=/lib/tls/libevent-2.0.so.5
13293: trying file=/lib/i686/sse2/libevent-2.0.so.5
13293: trying file=/lib/i686/libevent-2.0.so.5
13293: trying file=/lib/sse2/libevent-2.0.so.5
13293: trying file=/lib/libevent-2.0.so.5
13293: trying file=/usr/lib/tls/i686/sse2/libevent-2.0.so.5
13293: trying file=/usr/lib/tls/i686/libevent-2.0.so.5
13293: trying file=/usr/lib/tls/sse2/libevent-2.0.so.5
13293: trying file=/usr/lib/tls/libevent-2.0.so.5
13293: trying file=/usr/lib/i686/sse2/libevent-2.0.so.5
13293: trying file=/usr/lib/i686/libevent-2.0.so.5
13293: trying file=/usr/lib/sse2/libevent-2.0.so.5
13293: trying file=/usr/lib/libevent-2.0.so.5
/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
#可以看到在加载/usr/lib/libevent-2.0.so.5文件时出现了问题,先在系统中查找该文件
#find /usr/ -name " libevent-2.0.so*"
/usr/local/libevent/lib/libevent-2.0.so.5
/usr/local/libevent/lib/libevent-2.0.so.5.0.1
#通过查找发现在/usr/local/libevent/lib目录下有该文件,通过软链接方式可以解决
# ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5