| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
13年前发布

Memcached 搭建过程

     安装 memcached 服务端    <div>     <div id="code0">      yum -y install libevent libevent-devel      <br /> #需要 libevent 支持      <p>cd /opt<br /> rm -rf memcached-1.2.0.tar.gz<br /> wget http://192.168.0.97/download/linux/cache/memcached-1.2.0.tar.gz<br /> rm -rf memcached-1.2.0<br /> tar -zxf memcached-1.2.0.tar.gz<br /> cd /opt/memcached-1.2.0<br /> ./configure –with-libevent=<br /> make<br /> make install</p>     </div>    </div>    <p>2、安装 memcache 客户端</p>    <div>     <div id="code1">      cd /opt      <br /> rm -rf memcache-2.2.5.tgz      <br /> wget http://192.168.0.97/download/linux/cache/memcache-2.2.5.tgz      <br /> rm -rf memcache-2.2.5      <br /> tar -zxf memcache-2.2.5.tgz      <br /> cd /opt/memcache-2.2.5      <br /> /usr/local/php/bin/phpize      <br /> ./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir      <br /> make      <br /> make install      <p># 修改php.ini</p>      <p>- – - – -<br /> vi /etc/php.ini<br /> /extension_dir =<br /> iextension=memcache.so<br /> extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”<br /> #<br /> - – - – - -</p>      <p># 重启 apache php生效<br /> /usr/local/apache2/bin/apachectl restart</p>     </div>    </div>    <p>3、一般的维护 开启 关闭 查看状态</p>    <div>     <div id="code2">      开启memcache 服务端      <br /> /usr/local/bin/memcached -d -m 128 -u root -l 192.168.0.97 -c 256 -P /tmp/memcached.pid      <p>关闭memcache 服务端<br /> kill `cat /tmp/memcached.pid`</p>      <p>写成脚本<br /> vi /etc/init.d/memcache_start.sh<br /> i/usr/local/bin/memcached -d -m 128 -u root -l 192.168.0.97 -c 256 -P /tmp/memcached.pid<br /> chmod a+x /etc/init.d/memcache_start.sh</p>      <p>vi /etc/init.d/memcache_stop.sh<br /> ikill `cat /tmp/memcached.pid`<br /> chmod a+x /etc/init.d/memcache_start.sh</p>      <p>查看memcache状态<br /> telnet 192.168.0.98 11211<br /> 输入stats查询状态<br /> stats<br /> STAT pid 8601<br /> STAT uptime 696<br /> STAT time 1245832689<br /> STAT version 1.2.0<br /> STAT pointer_size 64<br /> STAT rusage_user 0.007998<br /> STAT rusage_system 0.030995<br /> STAT curr_items 1<br /> STAT total_items 1<br /> STAT bytes 76<br /> STAT curr_connections 2<br /> STAT total_connections 4<br /> STAT connection_structures 3<br /> STAT cmd_get 1<br /> STAT cmd_set 1<br /> STAT get_hits 1<br /> STAT get_misses 0<br /> STAT bytes_read 97<br /> STAT bytes_written 620<br /> STAT limit_maxbytes 134217728<br /> END</p>      <p>-d选项是启动一个守护进程,<br /> -m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,<br /> -u是运行Memcache的用户,我这里是root,<br /> -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.22.200,<br /> -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,<br /> -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,<br /> -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,</p>     </div>    </div>    <p>4、在客户端使用php测试</p>    <div>     <div id="code3">      <pre class="brush:php; toolbar: true; auto-links: false;"><?php $mem=new Memcache; $mem->connect(“192.168.0.97″,11211); $mem->set(‘key’,'This is a test!’, 0, 60); $val=$mem->get(‘key’); echo $val; ?></pre>      <br />     </div>    </div>     
 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1324368235733.html
缓存服务器 memcached