CentOS安装memcached,并为WDCP PHP面板添加memcached扩展
By lincanbin
at 2015-03-27
2人收藏 • 3428人看过
What is Memcached?
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.
直接从yum源安装:
yum -y install memcached
如图,安装成功,yum源的memcached版本是1.4.4,如果需要最新版本,可以到
http://memcached.org/downloads
以编译方式进行安装
设置memcached开机自启:
chkconfig --level 2345 memcached on
配置memcached,按自己需要进行:
vi /etc/sysconfig/memcached
PORT="11211" #端口 USER="memcached" #用户名 MAXCONN="1024" #最大连接数 CACHESIZE="64" #内存大小 OPTIONS="" #附加参数
- 登录后方可回帖
接下来是安装PHP的php_memcached扩展,php_memcached依赖libmemcached库,所以先安装安装libmemcached-1.x以上版本。
因为对版本有要求,我的yum源的版本并不符合要求,所以编译安装
使用这个版本:
https://launchpad.net/libmemcached/+milestone/1.0.18
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar -zxvf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 ./configure -prefix=/usr/local/libmemcached -with-memcached make && make install
安装php-devel,为了下面编译扩展作准备:
yum install php-devel
从PECL安装memcached扩展,最新版本是:2.2.0
http://pecl.php.net/package/memcached
wget http://pecl.php.net/get/memcached-2.2.0.tgz tar -zxvf memcached-2.2.0.tgz cd memcached-2.2.0 /www/wdlinux/apache_php/bin/phpize ./configure -enable-memcached -with-php-config=/www/wdlinux/apache_php/bin/php-config -with-zlib-dir -with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/phpmemcached -disable-memcached-sasl make && make install
我的是WDCP,PHP bin路径根据自己实际修改
编辑配置文件:
vi /www/wdlinux/etc/php.ini
加入:
[memcached] memcached.extension_dir = "/www/wdlinux/apache_php-5.6.5/lib/php/extensions/no-debug-non-zts-20131226/" extension = memcached.so
验证扩展是否已安装:
/www/wdlinux/apache_php/bin/php -m|grep memcached
显示memcached,表示成功
重启Apache:
service httpd restart
如果一切正常,在phpinfo()中就可以看到memcached了
需要注意的是php-devel依赖于httpd,如果你原来的httpd(即Apache)不是从Yum源安装的,可能会导致多安装一个httpd。
这样lanmp环境下,从yum重新安装的httpd的80端口会与nginx冲突,可能出错。(LANMP环境下是Nginx作为前端代理占据80端口,实际上Apache是跑在88端口的)
如果LANMP架构用户重启apache出现类似下面这种情况
httpd not running, trying to start (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs
那么删除yum源的httpd
yum remove httpd
这样会倒是service指令不可用,需要重新添加httpd服务
重新添加httpd服务
cp /www/wdlinux/httpd-2.2.24/bin/apachectl /etc/rc.d/init.d/httpd ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd service httpd start vi /etc/init.d/httpd
在第2行添加如下注释信息:
# chkconfig: 35 61 61 # description: Apache
最后
chkconfig --add httpd