首页 > 代码库 > memcached安装【转】

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安装【转】