参考资料:http://www.cnblogs.com/handongyu/p/6419305.html
一、安装libevent
首先检查系统中是否安装了libevent
[root@yeebian ~]# rpm -qa | grep libevent
如果安装了则查看libevent的安装路径,后续安装时需要用到
[root@yeebian ~]# rpm -ql libevent
如果没有安装,则先安装libevent
[root@yeebian ~]# cd /opt
[root@yeebian opt]# wget http://192.168.10.173:8080/website/linux/libevent-1.4.12-stable.tar.gz
[root@yeebian opt]# tar -zxvf libevent-1.4.12-stable.tar.gz
[root@yeebian opt]# cd libevent-1.4.12-stable
[root@yeebian libevent-1.4.12-stable]# ./configure -prefix=/opt/libevent/
[root@yeebian libevent-1.4.12-stable]# make && make install
[root@yeebian libevent-1.4.12-stable]# ldconfig #为了让动态链接库为系统所共享,需要执行以下动态链接库的管理命令ldconfig
二、安装memcached
[root@yeebian libevent-1.4.12-stable]# cd /opt
[root@yeebian opt]# wget http://192.168.10.173:8080/website/linux/memcached-1.4.33.tar.gz
[root@yeebian opt]# tar -zxvf memcached-1.4.33.tar.gz
[root@yeebian opt]# cd memcached-1.4.33
[root@yeebian memcached-1.4.33]#./configure --prefix=/opt/memcached-1.4.33/ --with-libevent=/opt/libevent/
[root@yeebian memcached-1.4.33]# make && make install
[root@yeebian memcached-1.4.33]# /opt/memcached-1.4.33/memcached -u root -d -m 128 -p 11211
三、设置memcached为开机自启动
[root@yeebian memcached-1.4.33]# cd /opt/
[root@yeebian opt]# wget http://192.168.10.173:8080/website/linux/memcached.sysv
[root@yeebian opt]# mv memcached.sysv /opt/memcached-1.4.33/scripts/memcached.sysv
[root@yeebian opt]# chmod 775 /opt/memcached-1.4.33/scripts/memcached.sysv
[root@yeebian opt]# cp /opt/memcached-1.4.33/scripts/memcached.sysv /etc/rc.d/init.d/memcached
[root@yeebian opt]# chkconfig --add memcached
[root@yeebian opt]# chkconfig memcached on
[root@yeebian opt]# service memcached restart
Stopping memcached: [ OK ]
Starting memcached: [ OK ]
[root@yeebian opt]# chkconfig | grep memcached
Self-starter configuration...
memcached 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@yeebian opt]# ps aux | grep memcached | grep 11211
Memcached progress...
root 9394 1.0 0.0 341484 3368 ? Ssl 16:31 0:00 /opt/memcached-1.4.33/memcached -d -p 11211 -u root -m 128 -c 1024 -P /var/run/memcached/memcached.pid
memcached.sysv启动脚本是我提前修改好上传到本地服务器的,脚本内容如下:
#! /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=128
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
prog="memcached" start () {
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
# chown $USER /var/run/memcached
daemon /opt/memcached-1.4.33/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
echo -n $"Stopping $prog: "
killproc memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached
rm -f /var/run/memcached/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 $?