【memcached安装】
Linux系统安装memcached可以自动安装,也可以手动编译安装,这里使用手动编译安装
1、Linux系统安装memcached,首先要先安装libevent库。
下载libevent压缩包,例 libevent-2.1.8-stable.tar
#tar zxvf libevent-2.1.8-stable.tar -C /usr/local
#cd /usr/local/libevent-2.1.8
#./configure --prefix=/usr/local/libevent
#make && make install
安装 sasl 环境
yum -y install cyrus-sasl-lib.x86_64
yum -y install cyrus-sasl-devel.x86_64
2、从其官方网站(http://memcached.org)下载memcached最新版本
去 http://memcached.org/ 下载最新版本
#tar -zxvf memcached-1.x.x.tar.gz ##解压源码
#cd memcached-1.x.x ##进入目录
#./configure --prefix=/usr/local/memcached --wiht-libevent=/usr/local/libevent ##配置
#make ##编译
# make install ##安装
启动:
#/usr/local/memcached/bin/memcached -d -m 10m -p 11211 -u root
附上memcached启动脚本
#vim /etc/rc.d/init.d/memcached
#!/bin/bash
#
# Init file for memcached
#
# chkconfig: - 86 14
# description: Distributed memory caching daemon
#
# processname: memcached
# config: /etc/sysconfig/memcached
. /etc/rc.d/init.d/functions
## Default variables
PORT="11211"
USER="nobody"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
RETVAL=0
prog="/usr/local/memcached/bin/memcached"
desc="Distributed memory caching"
lockfile="/var/lock/subsys/memcached"
start() {
echo -n $"Starting $desc (memcached): "
daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}
stop() {
echo -n $"Shutting down $desc (memcached): "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $desc ($prog): "
killproc $prog -HUP
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e $lockfile ] && restart
RETVAL=$?
;;
reload)
reload
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
保存退出后,给脚本执行权限
#chmod +x memcached
然后就可以通过
#service memcached [start |stop |restart] 来进行相应的操作了。