背景:
阅读新闻
LNMP平台+Memcached缓存系统
[日期:2012-11-12] 来源:Linux社区 作者:tdyso [字体:]
二、安装memcache
(一)安装libevent:
libevent是将多种系统底层上的各种不同的事件驱动机制封装成统一接口的库文件,memcached依赖于libevent API.
# tar xf libevent-2.0.20-stable.tar.gz
# cd libevent-2.0.20
# ./configure --prefix=/usr/local/libevent
# make && make install
输出libevent库文件路径
# echo "/usr/local/libevent/lib" > /etc/ld.so.conf.d/libevent.conf
# ldconfig
(二)安装服务器端memcached
1、安装memcached
# tar xf memcached-1.4.15.tar.gz
# cd memcached-1.4.15
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make install
2、为memcached建立sys v的服务脚本:
创建/etc/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
[ -f /etc/sysconfig/memcached ] && . /etc/sysconfig/memcached #将memcached的参数定义设置为独立配置文件
## Default variables
PORT=${PORT:-11211}
USER=${USER:-nobody}
MAXCONN=${MAXCONN:-1024}
CACHESIZE=${CACHESIZE:-64}
OPTIONS=${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
建立memcached参数配置文件:
#echo -e 'PORT="11211" \nUSER="nobody" \nMAXCONN="1024" \nCACHESIZE="64" \nOPTIONS="" ' > /etc/sysconfig/memcached
添加执行权限,加入到系统服务
# chmod +x /etc/init.d/memcached
# chkconfig --add memcached
# service memcached start
查看进程:
# ps aux | grep memcached
使用telnet命令测试memcached的使用:
# telnet 127.0.0.1 11211
相关资讯
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