1,安装memcached1.1,下载并安装# wget http://memcached.googlecode.com/files/memcached-1.4.8.tar.gz# tar -zxvf memcached-1.4.8.tar.gz# cd memcached-1.4.8# ./configure# make && make install注意:如果没有安装libevent导致./configure时出错,则先装libevent# wget https://github.com/downloads/libevent/libevent/libevent-2.0.15-stable.tar.gz# tar -zxvf libevent-2.0.15-stable.tar.gz# cd libevent-2.0.15-stable# ./configure# make && make install1.2,启动memcachedmemcached -d -m 1024 -u root -l 10.66.1.235 -p 11211 -c 4096 -P /tmp/memcached.pid说明:-p 监听的端口-l 连接的IP地址, 默认是本机-d start 启动memcached服务-d restart 重起memcached服务-d stop|shutdown 关闭正在运行的memcached服务-d install 安装memcached服务-d uninstall 卸载memcached服务-u 以的身份运行 (仅在以root运行的时候有效)-m 最大内存使用,单位MB。默认64MB-M 内存耗尽时返回错误,而不是删除项-c 最大同时连接数,默认是1024-f 块大小增长因子,默认是1.25-n 最小分配空间,key+value+flags默认是48-h 显示帮助注意:如果不能启动大于1024的连接数,那么必须要先修改Linux的内核参数,可以设置到最大的参数, ulimit -n 查看连接数。1.3,修改Linux内核的连接数(1).编辑 /etc/sysctl.conf在文件最末尾加入下面内容fs.file-max = 755070(2).编辑 /etc/security/limits.conf , 添加下面两行星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。* soft nofile 8192* hard nofile 8192(3).编辑 /etc/pam.d/login , 添加下面一行session required /lib64/security/pam_limits.so(4). 设置系统当前ulimit# ulimit -n 8192(5). 需无紧要,则重启系统。1.4,安装服务启动脚本(1),复制启动脚本# cp script/memcached.sysv /etc/init.d/memcached(2),修改脚本里的启动路径和绑定IP# vim /etc/init.d/memcachedchown $USER /usr/local/bin/memcacheddaemon /usr/local/bin/memcached -d -l 192.168.168.10 -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS(3),设置启动# chkconfig --add memcached# chkconfig memcached on# service memcached start(4),如果memcached服务脚本启动遇到问题,提示找不到libevent-2.0.so.5,则按下面访问解决 # ldd /usr/local/bin/memcached # cd /usr/local/bin/ # LD_DEBUG=libs ./memcached -v # ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5 # ldd /usr/local/bin/memcached libevent-2.0.so.5 显示找到,就OK了 2,安装PHP的memcache扩展. (1),下载和安装 # wget http://pecl.php.net/get/memcache-3.0.6.tgz # tar -zxvf memcache-3.0.6.tgz # cd memcache-3.0.6 # phpize && ./configure --enable-memcache && make # cp modules/memcache.so /usr/lib/php/modules/ # touch /etc/php.d/memcached.ini # echo 'extension=memcache.so' > /etc/php.d/memcached.ini(2),修改/etc/php.ini的PHP参数session.save_handler = memcachesession.save_path = "tcp://10.66.1.235:11211"3,重启apached# service httpd restart