memcached

Posted 岁月如歌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了memcached相关的知识,希望对你有一定的参考价值。

memcached安装

[root@localhost ~]# cd /usr/local/src

[root@localhost src]#wget http://www.memcached.org/files/memcached-1.4.34.tar.gz

[root@localhost memcached-1.4.34]# cd memcached-1.4.34

[root@localhost src]#wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz

[root@localhost src]# cd libevent-2.0.22

[root@localhost libevent-2.0.22]# ./configure --prefix=/usr/local/libevent

[root@localhost libevent-2.0.22]# make && make install

[root@localhost libevent-2.0.22]# cd /usr/local/src/memcached-1.4.34

[root@localhost memcached-1.4.34]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent

[root@localhost memcached-1.4.34]# make && make install

开启memcached

[root@localhost memcached-1.4.34]# cd /usr/local/memcached

memcached不能用root用户去开启,那么用普通用户开启

[root@localhost memcached]# ./bin/memcached -u xbl &

ok,memcached安装成功

pkill memcached

启动memcached

# /usr/local/memcached/bin/memcached -m 64 -p 11211 -u nobody -d

 

-p <num> tcp port number to listen on (default: 11211) // 监听
的端口
-u <num> udp port number to listen on (default: 0, off)
-s <file> unix socket path to listen on (disables network support)
-a <mask> access mask for unix socket, in octal (default 0700)
-l <ip_addr> interface to listen on, default is indrr_any
-d start tell memcached to start
-d restart tell running memcached to do a graceful restart
-d stop|shutdown tell running memcached to shutdown
-d install install memcached service // 把 memcached 注册成服务
-d uninstall uninstall memcached service
-r maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num> max memory to use for items in megabytes, default is 64
mb //分配给 memcached 的最大内存
-m return error on memory exhausted (rather than removing
items)

-c <num> max simultaneous connections, default is 1024 // 最大
的连接数
-k lock down all paged memory. note that there is a
limit on how much memory you may lock. trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u <username> user;
under sh this is done with \'ulimit -s -l num_kb\').
-v verbose (print errors/warnings while in event loop) //
输出错误信息
-vv very verbose (also print client commands/reponses) //
输出所有信息
-h print this help and exit
-i print memcached and libevent license
-b run a managed instanced (mnemonic: buckets)
-p <file> save pid in <file>, only used with -d option
-f <factor> chunk size growth factor, default 1.25 //增长因子
-n <bytes> minimum space allocated for key+value+flags, default 48

 

来个小例子(key value)

[root@localhost memcached]# /usr/local/memcached/bin/memcached -m 64 -p 11211 -u nobody -d
[root@localhost memcached]# netstat -tupln|grep 11211
tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      24244/memcached     
tcp        0      0 :::11211                    :::*                        LISTEN      24244/memcached     
udp        0      0 0.0.0.0:11211               0.0.0.0:*                               24244/memcached     
udp        0      0 :::11211                    :::*                                    24244/memcached     
[root@localhost memcached]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is \'^]\'.
add name 0 0 5
xiong
STORED
get name
VALUE name 0 5
xiong
END

以上是关于memcached的主要内容,如果未能解决你的问题,请参考以下文章

精华汇总

RabbitMQRedisMemcacheSQLAlchemy

Memcached

memcached

缓存相关

缓存之memcached