memcache安装


    ?

<blockquote>
1.分别把memcached和libevent下载回来,放到 /tmp 目录下:<br>
# cd /tmp<br>
# wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz<br>
# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz

2.先安装libevent:<br>
# tar zxvf libevent-1.2.tar.gz<br>
# cd libevent-1.2<br>
# ./configure --prefix=/usr<br>
# make<br>
# make install

3.测试libevent是否安装成功:<br>
# ls -al /usr/lib | grep libevent<br>
lrwxrwxrwx    1 root     root          21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3<br>
-rwxr-xr-x       1 root     root          263546 11?? 12 17:38 libevent-1.2.so.1.0.3<br>
-rw-r--r--        1 root     root          454156 11?? 12 17:38 libevent.a<br>
-rwxr-xr-x       1 root     root          811 11?? 12 17:38 libevent.la<br>
lrwxrwxrwx    1 root     root          21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3<br>
还不错,都安装上了。

4.安装memcached,同时需要安装中指定libevent的安装位置:<br>
# cd /tmp<br>
# tar zxvf memcached-1.2.0.tar.gz<br>
# cd memcached-1.2.0<br>
# ./configure --with-libevent=/usr<br>
# make<br>
# make install<br>
如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。<br>
安装完成后会把memcached放到 /usr/local/bin/memcached ,

5.测试是否成功安装memcached:<br>
# ls -al /usr/local/bin/mem*<br>
-rwxr-xr-x    1 root     root       137986 11?? 12 17:39 /usr/local/bin/memcached<br>
-rwxr-xr-x    1 root     root       140179 11?? 12 17:39 /usr/local/bin/memcached-debug

?

?

?

memcached的基本设置:<br>
1.启动Memcache的服务器端:<br>
# /usr/local/bin/memcached -d -m 10  -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid

<blockquote>-d选项是启动一个守护进程,<br>
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,<br>
-u是运行Memcache的用户,我这里是root,<br>
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,<br>
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,<br>
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,<br>
-P(大写)是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,</blockquote>
2.如果要结束Memcache进程,执行:

<blockquote># kill `cat /tmp/memcached.pid`</blockquote>
<blockquote>
<div class="bct fc05 fc11 nbw-blog ztag js-fs2" style="line-height: 25px; font-size: 14px; text-align: left; color: #d5d5d5; margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #272727;">

<table id="memcache" style="line-height: 25px;" border="1" cellspacing="0" cellpadding="0"><tbody>
<tr>
<td>pid</td>
<td>memcache服务器的进程ID</td>
</tr>
<tr>
<td>uptime</td>
<td>服务器已经运行的秒数</td>
</tr>
<tr>
<td>time</td>
<td>服务器当前的unix时间戳</td>
</tr>
<tr>
<td>version</td>
<td>memcache版本</td>
</tr>
<tr>
<td>pointer_size</td>
<td>当前<span style="text-decoration: underline;"> 操作系统</span>的指针大小(32位系统一般是32bit)</td>
</tr>
<tr>
<td>rusage_user</td>
<td>进程的累计用户时间</td>
</tr>
<tr>
<td>rusage_system</td>
<td>进程的累计系统时间</td>
</tr>
<tr>
<td>curr_items</td>
<td>服务器当前存储的items数量</td>
</tr>
<tr>
<td>total_items</td>
<td>从服务器启动以后存储的items总数量</td>
</tr>
<tr>
<td>bytes</td>
<td>当前服务器存储items占用的字节数</td>
</tr>
<tr>
<td>curr_connections</td>
<td>当前打开着的连接数</td>
</tr>
<tr>
<td>total_connections</td>
<td>从服务器启动以后曾经打开过的连接数</td>
</tr>
<tr>
<td>connection_structures</td>
<td>服务器分配的连接构造数</td>
</tr>
<tr>
<td>cmd_get</td>
<td>get命令(获取)总请求次数</td>
</tr>
<tr>
<td>cmd_set</td>
<td>set命令(保存)总请求次数</td>
</tr>
<tr>
<td>get_hits</td>
<td>总命中次数</td>
</tr>
<tr>
<td>get_misses</td>
<td>总未命中次数</td>
</tr>
<tr>
<td>evictions</td>
<td>为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)</td>
</tr>
<tr>
<td>bytes_read</td>
<td>总读取字节数(请求字节数)</td>
</tr>
<tr>
<td>bytes_written</td>
<td>总发送字节数(结果字节数)</td>
</tr>
<tr>
<td>limit_maxbytes</td>
<td>分配给memcache的内存大小(字节)</td>
</tr>
<tr>
<td>threads</td>
<td>当前线程数</td>
</tr>
</tbody></table>

<div style="color: #d5d5d5; font-family: Arial, Helvetica, simsun, u5b8bu4f53; text-align: left; background-color: #272727;">

<div class="nbw-act tbar fc03 clearfix" style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 0px; text-align: right; color: #d5d5d5; line-height: 20px; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #272727;">

</blockquote>
<blockquote><br></blockquote>
<blockquote>
stats items<br style="padding: 0px; margin: 0px;">输出各个slab中的item信息。s<br style="padding: 0px; margin: 0px;">stats slabs<br style="padding: 0px; margin: 0px;">输出slab中更详细的item信息<br style="padding: 0px; margin: 0px;">stats sizes<br style="padding: 0px; margin: 0px;">输出所有item的大小和个数

stats cachedump <slab_id> <limit_num>

<br style="padding: 0px; margin: 0px;">根据<slab_id>输出相同的<slab_id>中的item信息。<limit_num>是输出的个数,当<limit_num>为0是输出所有的item。

