memcached安裝【轉】
1、安裝依賴軟件
# yum -y install libevent libevent-devel perl-Test-Harness perl-Time-HiRes perl-TermReadKey perl-Test-Compile cpan perl perl-Test-Class
如果make test失敗可以試試yum install perl-Test*
2、安裝memcached
# cd /usr/local/src/
# wgethttp://www.memcached.org/files/memcached-1.4.29.tar.gz
# tar xvf memcached-1.4.29.tar.gz
# cd memcached-1.4.29
# ./configure --prefix=/usr/local/memcached
# make
# make test
# make install
3、啟動memcached
# /usr/local/memcached/bin/memcached -d -m 128 -u root -p 11211 -U 11211 -P /tmp/memcached.pid
啟動參數說明:/usr/local/memcached/bin/memcached -h 查看幫助
-P 是設置保存Memcache的pid文件
-c 選項是最大運行的並發連接數,默認是1024
-p 是設置Memcache的TCP監聽的端口,最好是1024以上的端口,默認為11211
-l 是監聽的服務器IP地址,默認為所有網卡。
-U 是設置Memcache的UDP監聽端口
-u 是運行Memcache的用戶,如果當前為root 的話,需要使用此參數指定用戶。
-M return error on memory exhausted (rather than removing items)
-m 是分配給Memcache使用的內存數量,單位是MB,默認64MB
-d 選項是啟動一個守護進程,
4、memcache開機啟動
# vim /etc/rc.d/init.d/memcached
#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
#[ ${NETWORKING} = "no" ] && exit 0
#[ -r /etc/sysconfig/dund ] || exit 0
#. /etc/sysconfig/dund
#[ -z "$DUNDARGS" ] && exit 0
start()
{
echo -n $"Starting memcached: "
#如需修改啟動參數,在這裏修改
daemon $MEMCACHED -d -m 128 -u root -p 11211 -U 11211 -P /tmp/memcached.pid
echo
}
stop()
{
echo -n $"Shutting down memcached: "
killproc memcached
echo
}
#註意修改下面memcached的路徑
MEMCACHED="/usr/local/memcached/bin/memcached"
[ -f $MEMCACHED ] || exit 1
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
# chmod 755 /etc/init.d/memcached
# chkconfig --add memcached
# chkconfig memcached on
# service memcached start
備註:另外也可以將啟動命令加入/etc/rc.local,讓memcached開機啟動
5、清除緩存方法
方法1:telnet 127.0.0.1 11211 執行flush_all命令
方法2:重啟memcached
轉自
memcached安裝 - 今日頭條(www.toutiao.com)
http://www.toutiao.com/i6432180294589088257/
memcached安裝【轉】