【基本介绍】
memcached是优秀的cache软件,有效减轻数据库服务器的压力
【下载】
http://www.danga.com/memcached/
libevent从何处下载?
http://monkey.org/~provos/libevent/
php的memcache模块下载:
http://pecl.php.net/package/memcache/download/
【服务端安装配置】-源码安装
1.安装libevent
tar -zxvf libevent-1.3e.tar.gz
./configure --prefix=/usr
make
make install
2.安装memcached
tar -zxvf memcached-1.2.2.tar.gz
./configure --with-libevent=/usr --enable-threads
make
make install
启动memcached服务器
/usr/local/bin/memcached -d -m 1024 -u root -l 192.168.13.236 -p 12001 -c 256 -P /tmp/chenxinhan/memcached.pid
参数说明:
-d 选项是启动一个守护进程,
-m 是分配给Memcache使用的内存数量,单位是MB,这里是1GB,
-u 是运行Memcache的用户,这里是root,
-l 是监听的服务器IP地址,如果有多个地址的话,以逗号隔开。这里指定了服务器的IP地址192.168.13.236,
-p 是设置Memcache监听的端口,我这里设置了12001,最好是1024以上的端口,
-c 选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P 是设置保存Memcache的pid文件,我这里是保存在 /tmp/chenxinhan/memcached.pid,
-t <num> number of threads to use, default 4
如果有此项,说明已经支持了线程,就可以在启动的时候使用 -t 选项来启动多线程
然后启动的时候必须加上你需要支持的线程数量:
/usr/local/memcache/bin/memcached -t 1024
结束Memcache进程,执行:
kill `cat /tmp/chenxinhan/memcached.pid`
或者:ps -aux | grep memcache
然后直接kill掉memcache进程。
--
yum安装(CentOS5.8)
yum install memcached.x86_64
service memcached start
【配置php能访问memcached】
wget http://pecl.php.net/get/memcache-2.2.0.tgz
tar -zxvf memcache-2.2.0.tgz
[root@datam memcache-2.2.0]# /usr/local/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.
没有autoconf
yum install autoconf
[root@datam memcache-2.2.0]# yum install autoconf
[root@datam memcache-2.2.0]# /usr/local/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
[root@datam memcache-2.2.0]# ./configure --enable-memcache --with-php-config=/usr/local/bin/php-config --with-zlib-dir
make
[root@datam memcache-2.2.0]# make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20050922/
至此安装成功
下面我们需把此安装成功的模块添加到php中去
vi php.ini
add下面的这两行
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20050922/"
extension=memcache.so
然后重启apache
用phpinfo()看到存在以下信息,则表示模块安装成功
【参考】
http://blog.csdn.net/chinalinuxzend/article/details/1812424
memcached - 安装及php使用
猜你喜欢
转载自runpanda.iteye.com/blog/2100359
今日推荐
周排行