本例:
服务端192.168.80.81
需要安装libevent-2.1.8-stable.tar.gz(跨平台的事件处理接口的封装,memcached安装需要依赖)
memcached-1.5.6.tar.gz 服务端软件
客户端192.168.80.82
需要安装lamp架构(mysql可不装)
memcache-2.2.7.tgz 客户端软件
win10测试机192.168.80.79
1.首先进行服务端的配置:
tar xf memcached-1.5.6.tar.gz -C /opt/
tar xf libevent-2.1.8-stable.tar.gz -C /opt/
cd /opt/libevent-2.1.8-stable
./configure --prefix=/usr/local/libevent
make && make install
cd /opt/memcached-1.5.6
./configure \
--prefix=/usr/local/memcached \
--with-libevent=/usr/local/libevent/
make && make install
ln -s /usr/local/libevent/lib/libevent-1.4.so.2.1.2 /usr/lib64/libevent-1.4.so.2 //不可缺少
cd /usr/local/memcached/bin/
./memcached -d -m 32m -p 11211 -u root
netstat -anpt | grep memc
service firewalld stop
setenforce 0
telnet 127.0.0.1 11211
set userid 0 0 5 //不进行压缩和序列化标识 数据过期时间为永不过期 标识号是5就需要输入5位数。
12345 //输入5位数
get userid //获取数据
stats //显示状态信息
quit //退出
2.客户端配置:
安装lap 不需要装mysql php5.6(php不能装高版本,否则不兼容)
yum install autoconf -y
tar xf memcache-2.2.7.tgz -C /opt/
cd /opt/memcache-2.2.7
/usr/local/php5/bin/phpize //增加为PHP的模块后再对memcache进行配置编译
./configure \
--enable-memcache \
--with-php-config=/usr/local/php5/bin/php-config
make && make install
/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/ //记录此行下面用到
vi /usr/local/php5/php.ini //搜索并修改下面一行,再新增一行
extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/"
extension = memcache.so
vi /usr/local/httpd/htdocs/index.php
<?php
$memcache = new Memcache();
$memcache->connect(‘192.168.80.81‘,11211);
$memcache->set(‘key‘,‘Memcache test Successfull!‘,0,60);
$result = $memcache->get(‘key‘);
unset($memcache);
echo $result;
?>
//编写测试页面,测试memcached工作是否正常,若正常,则显示Memcache test Successfull!
service httpd restart
3.测试:
win10访问客户端http://192.168.80.82/index.php //输入客户端地址测试是否成功
从而实现了访问客户端httpd,调用API,连接到memcached服务端
原文地址:http://blog.51cto.com/13469709/2092168