Memcache是用C编写的,要用到C的libevent来处理接口
点击下载memcached-1.4.0.tar.gz
下载libevent-2.0.13-stable.tar.gz
下载memcache-3.0.6.tgz
我下载到了/root/Downloads
a:先安装libevent
#cd /Downloads #tar zvxf libevent-2.0.13-stable.tar.gz #cd libevent-2.0.13-stable #./configure --prefix=/usr #make #make install
查看下安装是否成功
# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 2011-03-30 11:03 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3 -rw-r--r-- 1 root root 91768 2009-12-06 05:52 libevent-1.4.so.2.1.3 lrwxrwxrwx 1 root root 21 2011-09-16 01:41 libevent-2.0.so.5 -> libevent-2.0.so.5.1.2 -rwxr-xr-x 1 root root 817306 2011-09-16 01:41 libevent-2.0.so.5.1.2 -rw-r--r-- 1 root root 1048354 2011-09-16 01:41 libevent.a lrwxrwxrwx 1 root root 26 2011-09-16 01:41 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.2 -rwxr-xr-x 1 root root 499865 2011-09-16 01:41 libevent_core-2.0.so.5.1.2 -rw-r--r-- 1 root root 657028 2011-09-16 01:41 libevent_core.a -rwxr-xr-x 1 root root 968 2011-09-16 01:41 libevent_core.la lrwxrwxrwx 1 root root 26 2011-09-16 01:41 libevent_core.so -> libevent_core-2.0.so.5.1.2 lrwxrwxrwx 1 root root 27 2011-09-16 01:41 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.2 -rwxr-xr-x 1 root root 335387 2011-09-16 01:41 libevent_extra-2.0.so.5.1.2 -rw-r--r-- 1 root root 391398 2011-09-16 01:41 libevent_extra.a -rwxr-xr-x 1 root root 975 2011-09-16 01:41 libevent_extra.la lrwxrwxrwx 1 root root 27 2011-09-16 01:41 libevent_extra.so -> libevent_extra-2.0.so.5.1.2 -rwxr-xr-x 1 root root 933 2011-09-16 01:41 libevent.la lrwxrwxrwx 1 root root 29 2011-09-16 01:41 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.2 -rwxr-xr-x 1 root root 80238 2011-09-16 01:41 libevent_openssl-2.0.so.5.1.2 -rw-r--r-- 1 root root 86344 2011-09-16 01:41 libevent_openssl.a -rwxr-xr-x 1 root root 1004 2011-09-16 01:41 libevent_openssl.la lrwxrwxrwx 1 root root 29 2011-09-16 01:41 libevent_openssl.so -> libevent_openssl-2.0.so.5.1.2 lrwxrwxrwx 1 root root 30 2011-09-16 01:41 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.2 -rwxr-xr-x 1 root root 15733 2011-09-16 01:41 libevent_pthreads-2.0.so.5.1.2 -rw-r--r-- 1 root root 12998 2011-09-16 01:41 libevent_pthreads.a -rwxr-xr-x 1 root root 996 2011-09-16 01:41 libevent_pthreads.la lrwxrwxrwx 1 root root 30 2011-09-16 01:41 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.2 lrwxrwxrwx 1 root root 21 2011-09-16 01:41 libevent.so -> libevent-2.0.so.5.1.2
#cd ..
#tar zxvf memcached-1.4.0.tar.gz
#cd memcached-1.4.0
# ./configure --with-libevent=/usr
# make
# make install
注意编译配置./configure --with这里是两个 这里不要错了
检查是否成功
hihihi@TP-Tablet:~$ ls -la /usr/local/bin/*mem* -rwxr-xr-x 1 root root 257899 2011-09-18 18:10 /usr/local/bin/memcached
现在使用memcached,输入
/usr/local/bin/memcached -d -m 100 -u root -l 127.0.0.1 -p 11211 -c 256 -P tmp/memcached.pid
(参数说明:/usr/local/bin/memcached 是memcached编译后所在的地址 -d 是一个守护进程占用一个进程, -m 是分配给memcached的内存,单位MB, -u 是启动memcached的用户, -l 是监听的服务器地址,这里可以设置多台memcache服务器监听同一个IP作成集群, -p 是端口号,默认是11211,实际企业生产中建议修改, -c是运行时最大的并发连接数,默认1024, -P是设置保存memcached的pid文件. 其他参数可以用memcached -h获得帮助)
进入了memcached,随便输入下 比如输入stats显示状态,输入version显示版本.
也可以telnet 127.0.0.1 11211 连入,其他操作一样.
要关掉memcached服务,
killall -0 memcached
c. 安装memcache
#cd .. #tar vxzf memcache-3.0.6.tgz #cd memcache-3.0.6 #/usr/local/php/bin/phpize #./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir #make #make install #gvim /etc/php5/apache2/php.ini
修改php.ini中的extension_dir = “./”
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”添加
extension=memcache.so
#/usr/local/bin/memcached -d -m 128 -u root -l 127.0.0.1 -p 11211 -c 256 -P /var/temp/memcached.pid #kill `cat /var/temp/memcached.pid` 或者#killall memcached
sudo /etc/init.d/apche2 restart
< ?php $mem = new Memcache; $mem->connect(“127.0.0.1″, 11211); $mem->set(‘key’, ‘This is a test!’, 0, 60); $val = $mem->get(‘key’); echo $val; ?>
This is a test!
5: ubuntu/debian 。
a.直接sudo memcached
sudo apt-get install memcached
启动
memcached -d -m 128 -p 11211 -u root -l 127.0.0.1
b.sudo memcache
sudo apt-get install php5-memcache
sudo gvim /etc/php5/conf.d/memcache.ini ; uncomment the next line to enable the module extension=memcache.so [memcache] memcache.dbpath="/var/lib/memcache" memcache.maxreclevel=0 memcache.maxfiles=0 memcache.archivememlim=0 memcache.maxfilesize=0 memcache.maxratio=0
c.如果提示需要libevent
sudo apt-get install libevent-dev
然后重启下apache查看phpinfo就可以看见memcache了