Memcached 安装配置
程序员文章站
2022-03-10 20:20:38
...
Memcache知识点梳理 :http://369369.blog.51cto.com/319630/833234/
Memcached 教程 :http://www.runoob.com/memcached/memcached-tutorial.html
MemCache超详细解读:http://www.csdn.net/article/2016-03-16/2826609
安装libevent
先到官网http://libevent.org/下载最新版本压缩包并解压
配置目录:
编译:
安装
检查是否安装成功:
安装memcached
获取memcached源码:
解压
配置安装目录:
...
编译:
测试:
安装:
查看启动参数配置
启动memcached
连接memcached
具体Stats状态输出的解读可以查看这篇文章:
MemCache超详细解读:http://www.csdn.net/article/2016-03-16/2826609
这里显示了很多状态信息,下边详细解释每个状态项:
pid: memcache服务器进程ID
uptime:服务器已运行秒数
time:服务器当前Unix时间戳
version:memcache版本
pointer_size:操作系统指针大小
rusage_user:进程累计用户时间
rusage_system:进程累计系统时间
curr_connections:当前连接数量
total_connections:Memcached运行以来连接总数
connection_structures:Memcached分配的连接结构数量
cmd_get:get命令请求次数
cmd_set:set命令请求次数
cmd_flush:flush命令请求次数
get_hits:get命令命中次数
get_misses:get命令未命中次数
delete_misses:delete命令未命中次数
delete_hits:delete命令命中次数
incr_misses:incr命令未命中次数
incr_hits:incr命令命中次数
decr_misses:decr命令未命中次数
decr_hits:decr命令命中次数
cas_misses:cas命令未命中次数
cas_hits:cas命令命中次数
cas_badval:使用擦拭次数
auth_cmds:认证命令处理的次数
auth_errors:认证失败数目
bytes_read:读取总字节数
bytes_written:发送总字节数
limit_maxbytes:分配的内存总大小(字节)
accepting_conns:服务器是否达到过最大连接(0/1)
listen_disabled_num:失效的监听数
threads:当前线程数
conn_yields:连接操作主动放弃数目
bytes:当前存储占用的字节数
curr_items:当前存储的数据总数
total_items:启动以来存储的数据总数
evictions:LRU释放的对象数目
reclaimed:已过期的数据条目来存储新数据的数目
Memcached 教程 :http://www.runoob.com/memcached/memcached-tutorial.html
MemCache超详细解读:http://www.csdn.net/article/2016-03-16/2826609
安装libevent
先到官网http://libevent.org/下载最新版本压缩包并解压
[memcached@donald Documents]$ ls libevent-2.1.8-stable.tar.gz memcached-1.5.2 memcached-1.5.2.tar.gz [memcached@donald Documents]$ tar -zxvf libevent-2.1.8-stable.tar.gz
配置目录:
[memcached@donald libevent-2.1.8-stable]$./configure --prefix=/usr
编译:
[memcached@donald libevent-2.1.8-stable]$ make GEN test/rpcgen-attempted GEN include/event2/event-config.h make all-am make[1]: Entering directory `/home/memcached/Documents/libevent-2.1.8-stable' ...
安装
[memcached@donald libevent-2.1.8-stable]$ sudo make install
检查是否安装成功:
[memcached@donald libevent-2.1.8-stable]$ ls -al /usr/lib | grep libevent lrwxrwxrwx 1 root root 21 Oct 9 12:58 libevent-2.1.so.6 -> libevent-2.1.so.6.0.2 -rwxr-xr-x 1 root root 1325594 Oct 9 12:58 libevent-2.1.so.6.0.2 -rw-r--r-- 1 root root 2461544 Oct 9 12:58 libevent.a lrwxrwxrwx 1 root root 26 Oct 9 12:58 libevent_core-2.1.so.6 -> libevent_core-2.1.so.6.0.2 ... [memcached@donald libevent-2.1.8-stable]$
安装memcached
获取memcached源码:
memcached@donald memcached-1.5.2]$wget http://memcached.org/latest
解压
memcached@donald memcached-1.5.2]$tar -zxvf memcached-1.x.x.tar.gz [memcached@donald Documents]$ cd memcached-1.5.2/
配置安装目录:
[memcached@donald memcached-1.5.2]$ sudo ./configure --prefix=/usr/local --with-libevent=/usr checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c
...
编译:
[memcached@donald memcached-1.5.2]$ sudo make make all-recursive make[1]: Entering directory `/home/memcached/Documents/memcached-1.5.2' Making all in doc make[2]: Entering directory `/home/memcached/Documents/memcached-1.5.2/doc' make all-am make[3]: Entering directory `/home/memcached/Documents/memcached-1.5.2/doc' ...
测试:
[memcached@donald memcached-1.5.2]$ sudo make test
安装:
[memcached@donald memcached-1.5.2]$ [memcached@donald memcached-1.5.2]$ sudo make install make install-recursive make[1]: Entering directory `/home/memcached/Documents/memcached-1.5.2' Making install in doc make[2]: Entering directory `/home/memcached/Documents/memcached-1.5.2/doc' make install-am make[3]: Entering directory `/home/memcached/Documents/memcached-1.5.2/doc' make[4]: Entering directory `/home/memcached/Documents/memcached-1.5.2/doc' make[4]: Nothing to be done for `install-exec-am'. /bin/mkdir -p '/usr/local/share/man/man1' /bin/install -c -m 644 memcached.1 '/usr/local/share/man/man1' make[4]: Leaving directory `/home/memcached/Documents/memcached-1.5.2/doc' make[3]: Leaving directory `/home/memcached/Documents/memcached-1.5.2/doc' make[2]: Leaving directory `/home/memcached/Documents/memcached-1.5.2/doc' make[2]: Entering directory `/home/memcached/Documents/memcached-1.5.2' make[3]: Entering directory `/home/memcached/Documents/memcached-1.5.2' /bin/mkdir -p '/usr/local/bin' /bin/install -c memcached '/usr/local/bin' /bin/mkdir -p '/usr/local/include/memcached' /bin/install -c -m 644 protocol_binary.h '/usr/local/include/memcached' make[3]: Leaving directory `/home/memcached/Documents/memcached-1.5.2' make[2]: Leaving directory `/home/memcached/Documents/memcached-1.5.2' make[1]: Leaving directory `/home/memcached/Documents/memcached-1.5.2' [memcached@donald memcached-1.5.2]$
查看启动参数配置
[memcached@donald Documents]$ memcached -h memcached 1.5.2 -p, --port=<num> TCP port to listen on (default: 11211) TCP 监听端口 -U, --udp-port=<num> UDP port to listen on (default: 11211, 0 is off) UDP 监听端口 -s, --unix-socket=<file> UNIX socket to listen on (disables network support) -A, --enable-shutdown enable ascii "shutdown" command -a, --unix-mask=<mask> access mask for UNIX socket, in octal (default: 0700) -l, --listen=<addr> interface to listen on (default: INADDR_ANY) 监听地址 -d, --daemon run as a daemon 以守候模式运行 -r, --enable-coredumps maximize core file limit 最大核心文件限制 -u, --user=<user> assume identity of <username> (only when run as root) 运行用户 -m, --memory-limit=<num> item memory in megabytes (default: 64 MB) 内存大小 -M, --disable-evictions return error on memory exhausted instead of evicting 内存耗尽时返回错误,而不是删除,即不用LRU算法 -c, --conn-limit=<num> max simultaneous connections (default: 1024) 最大连接数 -k, --lock-memory lock down all paged memory -v, --verbose verbose (print errors/warnings while in event loop) -vv very verbose (also print client commands/responses) -vvv extremely verbose (internal state transitions) -h, --help print this help and exit -i, --license print memcached and libevent license -V, --version print version and exit -P, --pidfile=<file> save PID in <file>, only used with -d option 进程的pid存放地点,此处“p”为大写“P” -f, --slab-growth-factor=<num> chunk size growth factor (default: 1.25) 块大小增长因子,默认是1.25 -n, --slab-min-size=<bytes> min space used for key+value+flags (default: 48) 块最小size -L, --enable-largepages try to use large memory pages (if available) -D <char> Use <char> as the delimiter between key prefixes and IDs. This is used for per-prefix stats reporting. The default is ":" (colon). If this option is specified, stats collection is turned on automatically; if not, then it may be turned on by sending the "stats detail on" command to the server. -t, --threads=<num> number of threads to use (default: 4) 线程数 -R, --max-reqs-per-event maximum number of requests per event, limits the requests processed per connection to prevent starvation (default: 20) -C, --disable-cas disable use of CAS -b, --listen-backlog=<num> set the backlog queue limit (default: 1024) -B, --protocol=<name> protocol - one of ascii, binary, or auto (default) -I, --max-item-size=<num> adjusts max item size (default: 1mb, min: 1k, max: 128m) -F, --disable-flush-all disable flush_all command -X, --disable-dumping disable stats cachedump and lru_crawler metadump -o, --extended comma separated list of extended options most options have a 'no_' prefix to disable - maxconns_fast: immediately close new connections after limit - hashpower: an integer multiplier for how large the hash table should be. normally grows at runtime. set based on "STAT hash_power_level" - tail_repair_time: time in seconds for how long to wait before forcefully killing LRU tail item. disabled by default; very dangerous option. - hash_algorithm: the hash table algorithm default is murmur3 hash. options: jenkins, murmur3 - lru_crawler: enable LRU Crawler background thread - lru_crawler_sleep: microseconds to sleep between items default is 100. - lru_crawler_tocrawl: max items to crawl per slab per run default is 0 (unlimited) - lru_maintainer: enable new LRU system + background thread - hot_lru_pct: pct of slab memory to reserve for hot lru. (requires lru_maintainer) - warm_lru_pct: pct of slab memory to reserve for warm lru. (requires lru_maintainer) - hot_max_factor: items idle > cold lru age * drop from hot lru. - warm_max_factor: items idle > cold lru age * this drop from warm. - temporary_ttl: TTL's below get separate LRU, can't be evicted. (requires lru_maintainer) - idle_timeout: timeout for idle connections - slab_chunk_max: (EXPERIMENTAL) maximum slab size. use extreme care. - watcher_logbuf_size: size in kilobytes of per-watcher write buffer. - worker_logbuf_size: size in kilobytes of per-worker-thread buffer read by background thread, then written to watchers. - track_sizes: enable dynamic reports for 'stats sizes' command. - no_inline_ascii_resp: save up to 24 bytes per item. small perf hit in ASCII, no perf difference in binary protocol. speeds up all sets. - modern: enables options which will be default in future. currently: nothing - no_modern: uses defaults of previous major version (1.4.x) [memcached@donald Documents]$
启动memcached
[memcached@donald Documents]$ memcached -p 11211 -d -u memcached -l 192.168.126.128 -c 1024 [memcached@donald Documents]$ netstat -ntlp (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.126.128:11211 0.0.0.0:* LISTEN 29555/memcached tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN - tcp6 0 0 :::3306 :::* LISTEN - tcp6 0 0 :::22 :::* LISTEN - tcp6 0 0 ::1:631 :::* LISTEN - [memcached@donald Documents]$
连接memcached
[memcached@donald Documents]$ telnet 192.168.126.128 11211 Trying 192.168.126.128... Connected to 192.168.126.128. Escape character is '^]'. stats 查看状态 STAT pid 29555 STAT uptime 382 STAT time 1507538855 STAT version 1.5.2 STAT libevent 2.1.8-stable STAT pointer_size 64 STAT rusage_user 0.146294 STAT rusage_system 0.089402 STAT max_connections 1024 STAT curr_connections 5 STAT total_connections 6 STAT rejected_connections 0 STAT connection_structures 6 STAT reserved_fds 20 STAT cmd_get 0 STAT cmd_set 0 STAT cmd_flush 0 STAT cmd_touch 0 STAT get_hits 0 STAT get_misses 0 STAT get_expired 0 STAT get_flushed 0 STAT delete_misses 0 STAT delete_hits 0 STAT incr_misses 0 STAT incr_hits 0 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT touch_hits 0 STAT touch_misses 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 7 STAT bytes_written 0 STAT limit_maxbytes 67108864 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT time_in_listen_disabled_us 0 STAT threads 4 STAT conn_yields 0 STAT hash_power_level 16 STAT hash_bytes 524288 STAT hash_is_expanding 0 STAT slab_reassign_rescues 0 STAT slab_reassign_chunk_rescues 0 STAT slab_reassign_evictions_nomem 0 STAT slab_reassign_inline_reclaim 0 STAT slab_reassign_busy_items 0 STAT slab_reassign_busy_deletes 0 STAT slab_reassign_running 0 STAT slabs_moved 0 STAT lru_crawler_running 0 STAT lru_crawler_starts 765 STAT lru_maintainer_juggles 430 STAT malloc_fails 0 STAT log_worker_dropped 0 STAT log_worker_written 0 STAT log_watcher_skipped 0 STAT log_watcher_sent 0 STAT bytes 0 STAT curr_items 0 STAT total_items 0 STAT slab_global_page_pool 0 STAT expired_unfetched 0 STAT evicted_unfetched 0 STAT evicted_active 0 STAT evictions 0 STAT reclaimed 0 STAT crawler_reclaimed 0 STAT crawler_items_checked 0 STAT lrutail_reflocked 0 STAT moves_to_cold 0 STAT moves_to_warm 0 STAT moves_within_lru 0 STAT direct_reclaims 0
具体Stats状态输出的解读可以查看这篇文章:
MemCache超详细解读:http://www.csdn.net/article/2016-03-16/2826609
这里显示了很多状态信息,下边详细解释每个状态项:
pid: memcache服务器进程ID
uptime:服务器已运行秒数
time:服务器当前Unix时间戳
version:memcache版本
pointer_size:操作系统指针大小
rusage_user:进程累计用户时间
rusage_system:进程累计系统时间
curr_connections:当前连接数量
total_connections:Memcached运行以来连接总数
connection_structures:Memcached分配的连接结构数量
cmd_get:get命令请求次数
cmd_set:set命令请求次数
cmd_flush:flush命令请求次数
get_hits:get命令命中次数
get_misses:get命令未命中次数
delete_misses:delete命令未命中次数
delete_hits:delete命令命中次数
incr_misses:incr命令未命中次数
incr_hits:incr命令命中次数
decr_misses:decr命令未命中次数
decr_hits:decr命令命中次数
cas_misses:cas命令未命中次数
cas_hits:cas命令命中次数
cas_badval:使用擦拭次数
auth_cmds:认证命令处理的次数
auth_errors:认证失败数目
bytes_read:读取总字节数
bytes_written:发送总字节数
limit_maxbytes:分配的内存总大小(字节)
accepting_conns:服务器是否达到过最大连接(0/1)
listen_disabled_num:失效的监听数
threads:当前线程数
conn_yields:连接操作主动放弃数目
bytes:当前存储占用的字节数
curr_items:当前存储的数据总数
total_items:启动以来存储的数据总数
evictions:LRU释放的对象数目
reclaimed:已过期的数据条目来存储新数据的数目