1、下载libevent http://ftp.lfs-matrix.net/pub/blfs/conglomeration/libevent/libevent-2.0.22-stable.tar.gz 2、下载memcached http://memcached.org/files/memcached-1.4.34.tar.gz yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel 1、安装libevent cd /usr/local/src tar zxvf libevent-2.0.22-stable.tar.gz cd libevent-2.0.22-stable ./configure --prefix=/usr/local/libevent make make install 2、安装memcached cd /usr/local/src tar zxvf memcached-1.4.34.tar.gz cd memcached-1.4.34 ./configure --enable-sasl --prefix=/usr/local/memcached -with-libevent=/usr/local/libevent make make install 3、测试Memcached groupadd memcached #创建组 useradd -g memcached memcached -s /bin/false #创建账号 ln -s /usr/local/memcached/bin/memcached /usr/local/bin/memcached #添加软连接 启动Memcache的服务器端的命令为: /usr/local/memcached/bin/memcached -d -m 4096 -u root -l 192.168.4.6 -p 11211 -c 1024 -P /usr/local/memcached/memcached.pid 或者 /usr/local/memcached/bin/memcached -d -m 4096 -u memcached -l 192.168.4.6 -p 11211 -c 1024 参数说明: -d选项是启动一个守护进程, -m是分配给Memcache使用的内存数量,单位是MB,这里是4096MB -u是运行Memcache的用户,比如root或者memcached -l是监听的服务器IP地址,这里指定服务器的IP地址192.168.4.6,不设置默认监听服务器所有IP地址 -p是设置Memcache监听的端口,默认为11211 -c选项是最大运行的并发连接数,默认是1024 -P是设置保存Memcache的pid文件,/usr/local/memcached/memcached.pid 开机自启动,在/etc/rc.d/rc.local中加入一行 /usr/local/memcached/bin/memcached -d -m 4096 -u root -l 192.168.4.6 -p 11211 -c 1024 -P /usr/local/memcached/memcached.pid 也可以使用下面的命令: /usr/local/memcached/bin/memcached -d -m 4096 -p 11211 -u memcached ip不指定时,默认监听本地所有ip地址,用户最好选择是非root用户,例如memcached 关闭Memcached服务 cat /usr/local/memcached/memcached.pid #查看进程 kill 22856 #结束进程 或者 killall memcached #结束服务 4、设置Memcached开机启动 vi /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 MEMCACHED="/usr/local/memcached/bin/memcached" start() { echo -n $"Starting memcached: " daemon $MEMCACHED -u memcached -d -m 4096 -p 11211 -c 1024 echo } stop() { echo -n $"Shutting down memcached: " killproc memcached echo } [ -f $MEMCACHED ] || exit 0 # See how we were called. case "$1" in start) start ;; stop) stop ;; restart|reload) stop start ;; condrestart) stop start ;; *) echo $"Usage: $0 {start|stop|restart|reload|condrestart}" exit 1 esac exit 0 :wq! #保存退出 chmod 775 /etc/rc.d/init.d/memcached #赋予文件执行权限 chkconfig memcached on #设置开机启动 /etc/rc.d/init.d/memcached start #启动