本文共 5374 字,大约阅读时间需要 17 分钟。
目录
libevent
# yum install libevent libevent-devel -y
memcache
# wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz# tar zxf memcached-1.4.5.tar.gz# cd memcached-1.4.5# ./configure --prefix=/usr/local/memcached-1.4.5# make && make install
start
# ln -s /usr/local/memcached-1.4.5 /usr/local/memcached# /usr/local/memcached/bin/memcached -d -m 128 -p 11211 -u nobody -l 172.16.0.1
http://www.monkey.org/~provos/libevent/
cd /usr/local/src/wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gztar zxf libevent-1.4.13-stable.tar.gzcd libevent-1.4.13-stable./configure --prefix=/usr/local/libevent-1.4.13-stablemakemake installmake verifyln -s /usr/local/libevent-1.4.13-stable /usr/local/libeventln -s /usr/local/libevent/lib/* /usr/lib/ln -s /usr/local/libevent/include/* /usr/include/ln -s /usr/local/libevent/lib/* /usr/local/lib/ln -s /usr/local/libevent/include/* /usr/local/include/
http://www.danga.com/memcached/
cd /usr/local/src/wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gztar zxf memcached-1.4.5.tar.gzcd memcached-1.4.5./configure --prefix=/usr/local/memcached-1.4.5 --with-libevent=/usr/local/libeventmakemake installln -s /usr/local/memcached-1.4.5/ /usr/local/memcachedln -s /usr/local/memcached/bin/memcached /usr/sbin/memcached/usr/local/memcached/bin/memcached -d -m 2048 -l 127.0.0.1 -p 11211 -u root -c 15000 -P /tmp/memcached.pid
例 6.1. /etc/init.d/memcached
#!/bin/bash# memcached init file for memcached## chkconfig: - 100 100# description: a distributed memory object caching system# author: Neo Chen## processname: /usr/sbin/memcached# config:# pidfile: /var/run/memcached# source function library. /etc/init.d/functionsOPTIONS="-d -m 2048 -l 127.0.0.1 -p 11211 -u root -c 4096 -P /var/run/memcached"USER=daemonRETVAL=0prog="memcached"start() { echo -n $"Starting $prog: " if [ $UID -ne 0 ]; then RETVAL=1 failure else daemon --user=$USER /usr/sbin/memcached $OPTIONS RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached fi; echo return $RETVAL}stop() { echo -n $"Stopping $prog: " if [ $UID -ne 0 ]; then RETVAL=1 failure else killproc /usr/sbin/memcached RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/memcached fi; echo return $RETVAL}reload(){ echo -n $"Reloading $prog: " killproc /usr/sbin/memcached -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}condrestart(){ [ -e /var/lock/subsys/memcached ] && restart return 0}case "$1" in start) start ;; stop) stop ;; restart) restart ;;# reload)# reload# ;; condrestart) condrestart ;; status) status memcached RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" RETVAL=1esacexit $RETVAL
/etc/init.d/memcached
chmod +x /etc/init.d/memcached
flush_all指令清空memcache中的数据
$ telnet 172.16.3.51 11511Trying 172.16.3.51...Connected to 172.16.3.51.Escape character is '^]'.flush_allOKquitConnection closed by foreign host.
$ sudo apt-get install memcache
/etc/memcached.conf
$ cat /etc/memcached.conf# memcached default config file# 2003 - Jay Bonci# This configuration file is read by the start-memcached script provided as# part of the Debian GNU/Linux distribution.# Run memcached as a daemon. This command is implied, and is not needed for the# daemon to run. See the README.Debian that comes with this package for more# information.-d# Log memcached's output to /var/log/memcachedlogfile /var/log/memcached.log# Be verbose# -v# Be even more verbose (print client commands as well)# -vv# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default# Note that the daemon will grow to this size, but does not start out holding this much# memory-m 64# Default connection port is 11211-p 11211# Run the daemon as root. The start-memcached will default to running as root if no# -u command is present in this config file-u nobody# Specify which IP address to listen on. The default is to listen on all IP addresses# This parameter is one of the only security measures that memcached has, so make sure# it's listening on a firewalled interface.-l 127.0.0.1# Limit the number of simultaneous incoming connections. The daemon default is 1024# -c 1024# Lock down all paged memory. Consult with the README and homepage before you do this# -k# Return error when memory is exhausted (rather than removing items)# -M# Maximize core file limit# -r
restart
$ sudo /etc/init.d/memcached restart
# yum install memcached# chkconfig memcached on# chkconfig --list memcached# cat /etc/sysconfig/memcachedPORT="11211"USER="memcached"MAXCONN="1024"CACHESIZE="64"OPTIONS=""# /etc/init.d/memcached startStarting memcached: [ OK ]