1.memcached安装部署 wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz tar axf libevent-2.0.22-stable.tar.gz cd libevent-2.0.22-stable ./configure make && make install echo "usr/local/lib" >/etc/ld.so.conf.d/libevent.conf
wget http://www.memcached.org/files/memcached-1.4.22.tar.gz tar axf memcached-1.4.22.tar.gz cd memcached-1.4.22 ./configure make && make install 查看帮助命令 /usr/local/bin/memcached -h
启动memcached /usr/local/bin/memcached -p 11211 -l 127.0.0.1 -u root -m 100 -c 200 -vvv -n 10 -f 2 -d
选项及其含义 -p 指定端口 -l 服务器的IP地址 -u 程序运行时使用的用户身份 -m 指定使用本机多少的内存存数据 -c memcached服务的最大连接数 -vvv显示详细信息 -n chunk size的最小空间是多少,单位是字节 -f chunk size大小增长的倍数 -d 在后台启动
测试memcached的内部状态 telnet 127.0.0.1 11211
2.PHP memcached
部署LNMP,使用php页面对memcached进行读写操作 wget http://zyan.cc/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz tar axf memcache-2.2.5.tgz cd memcache-2.2.5 /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --enable-memcache make && make install vim /usr/local/php5/etc/php.ini extension_dir="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/" extension=memcache.so
service php-fpm reload
vim /usr/local/nginx/html/test.php <?php $memcache=new Memcache; $memcache->connect('localhost',11211) or die('could not connect!!'); $memcache->set('key','test'); $get_values=$memcache->get('key'); echo $get_values; ?>