memcahce 介绍以及安装以及扩展的安装
时间:2015-01-19 13:36 来源:linux.it.net.cn 作者:IT
简单介绍:
memcache是一个高性能的分布式的内存对象缓存系统。通过在内存里维护一个巨大的hash表.
守护进程名: memcached
端口号:11211
单进程
依赖 libevent
安装memcached
window:
memcache -d install #安装到系统服务里
memcache -d uninstall #卸载
memcached.exe -m 1024 -l 127.0.0.1 -p 11211 -d start #启动
linux
依赖 libevent :http://libevent.org/
memcached-1.4.15.tar.gz 下载地址:https://code.google.com/p/memcached/downloads/list
./configure --prefix=/usr/local/memcached #如果libevent的自定义目录安装的需要指定libevent的安装目录 --with-libevent=PATH
make && make install
/usr/local/bin/memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid #启动
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是1024MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid 方便结束进程,
安装memcache扩展(window太简单了,这里不做介绍)
下载地址:http://pecl.php.net/package/memcache 这里用 memcache-2.2.6.tgz
tar -zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
make && make install
#修改php.ini文件添加 extension = "memcache.so"
/usr/local/php/sbin/php-fpm -t #检测配置文件
kill -USR2 `cat /usr/local/php//var/php-fpm.pid` #重启php-fpm服务
stats
pid
memcache服务器的进程ID
uptime
服务器已经运行的秒数
time
服务器当前的unix时间戳
version
memcache版本
pointer_size
当前操作系统的指针大小(32位系统一般是32bit)
rusage_user
进程的累计用户时间
rusage_system
进程的累计系统时间
curr_items
服务器当前存储的items数量
total_items
从服务器启动以后存储的items总数量
bytes
当前服务器存储items占用的字节数
curr_connections
当前打开着的连接数
total_connections
从服务器启动以后曾经打开过的连接数
connection_structures
服务器分配的连接构造数
cmd_get
get命令(获取)总请求次数
cmd_set
set命令(保存)总请求次数
get_hits
总命中次数
get_misses
总未命中次数
evictions
为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)
bytes_read
总读取字节数(请求字节数)
bytes_written
总发送字节数(结果字节数)
limit_maxbytes
分配给memcache的内存大小(字节)
threads
当前线程数
telnet 可操作命令:
Command
Description
Example
get
Reads a value
get mykey
set
Set a key unconditionally
set mykey 0 60 5
add
Add a new key
add newkey 0 60 5
replace
Overwrite existing key
replace key 0 60 5
append
Append data to existing key
append key 0 60 15
prepend
Prepend data to existing key
prepend key 0 60 15
incr
Increments numerical key value by given number
incr mykey 2
decr
Decrements numerical key value by given number
decr mykey 5
delete
Deletes an existing key
delete mykey
flush_all
Invalidate specific items immediately
flush_all
Invalidate all items in n seconds
flush_all 900
stats
Prints general statistics
stats
Prints memory statistics
stats slabs
Prints memory statistics
stats malloc
Print higher level allocation statistics
stats items
stats detail
stats sizes
Resets statistics
stats reset
version
Prints server version.
version
verbosity
Increases log level
verbosity
quit
Terminate telnet session
quit
可用参数
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB ,最大好像2G
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
自带pecl命令快速安装memcache扩展(快捷)
/usr/local/php/bin/pecl install memcache #运行上述命令,会自动帮你安装,同样适用于其他扩展
(责任编辑:IT)
简单介绍: memcache是一个高性能的分布式的内存对象缓存系统。通过在内存里维护一个巨大的hash表.
守护进程名: memcached 端口号:11211 单进程 依赖 libevent
安装memcached window: memcache -d install #安装到系统服务里 memcache -d uninstall #卸载 memcached.exe -m 1024 -l 127.0.0.1 -p 11211 -d start #启动 linux 依赖 libevent :http://libevent.org/ memcached-1.4.15.tar.gz 下载地址:https://code.google.com/p/memcached/downloads/list ./configure --prefix=/usr/local/memcached #如果libevent的自定义目录安装的需要指定libevent的安装目录 --with-libevent=PATH make && make install /usr/local/bin/memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid #启动 -d选项是启动一个守护进程, -m是分配给Memcache使用的内存数量,单位是MB,我这里是1024MB, -u是运行Memcache的用户,我这里是root, -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1, -p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口, -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定, -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid 方便结束进程,
安装memcache扩展(window太简单了,这里不做介绍) 下载地址:http://pecl.php.net/package/memcache 这里用 memcache-2.2.6.tgz
tar -zxvf memcache-2.2.6.tgz cd memcache-2.2.6 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache make && make install
#修改php.ini文件添加 extension = "memcache.so"
stats
telnet 可操作命令:
可用参数 -p 监听的端口 -l 连接的IP地址, 默认是本机 -d start 启动memcached服务 -d restart 重起memcached服务 -d stop|shutdown 关闭正在运行的memcached服务 -d install 安装memcached服务 -d uninstall 卸载memcached服务 -u 以的身份运行 (仅在以root运行的时候有效) -m 最大内存使用,单位MB。默认64MB ,最大好像2G -M 内存耗尽时返回错误,而不是删除项 -c 最大同时连接数,默认是1024 -f 块大小增长因子,默认是1.25 -n 最小分配空间,key+value+flags默认是48 -h 显示帮助
自带pecl命令快速安装memcache扩展(快捷)
/usr/local/php/bin/pecl install memcache #运行上述命令,会自动帮你安装,同样适用于其他扩展
(责任编辑:IT) |