分类: IT职场
2013-04-23 16:26:49
1、memcache介绍
目前全世界不少人使用memcache这个缓存项目来构建自己大负载的网站,来分担数据库的压力。memcache官方网站:源码包下载地址wget;由于memcachee用到了libevent这个库用于Socket的处理,所以还需要安装libevent,最近libevent稳定版本下载地址wget。
2、安装memcache
1)、安装libevent
# tar xzvf libevent-1.4.14b-stable.tar.gz
# cd libevent-1.4.14b-stable
# ./configure –prefix=/usr
# make && make install
# cd ..
# ls -al /usr/lib | grep libevent (查看是否安装成功)
2)、安装memcache
# tar xzvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure –with-libevent=/usr
# make && make install
# ls -al /usr/local/bin/mem* (查看是否生成memcached可执行程序文件)
#备注:如果是64位的系统可能会报错,因为默认的库文件只会安装到/usr/lib下面
3、启动memcache# 通过/usr/local/bin/memcached –h查看命令选项帮助
[root@Centos2 memcached-1.4.5]# /usr/local/bin/memcached -h memcached 1.4.5 -p TCP port number to listen on (default: 11211) -U UDP port number to listen on (default: 11211, 0 is off) -s UNIX socket path to listen on (disables network support) -a access mask for UNIX socket, in octal (default: 0700) -l interface to listen on (default: INADDR_ANY, all addresses) -d run as a daemon -r maximize core file limit -u assume identity of (only when run as root) -m max memory to use for items in megabytes (default: 64 MB) -M return error on memory exhausted (rather than removing items) -c max simultaneous connections (default: 1024)
#启动命令如下
# /usr/local/bin/memcached -d -m 10 -u root -l 172.28.5.2 -p 12000 -c 1024 –P /tmp/memcached.pid
4、Php的memcache扩展的安装
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
修改php.ini文件
查找/usr/local/php/etc/php.ini中的 extension_dir = “./”修改为extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加一行,然后保存:
extension = “memcache.so”
创建php文件aaa.php,内容如下:
Phpinfo();
?>
保存,然后访问看是否能显示memcache模块的信息!