安装Memcached及Memcached配置和状态查询

安装Memcached及Memcached配置和状态查询

          要想使用Memcached做缓存首先需要安装Memcached服务,安装方法如下:

      1. 下载Memcached:http://code.jellycan.com/memcached/现在的最新版本是1.2.6.注意下载正确的版本,windows 服务的话下载win32 binary。

      2.解压之后放在硬盘的目录下,如:D:\memcached. 然后在运行中输入cmd进入命令行,进入到Memcached.exe 所在的目录,例如:D:\memcached,然后输入:Memcached –d install,即可完成安装。

          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 –m 200来调整最大内存占用之后会发现没有起作用,总是默认的64MB的内存,在网上搜了一下,原因是注册表中并没有写入信息,可以这样来修改。

         1. memcached –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 3000 -c 2048。

        3.memcached –d start 启动memcached服务,这样就将memcached的最大内存修改为了3000MB。

        对Memcached缓存服务的状态查询,可以先telnet连接上服务:telnet 127.0.0.1 11211 ,然后使用 stats命令查看缓存服务的状态,会返回如下的数据:  

        time:    1255537291                               服务器当前的unix时间戳
        total_items:    54                                     从服务器启动以后存储的items总数量
        connection_structures:    19                    服务器分配的连接构造数
        version:    1.2.6                                        memcache版本
        limit_maxbytes:    67108864                    分配给memcache的内存大小(字节)
        cmd_get:    1645                                      get命令(获取)总请求次数
        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:    2816                                               memcache服务器的进程ID
        bytes_written:    16517259                     总发送字节数(结果字节数)
        get_hits:    1563                                      总命中次数
        cmd_set:    54                                          set命令(保存)总请求次数
        curr_items:    28                                       服务器当前存储的items数量

转载:
    http://fhuan123.iteye.com/blog/1714178

猜你喜欢

转载自username2.iteye.com/blog/1714348