wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gzwget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gzwget http://pecl.php.net/get/memcache-2.2.5.tgztar zxvf libevent-1.4.13-stable.tar.gztar zxvf memcached-1.4.4.
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gzwget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gzwget http://pecl.php.net/get/memcache-2.2.5.tgztar zxvf libevent-1.4.13-stable.tar.gztar zxvf memcached-1.4.4.tar.gzcd libevent-1.4.13-stable./configure --prefix=/usrmakemake installln -s /usr/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2cd memcached-1.4.4./configure --prefix=/home/memcached --enable-64bitmakemake install/home/memcached/bin/memcached -d -m 1024 -p 11211 -u root
参数说明: -d 启动为守护进程 -m 分配给memcached使用的内存数量,单位是mb,默认为64mb -u 运行memcached的用户,仅当作为root运行时 -l 监听的服务器ip地址,默认为环境变量indrr_any的值 -p 设置memcached监听的端口,最好是1024以上的端口 -c 设置最大并发连接数,默认为1024 -p 设置保存memcached的pid文件,与-d选择同时使用
cd memcache-2.2.5/home/php/bin/phpize./configure --prefix=/home/phpmemcache --with-php-config=/home/php/bin/php-configmakemake installsed –i ‘s:./:/home/php/lib/php/extensions/no-debug-zts-20060613/:g’ /home/php/lib/php.inised –i ‘/zip.dll/aextension=memcache.so’ /home/php/lib/php.inicat >> /cache/data/test.php addserver('127.0.0.1', 11211);$memcache->addserver('192.168.0.2', 11212);$version = $memcache->getversion();echo server's version: .$version.n;$tmp_object = new stdclass;$tmp_object->str_attr = 'test';$tmp_object->int_attr = 123;$memcache->set('key', $tmp_object, false, 10) or die (failed to save data at the server);echo store data in the cache (data will expire in 10 seconds)n;$get_result = $memcache->get('key');echo data from the cache:n;var_dump($get_result);?>eof
curl http://localhost/test.phserver's version: 1.4.4store data in the cache (data will expire in 10 seconds)data from the cache:object(stdclass)#3 (2) {[str_attr]=>string(4) test[int_attr]=>int(123)}# telnet localhost 11211
trying 127.0.0.1...connected to localhost.localdomain (127.0.0.1).escape character is '^]'.statsstat pid 3015stat uptime 3185 memcached运行的秒数stat time 1267090234stat version 1.4.4stat pointer_size 64stat rusage_user 0.000000stat rusage_system 0.000000stat curr_connections 10stat total_connections 18stat connection_structures 11stat cmd_get 3 查询缓存的次数stat cmd_set 5?设置key=>value的次数stat cmd_flush 0stat get_hits 3? 缓存命中的次数stat get_misses 0stat delete_misses 0stat delete_hits 0stat incr_misses 0stat incr_hits 0stat decr_misses 0stat decr_hits 0stat cas_misses 0stat cas_hits 0stat cas_badval 0stat auth_cmds 0stat auth_errors 0stat bytes_read 2697stat bytes_written 1150stat limit_maxbytes 1073741824stat accepting_conns 1stat listen_disabled_num 0stat threads 4stat conn_yields 0stat bytes 1255stat curr_items 2stat total_items 5stat evictions 0end
完成~~~以上仅为试验,如果只是一个小web单机环境的话,只需要php+eaccelerator(或者apc/xcache等)就足够了。用php+memcached+mysql-proxy+mysql是大型网站架构的事情~~
原文地址:memcached部署, 感谢原作者分享。