<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; memcache</title>
	<atom:link href="https://www.yunda51.com/?feed=rss2&#038;tag=memcache" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>CentOs下memcache的安装以及php添加memcache扩展</title>
		<link>https://www.yunda51.com/?p=1610</link>
		<comments>https://www.yunda51.com/?p=1610#comments</comments>
		<pubDate>Tue, 18 Aug 2015 16:03:37 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[Mysql]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1610</guid>
		<description><![CDATA[一、下载需要的源码包 1、 下载libevent2.0.22                   2、 下载m<a href="https://www.yunda51.com/?p=1610" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>一、下载需要的源码包<br />
1、 下载libevent2.0.22                  <a style="background: transparent none repeat scroll 0% 0%;" href="http://pan.baidu.com/s/1sjIEu1v" target=""><img class="alignnone size-full wp-image-1075" title="btn_load" src="http://www.yunda51.com/wp-content/uploads/2013/11/btn_load3.png" alt="" width="86" height="28" /></a><br />
2、 下载memcached1.4.24           <a style="background: transparent none repeat scroll 0% 0%;" href="http://pan.baidu.com/s/1kTF2Mz1" target=""><img class="alignnone size-full wp-image-1075" title="btn_load" src="http://www.yunda51.com/wp-content/uploads/2013/11/btn_load3.png" alt="" width="86" height="28" /></a><br />
3、 下载php扩展memcache3.0.8  <a style="background: transparent none repeat scroll 0% 0%;" href="http://pan.baidu.com/s/1gdwDZaj" target=""><img class="alignnone size-full wp-image-1075" title="btn_load" src="http://www.yunda51.com/wp-content/uploads/2013/11/btn_load3.png" alt="" width="86" height="28" /></a></p>
<p>二、安装详细步骤<br />
首先将以上下载的三个软件包下载到/usr/local/src目录下（注：你们可以放到别的目录）<br />
1. 安装libevent<br />
cd /usr/local/src<br />
tar zxvf libevent-2.0.22-stable.tar.gz #解压包<br />
cd libevent-2.0.22-stable<br />
./configure --prefix=/usr/local #编译前配置，生成Makefile文件，路径可自行更改<br />
make #编译<br />
make install #安装</p>
<p>2、安装memcached<br />
cd /usr/local/src<br />
tar zxvf memcached-1.4.24.tar.gz #解压包<br />
cd memcached-1.4.24<br />
./configure –with-libevent=/usr/local #编译前配置，生成Makefile文件，路径必须与libevent中一致<br />
make #编译<br />
make install #安装</p>
<p>（注：如果在make 编译的时候报错，出现如图：）<br />
<a href="http://www.yunda51.com/wp-content/uploads/2015/08/11.png"><img class="alignnone size-full wp-image-1614" src="http://www.yunda51.com/wp-content/uploads/2015/08/11.png" alt="1" width="558" height="92" /></a></p>
<p>解决办法：<br />
1、cd /usr/local/memcached-1.4.24 进入memcached目录<br />
2、vi Makefile （编辑Makefile文件，删除文件中的“-Werror” ，保存后即可。）<br />
3、保存之后，接着安装 make install。<br />
测试是否安装成功。<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/21.png"><img class="alignnone size-full wp-image-1615" src="http://www.yunda51.com/wp-content/uploads/2015/08/21.png" alt="2" width="558" height="36" /></a><br />
3、安装扩展<br />
1、cd /usr/local/src<br />
2、tar zxvf memcache-3.0.8.tgz<br />
3、memcache-3.0.8<br />
4、/usr/local/php5/bin/phpize #执行phpize扩展安装程序<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/22.png"><img class="alignnone size-full wp-image-1623" src="http://www.yunda51.com/wp-content/uploads/2015/08/22.png" alt="2" width="689" height="138" /></a><br />
5、./configure -enable-memcache -with-php-config=/usr/local/php5/bin/php-config -with-zlib-dir<br />
6、make #编译<br />
7、make install #安装<br />
如图： <a href="http://www.yunda51.com/wp-content/uploads/2015/08/4.png"><img class="alignnone size-full wp-image-1617" src="http://www.yunda51.com/wp-content/uploads/2015/08/4.png" alt="4" width="558" height="49" /></a><br />
三 、配置php.ini文件<br />
1、 查看是否有memcache.so<br />
cd /usr/local/lib/php/extensions/no-debug-non-zts-20100525/<br />
2、vi /usr/local/php5/etc/php.ini #编辑php.ini<br />
添加如下代码：<br />
extension=memcache.so<br />
[Memcache]<br />
extension_dir =“/usr/local/lib/php/extensions/no-debug-non-zts-20100525/”<br />
memcache.allow_failover = 1<br />
memcache.max_failover_attempts=20<br />
memcache.chunk_size =8192</p>
<p>四、配置memcached服务器<br />
1、启动memcached服务器<br />
memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P /usr/local/bin/memcached/memcached.pid</p>
<p>如果在启动memcached时候报“memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory”之类的错误信息，表示memcached找不到libevent的位置<br />
<strong>如图：</strong><br />
<a href="http://www.yunda51.com/wp-content/uploads/2015/08/memcached.png"><img class="alignnone size-full wp-image-1620" src="http://www.yunda51.com/wp-content/uploads/2015/08/memcached.png" alt="memcached" width="558" height="34" /></a></p>
<p><strong>解决办法： </strong><br />
1、 首先查看，libevent 在哪里 ，执行：# whereis libevent<br />
2、 然后，再看memcached 从哪里找它，执行# LD_DEBUG=libs memcached -v 2&gt;&amp;1 &gt; /dev/null | less 可以看到：是/usr/lib/libevent-2.0.so.5，所以，创建软链<br />
3、 # ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5<br />
4、 关闭memcached :pkill memcached<br />
5、 再次启动：memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P /usr/local/bin/memcached/memcached.pid<br />
6、 查看端口，看memcached是否启动成功！# netstat –ant<br />
如图：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2015/08/memcached1.png"><img class="alignnone size-full wp-image-1621" src="http://www.yunda51.com/wp-content/uploads/2015/08/memcached1.png" alt="memcached1" width="558" height="162" /></a><br />
表示启动成功！<br />
7、查看你得memcache扩展是否添加成功！<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/12.png"><img class="alignnone size-full wp-image-1622" src="http://www.yunda51.com/wp-content/uploads/2015/08/12.png" alt="1" width="661" height="241" /></a><br />
表示扩展添加成功！<br />
五 测试php的memcache扩展<br />
<!--?php $mem = new Memcache(); $mem--->connect("127.0.0.1", 11211);<br />
$mem-&gt;set('key', 'This is my  memcache ceshi!', 0, 60);<br />
$val = $mem-&gt;get('key');<br />
echo $val;<br />
?&gt;</p>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1470.html">http://www.yunda51.com/1610.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1610</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
