memcached服务直接用yum安装
[[email protected] ~]# yum install memcached
然后启动memcache服务,启动多个实例
[[email protected] ~]# /usr/bin/memcached -d -m 512 -p 11211 -u memcached -c 1024
[[email protected] ~]# /usr/bin/memcached -d -m 512 -p 11212 -u memcached -c 1024
[[email protected] ~]# /usr/bin/memcached -d -m 512 -p 11266 -u memcached -c 1024
[[email protected] ~]# ps -ef|grep memcached
root 2228 32759 0 19:15 pts/2 00:00:00 grep --color memcached
495 2713 1 0 Jun12 ? 00:04:04 /usr/bin/memcached -d -m 512 -p 11211 -u memcached -c 1024
495 2720 1 0 Jun12 ? 00:05:10 /usr/bin/memcached -d -m 512 -p 11212 -u memcached -c 1024
495 2727 1 0 Jun12 ? 00:07:10 /usr/bin/memcached -d -m 512 -p 11266 -u memcached -c 1024
查看memcached版本
[[email protected] ~]# memcached -h|head -1
memcached 1.4.4
这个1.4.4版本的memcached就是本机程序使用的缓存服务。
---------------------------------------------------------------------------------
由于之前安装了php服务,后续需要手动添加memcached扩展模块。
php扩展模块安装使用的是2.2.0版本的memcached
1)首先安装memcached的库libmemcached
[[email protected] ~]# https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz
[[email protected] ~]# tar -zvxf libmemcached-1.0.18.tar.gz
[[email protected] ~]# cd libmemcached-1.0.18
[[email protected] libmemcached-1.0.18]# ./configure --prefix=/usr/local/libmemcached --with-memcached
[[email protected] libmemcached-1.0.18]# make && make install
2)接着安装memcached
[[email protected] ~]# wget http://pecl.php.net/get/memcached-2.2.0.tgz
[[email protected] ~]# tar -zvxf memcached-2.2.0.tgz
[[email protected] ~]# cd memcached-2.2.0
[[email protected] memcached-2.2.0]# /usr/local/php5.6.26/bin/phpize #使用phpize命令生成一个configure文件
[[email protected] memcached-2.2.0]# ./configure --with-php-config=/usr/local/php5.6.26/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached
[[email protected] memcached-2.2.0]# make && make install
安装完成后,会产生一个memcached.so文件,这个文件需要在php.ini配置文件里添加
安装php5.6.26后,得知扩展文件路径存放在/usr/loca/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/
然后将上面编译生成的memcached.so文件放到/usr/loca/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/
编译php.ini文件
[[email protected] ~]# vim /usr/loca/php5.6.26/etc/php.ini
....
extension="/usr/loca/php5.6.26/lib/php/extensions/no-debug-non-zts-20131226/memcached.so"
然后重启php
[[email protected] ~]# pkill -9 php-fpm
[[email protected] ~]# /usr/loca/php5.6.26/sbin/php-fpm
然后查看php的扩展模块
[[email protected] etc]# /usr/loca/php5.6.26/bin/php -m
......
memcached