官网
http://memcached.org/
下载地址
http://memcached.org/downloads
默认端口
11211
通信
UDP协议 集群间memcached无法通讯
安装
yum 安装版本为memcached-1.4.4-5
源码安装
memcached 运行需要有 libevent 库的支持,因为memcached需要支持非阻塞的IO访问
源码安装 libevent
下载地址
http://www.linuxfromscratch.org/blfs/view/svn/basicnet/libevent.html
[root@tom01 tools]# tar xf libevent-2.1.8-stable.tar.gz
[root@tom01 tools]# cd libevent-2.1.8-stable
[root@tom01 libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent/
[root@tom01 libevent-2.1.8-stable]# make && make install
源码安装 memcached
[root@tom01 tools]# tar xf memcached-1.5.12.tar.gz
[root@tom01 tools]# cd memcached-1.5.12
[root@tom01 memcached-1.5.12]# ./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached
[root@tom01 memcached-1.5.12]# make && make install
设置环境变量
echo “export PATH=$PATH:/usr/local/memcached/bin/” >>/etc/profile
. /etc/profile
创建memcached用户
[root@tom01 memcached-1.5.12]# useradd memcache -s /sbin/nologin -M
启动memcached(多实例)
[root@tom01 memcached-1.5.12]# memcached -m 100 -u memcache -p 11211 -c 8192 -d -vv
[root@tom01 memcached-1.5.12]# memcached -m 100 -u memcache -p 11212 -c 8192 -d -vv
[root@tom01 memcached-1.5.12]# netstat -anu|grep 112
udp 0 0 0.0.0.0:11211 0.0.0.0:*
udp 0 0 0.0.0.0:11212 0.0.0.0:*
memcached参数
-m 最大内存使用,单位MB。默认64MB
-u 指定运行账户
-d 后台运行
-vv 显示详细信息
-p 指定端口号(如不加默认端口11211)
-l 监听地址(如不加默认监听全部)
-c 指定并发数 (如不加默认1024)
-M 禁止LRU策略(禁用自动清理缓存),内存耗尽时返回错误
-p 将PID保存在file文件
-f 增长因子,默认1.25
-n 初始chunk=key+suffix+value+32结构体,默认48字节
-L启用大内存页,可以降低内存浪费,改进性能
-l 调整分配slab页的大小,默认1M,最小1k到128M
-t 线程数,默认4。由于memcached采用NIO,所以更多线程没有太多作用
-R 每个event连接最大并发数,默认20
-C 禁用CAS命令(可以禁止版本计数,减少开销)