<br style="padding: 0px; margin: 0px;"> 利用shell命令操作Memcached<br style="padding: 0px; margin: 0px;">1、数据存储(假设key为g,value为12345)?<br style="padding: 0px; margin: 0px;">???

?printf "set g 0 0 5\r\n12345\r\n"|nc 127.0.0.1 11211

??? STORED

??? 2、数据取回(假设key为zhangyan)

<br style="padding: 0px; margin: 0px;">printf "get g\r\n"|nc 127.0.0.1 11211

??? VALUE g 0 5<br style="padding: 0px; margin: 0px;">???  12345<br style="padding: 0px; margin: 0px;">???  END

??? 3、数值增加1(假设key为g,并且value为正整数)

?

?printf "incr g 1\r\n" | nc 127.0.0.1 11211

??? 12346

??? 4、数值减少3(假设key为g,并且value为正整数)

?

?printf "decr g? 3\r\n" | nc 127.0.0.1 11211

??? 12343

??? 5、数据删除(假设key为g)

?

?printf "delete g\r\n" | nc 127.0.0.1 11211

??? DELETED

??? 6、查看Memcached状态

?

?printf "stats\r\n" | nc 127.0.0.1 11211

? STAT pid 3025<br style="padding: 0px; margin: 0px;"> STAT uptime 4120500<br style="padding: 0px; margin: 0px;"> STAT time 1228021767<br style="padding: 0px; margin: 0px;"> STAT version 1.2.6<br style="padding: 0px; margin: 0px;"> STAT pointer_size 32<br style="padding: 0px; margin: 0px;"> STAT rusage_user 433.463103<br style="padding: 0px; margin: 0px;"> STAT rusage_system 1224.515845<br style="padding: 0px; margin: 0px;"> STAT curr_items 1132460<br style="padding: 0px; margin: 0px;"> STAT total_items 8980260<br style="padding: 0px; margin: 0px;"> STAT bytes 1895325386<br style="padding: 0px; margin: 0px;"> STAT curr_connections 252<br style="padding: 0px; margin: 0px;"> STAT total_connections 547850<br style="padding: 0px; margin: 0px;"> STAT connection_structures 1189<br style="padding: 0px; margin: 0px;"> STAT cmd_get 13619685<br style="padding: 0px; margin: 0px;"> STAT cmd_set 8980260<br style="padding: 0px; margin: 0px;"> STAT get_hits 6851607<br style="padding: 0px; margin: 0px;"> STAT get_misses 6768078<br style="padding: 0px; margin: 0px;"> STAT evictions 0<br style="padding: 0px; margin: 0px;"> STAT bytes_read 160396238246<br style="padding: 0px; margin: 0px;"> STAT bytes_written 260080686529<br style="padding: 0px; margin: 0px;"> STAT limit_maxbytes 2147483648<br style="padding: 0px; margin: 0px;"> STAT threads 1<br style="padding: 0px; margin: 0px;"> END

  7、模拟top命令,实时查看,查看Memcached状态:

?

?watch "printf 'stats\r\n' | nc 127.0.0.1 11211"?<br style="padding: 0px; margin: 0px;">??<br style="padding: 0px; margin: 0px;">? 或者<br style="padding: 0px; margin: 0px;">??<br style="padding: 0px; margin: 0px;">?? watch "echo stats | nc 127.0.0.1 11211"

一、echo stats items | nc127.0.0.1 11211<br style="padding: 0px; margin: 0px;">STAT items:1:number 998?????????????????? Slab Id=1 ; items数量:998(也就是已经存储了998个key值)<br style="padding: 0px; margin: 0px;">STAT items:1:age 604348?????????????????? Slab Id=1 ; 已经存在时间,单位秒<br style="padding: 0px; margin: 0px;">STAT items:1:evicted 0??????????????????????? Slab Id=1 ; 被踢出的数量<br style="padding: 0px; margin: 0px;">STAT items:1:evicted_nonzero 0<br style="padding: 0px; margin: 0px;">STAT items:1:evicted_time 0<br style="padding: 0px; margin: 0px;">STAT items:1:outofmemory 0<br style="padding: 0px; margin: 0px;">STAT items:1:tailrepairs 0<br style="padding: 0px; margin: 0px;">STAT items:1:reclaimed 0<br style="padding: 0px; margin: 0px;">STAT items:6:number 91897????????????? Slab Id=6 ; items数量:91897(也就是已经存储了91897个key值)<br style="padding: 0px; margin: 0px;">STAT items:6:age 604345????????????????? Slab Id=6 ; 已经存在时间,单位秒<br style="padding: 0px; margin: 0px;">STAT items:6:evicted 0?????????????????????? Slab Id=6 ; 被踢出的数量<br style="padding: 0px; margin: 0px;">STAT items:6:evicted_nonzero 0<br style="padding: 0px; margin: 0px;">STAT items:6:evicted_time 0<br style="padding: 0px; margin: 0px;">STAT items:6:outofmemory 0<br style="padding: 0px; margin: 0px;">STAT items:6:tailrepairs 0<br style="padding: 0px; margin: 0px;">STAT items:6:reclaimed 0<br style="padding: 0px; margin: 0px;">?

</blockquote>
<blockquote>
参考资料:<br>
对Memcached有疑问的朋友可以参考下列文章:<br>
Linux下的Memcache安装: http://www.ccvita.com/257.html<br>
Windows下的Memcache安装: http://www.ccvita.com/258.html<br>
Memcache基础教程: http://www.ccvita.com/259.html<br>
Discuz!的Memcache缓存实现: http://www.ccvita.com/261.html<br>
Memcache协议中文版: http://www.ccvita.com/306.html<br>
Memcache分布式部署方案: http://www.ccvita.com/395.html
</blockquote>
</blockquote>
 

你可能感兴趣的:(java,工作,memcache安装)