Memcached 是一個高性能的分布式內存對象緩存系統,用於動態 Web 應用以減輕數據庫負載。
它通過在內存中緩存數據和對象來減少讀取數據庫的次數,從而提高動態、數據庫驅動網站的速度。
Memcached 基於 key/value 的 hashmap。其守護進程 ( daemon ) 是用 C 寫的,但是客戶端可以用任何語言來編寫,並通過 memcached 協議與守護進程通信。
以下介紹 Memcached 安裝方法 :
yum -y install libevent libevent-devel
wget https://memcached.org/latest
mv lastest memcached.tar.gz
./configure --prefix=/opt/memcached
make && make test && make install
touch /etc/init.d/memcached
編輯啟動檔
vim /etc/init.d/memcached
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# pidfile: /var/run/memcached/memcached.pid
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
PORT=11211
USER=nobody
MAXCONN=1024
CACHESIZE=384
OPTIONS=""
if [ -f /etc/sysconfig/memcached ];then
. /etc/sysconfig/memcached
fi
# Check that networking is up.
. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcached"
start () {
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
if [ "stat -c %U /var/run/memcached
" != "$USER" ]; then
chown $USER /var/run/memcached
fi
daemon --pidfile /var/run/memcached/memcached.pid /opt/memcached/bin/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 -p /var/run/memcached/memcached.pid /opt/memcached/bin/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|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/memcached ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac
exit $?
設定自動啟動服務
chmod 755 /etc/init.d/memcached
chkconfig --add memcached
chkconfig memcached on