Memcached是一个基于key=>value的分布式对象缓存系统,虽说现在redis的功能相对强大,但是某些场景Memcached还是占有优势,如数据库缓存。
×以下安装均在CentOS 5/6 64位操作系统上完成×
目录:
Libevent的安装
Memcached的安装与配置
Zabbix监控Memcached
Web管理Memcached
1.Libevent安装
1
2
3
|
wget
tar
zxf release-1.4.15-stable.
tar
.gz
cd
libevent-release-1.4.15-stable/
|
一般来说直接运行./configure就可以的,而且里面的文档也是这样说的
[root@Nginx libevent-release-1.4.15-stable]# ./configure
-bash: ./configure: No such file or directory
会发现提示错误,其实这个时候还没有生成configure文件,需要执行以下目录下的./autogen.sh
[root@Nginx libevent-release-1.4.15-stable]# ./autogen.sh
./autogen.sh: line 11: aclocal: command not found
又提示找不到aclocal,这是因为没有安装autoconf automake libtool
1
2
3
4
|
yum -y
install
autoconf automake libtool
.
/autogen
.sh
.
/configure
--prefix=
/usr/local/libevent1
.4.15
make
&&
make
install
|
注意:libevent安装的时候需要先生成configure文件,这里应该会走不少弯路
2.Memcached的安装
1
2
3
4
5
6
|
wget
tar
zxf memcached-1.4.25.
tar
.gz
cd
memcached-1.4.25
.
/configure
--prefix=
/usr/local/memcached1
.4.25 --with-libevent=
/usr/local/libevent1
.4.15
#注意这里需要指定libevent的安装地址
make
&&
make
install
|
memcached命令行监控工具:
将附件中的memcached-tool上传到/usr/local/memcached1.4.25/bin目录下
将附件中的memcached文件上传到/etc/init.d/目录下
1
2
3
4
|
chmod
+x
/etc/init
.d
/memcached
chmod
+x
/usr/local/memcached1
.4.25
/bin/memcached-tool
mkdir
-p
/var/run/memcached
ln
-s
/usr/local/memcached1
.4.25
/bin/
*
/usr/bin/
|
如果需要自定义memcached的启动参数,可以直接修改/etc/init.d/memcached文件
PORT=11211
USER=nobody
MAXCONN=10240
CACHESIZE=3096
OPTIONS=""
Memcache的状态查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
[root@Nginx ~]
# memcached-tool 127.0.0.1:11211 stats
#127.0.0.1:11211 Field Value
accepting_conns 1
auth_cmds 0
auth_errors 0
bytes 0
bytes_read 7
bytes_written 0
cas_badval 0
cas_hits 0
cas_misses 0
cmd_flush 0
cmd_get 0
cmd_set 0
cmd_touch 0
conn_yields 0
connection_structures 11
crawler_items_checked 0
crawler_reclaimed 0
curr_connections 10
curr_items 0
decr_hits 0
decr_misses 0
delete_hits 0
delete_misses 0
evicted_unfetched 0
evictions 0
expired_unfetched 0
get_hits 0
get_misses 0
hash_bytes 524288
hash_is_expanding 0
hash_power_level 16
incr_hits 0
incr_misses 0
libevent 1.4.15
limit_maxbytes 3246391296
listen_disabled_num 0
lrutail_reflocked 0
malloc_fails 0
pid 13376
pointer_size 64
reclaimed 0
reserved_fds 20
rusage_system 0.000999
rusage_user 0.000000
threads 4
time
1452663956
time_in_listen_disabled_us 0
total_connections 11
total_items 0
touch_hits 0
touch_misses 0
uptime 13
version 1.4.25
|
以上是memcached的状态项目
3.Zabbix监控脚本:
在zabbix_agentd.conf文件末尾添加
1
|
UserParameter=memcached.stats[*],
/usr/bin/memcached-tool
127.0.0.1:11211 stats|
awk
'/$1/{print $$2}'
|
head
-1
|
然后重启zabbix_agentd服务
然后导入zabbix memcached模板
4.利用memadmin监控管理memcached
这个需要在一台安装了php环境带有memcache模块下运行
下载地址:http://down.51cto.com/data/2149158
总体来说memcached的安装还是比较简单的,而且还带有简单的状态接口,便于我们对其进行监控。
附件:http://down.51cto.com/data/2367288
本文转自 rong341233 51CTO博客,原文链接:http://blog.51cto.com/fengwan/1734550