日期:2014-05-16 浏览次数:20739 次
一、准备工作:
??? 1.下载libevent:http://monkey.org/~provos/libevent/ (由于memcached与客户端的通信是借助libevent来实现的,所以此动作必须在memcached安装前完成)
??? 2.下载memcached:http://memcached.org/ (注意:memcache是由服务器端和客户端共同组成,此处指memcache的服务器端,客户端在memcache的官网也提供了下载地址)
?
二、libevent安装:
??? 1.解压libevent安装包:
??? shell > tar zxvf libevent-2.0.10-stable.tar.gz
??? 2.进入解压后的目录并执行如下命令:
??? shell > ./configure (或./configure --prefix=libevent安装目录,默认安装目录为/usr/local/lib)
??? shell > make && make install
??? 3.查看安装是否成功
??? 测试libevent是否安装成功:ls -al /usr/lib | grep libevent(或 ls -al /usr/local/lib | grep libevent)
????
??? 4.Now we need to update /etc/ld.so.conf.d/libevent-i386.conf to add the path information for libevent. Use your favorite editor to edit /etc/ld.so.conf.d/libevent-i386.conf and add the following line if it doesn’t exist:
/usr/local/lib/,and then run ldconflg
??? 注意:向libevent-i386.conf中添加的是libevent库的安装目录(如:/usr/local/lib);ldconfig是一个动态链接库管理命令
?
三、Memcached安装:
??? 1.解压memcached安装目录:
??? shell > tar zxvf memcached-1.4.5.tar.gz
??? 2.进入解压后的目录并执行如下命令:
??? shell > ./configure (或./configure --with-libevent=libevent安装目录
--prefix=memcached安装目录,默认安装在/usr/local/bin目录下)
??? shell > make && make install
??? 3.测试memcached安装是否成功:
??? shell > memcached -u root -vv后出现如下画面则说明成功:
???
?
四、配置memcached自启动
??? 1.编写memcached自启动脚本或直接使用memcached安装包中的脚本(位置如下,本文使用官方自带的脚本)
???
??? 2.修改自启动脚本(红色部分标识)
#! /bin/sh # # chkconfig: - 55 45 # description:? The memcached daemon is a network memory cache service. # processname: memcached # config: /etc/sysconfig/memcached # Source function library. . /etc/rc.d/init.d/functions PORT=11211 USER=root MAXCONN=1024 CACHESIZE=64 OPTIONS="" if [ -f /etc/sysconfig/memcached ];then ??? . /etc/sysconfig/memcached fi # Check that networking is up. if [ "$NETWORKING" = "no" ] then ??? exit 0 fi RETVAL=0 start () { ??? echo "Starting memcached ..." ??? # insure that /var/run/memcached has proper permissions ??? chown $USER /usr/local/bin/memcached ??? /usr/local/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached.pid $OPTIONS ??? RETVAL=$? ??? echo ??? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached } stop () { ??? echo "Stopping memcached ..." ??? killproc memcached ??? RETVAL=$? ??? echo ??? if [ $RETVAL -eq 0 ] ; then ??????? rm -f /var/lock/subsys/memcached ??????? rm -f /var/run/memcached.pid ??? fi } restart () { ??? stop ??? start } # See how we were called. case "$1" in ??? start) ??????? start ??????? ;; ??? stop) ??? stop ??? ;; ??? status) ??? status memcached ??? ;; ??? restart|reload) ??? restart ??? ;; ??? condrestart) ??? [ -f /var/lock/subsys/memcached ] && restart || : ??? ;; ??? *) ??? echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" ??? exit 1 esac exit $? |
??? 3.将此脚本呢cp到/etc/init.d目录下并改名为memcached,然后执行chmod a+x memcached,如下:
??? shell > cp memcached.sysv /etc/init.d/memcached
<