安装Memcached及Memcached配置和状态查询
?
要想使用Memcached做缓存首先需要安装Memcached服务,安装方法如下:
1. 下载Memcached:http://code.jellycan.com/memcached,现在的最新版本是1.2.6。注意下载正确的版本,本文中用的是windows版,下载win32 binary。
2.解压之后放在硬盘的目录下,如:D:\memcached,在命令行中然后输入:D:\memcached\memcached.exe -d install,即可完成安装。输入:D:\memcached\memcached.exe -d start 进行启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动 ----freefancy!
?
Memcached还有其他的一些常用的命令如下:
-p 监听的端口?
-l 连接的IP地址, 默认是本机?
-d start 启动memcached服务?
-d restart 重起memcached服务?
-d stop|shutdown 关闭正在运行的memcached服务?
-d install 安装memcached服务?
-d uninstall 卸载memcached服务?
-u 以的身份运行 (仅在以root运行的时候有效)?
-m 最大内存使用,单位MB。默认64MB?
-M 内存耗尽时返回错误,而不是删除项?
-c 最大同时连接数,默认是1024?
-f 块大小增长因子,默认是1.25?
-n 最小分配空间,key+value+flags默认是48?
-h 显示帮助
?
按照上面的安装步骤安装之后,使用memcached.exe -m 200来调整最大内存占用之后会发现没有起作用,总是默认的64MB的内存,原因是注册表中并没有写入信息,可以这样来修改。
1、memcached.exe -d shutdown 先关闭memcached服务
2、进入注册表,找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server, 在其中有一个ImagePath项,值为"D:\memcached\memcached.exe" -d runservice,在后面加上-l 127.0.0.1 -m 300 -c 2048
3、memcached.exe -d start 启动memcached服务,这样就将memcached的最大内存修改为了300MB了
------------------------------------------------freefancy------------------------
对Memcached缓存服务的状态查询,可以先telnet连接上服务:telnet 127.0.0.1 11211 ,然后使用 stats命令查看缓存服务的状态,会返回如下的数据:
time: ? ?1255537291服务器当前的unix时间戳?
? ? ? ? total_items: ? ? 54从服务器启动以后存储的items总数量?
? ? ? ? connection_structures: ? ?19 ? ? ? ? ? ?服务器分配的连接构造数?
? ? ? ? version: ? ?1.2.6memcache版本?
? ? ? ? limit_maxbytes: ? ?67108864分配给memcache的内存大小(字节)?
? ? ? ? cmd_get: ? ?1645get命令(获取)总请求次数?
? ? ? ? evictions: ? ?0为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)?
? ? ? ? total_connections: ? ?19从服务器启动以后曾经打开过的连接数?
? ? ? ? bytes: ? ?248723当前服务器存储items占用的字节数?
? ? ? ? threads: ? ?1当前线程数?
? ? ? ? get_misses: ? ?82总未命中次数?
? ? ? ? pointer_size: ? ?32当前操作系统的指针大小(32位系统一般是32bit)?
? ? ? ? bytes_read: ? ?490982总读取字节数(请求字节数)?
? ? ? ? uptime: ? ?161服务器已经运行的秒数?
? ? ? ? curr_connections: ? ?18当前打开着的连接数?
? ? ? ? pid: ? ?2816memcache服务器的进程ID?
? ? ? ? bytes_written: ? ?16517259总发送字节数(结果字节数)?
? ? ? ? get_hits: ? ?1563总命中次数?
? ? ? ? cmd_set: ? ?54set命令(保存)总请求次数?
? ? ? ? curr_items: ? ?28服务器当前存储的items数量
?