1)首先安装最新版本的libevent安装包
官网下载:http://libevent.org/
./configure --prefix=/usr/local/libevent
make;make install
为了避免再次寻找旧版本,删除旧版本的libevent的文件
2)安装最新版本的memchached安装包
官网下载:http://memcached.org/
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make;make install
3)编写memcached的启动脚本
# cat /etc/init.d/memcached.rc
#!/bin/sh
# author:shenxiaoran
# Source function library.
. /etc/init.d/functions
prog_home=/usr/local/memcached
prog=$prog_home/bin/memcached
ip=192.168.92.15
port=10000
log=$prog_home/log/memcached.log
cpu_cores=$(cat /proc/cpuinfo|grep processor|wc -l)
echo -n $"Starting $prog: "
# start daemon
$prog -u root -d -m 20480 -l $ip -p $port -P /tmp/memcached.pid -v $log -t $cpu_cores
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/memcached
return $RETVAL
}
stop () {
# stop daemon
echo -n $"Stopping $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/memcached
}
restart() {
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 3
esac
exit $RETVAL
保存退出
3)编写一个测试memcached的小脚本
本人简单的使用了一个perl连接memcached的模块来做测试,脚本内容如下
# cat test_memcached.pl
#!/usr/bin/perl
use Cache::Memcached::Fast;
my $memd = new Cache::Memcached::Fast({
servers => [ { address => '192.168.123.44:10001', weight => 2.5 } ],
});
# Store scalars.
$memd->set(shen, 123, 10);
$memd->add(xiao, 456, 10);
$memd->set(ran, 789, 10);
# Print
print $memd->get(shen)."\n";
print $memd->get(xiao)."\n";
print $memd->get(ran)."\n";
$memd->flush_all;
保存退出