memcache安装运行、cacti监控memcache实战
简介Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。Memcache官方网站:http://memcached.org/1,安装下载地址: http://www.memcached.org/downloads,我们线上使用的比较稳定的版本是1.4.15,如果官网找不到以前的版本了,可以去我的csdn资源里面下载此版本,下载地址:memcache1.4.15 :http://download.iyunv.com/detail/mchdba/7562193libevent2:http://download.iyunv.com/detail/mchdba/7562201或者去官网下载最新的:wgethttp://memcached.org/latest#tar -xvf memcached-1.4.15.tar.gz# cd memcached-1.4.15# ./configure && make && make test && sudo make install……checking for library containing clock_gettime... -lrtchecking for library containing socket... none requiredchecking for library containing gethostbyname... none requiredchecking for libevent directory... configure: error: libevent is required.You can get it from http://www.monkey.org/~provos/libevent/ If it's already installed, specify its path using --with-libevent=/dir/ 看到提示,需要先安装libevent包,lebevent主要用于socket的处理, wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar -xvf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure--prefix=/usr/local/libevent make make install #删除原来的目录,重新解压缩进行编译安装#rm -rf /root/memcached-1.4.15/# tar -xvf memcached-1.4.15.tar.gz# cd /root/memcached-1.4.15/# ./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcache# make# make test# make install 2,如何运行memcache/usr/local/bin/memcached -d -m 10-u root -l 10.xx.xx.xx -p 12000 -c 1024 –P /tmp/memcached.pid##相关选项说明-d 表示启动一个守护进程-m 是分配给memcached使用的内存-u 运行memcached的用户-l 是memcached监听的ip-p 是memcached监听的端口-c memcache运行的最大并发连接数-P 是设置memcache的pid文件 # /usr/local/memcache/bin/memcached -d -u nobody -m 1024 -t 64 -c 2048 -k -I 1M -L -l 127.0.0.1 -p11211 -P /var/memcached/memcached_11211.pidCannot enable large pages on this system(There is no Linux support as of this version)#Cannot enable large pages,启动命令不合适,换成如下/usr/local/memcache/bin/memcached -d -m 1024 -u root -l 10.xx.xx.xx -p 11211 -c 2048 -P /var/memcached/memcached.pid 3,实现service启动停止以及查看状态然后执行如下,加载到启动项:chkconfig --add memcache#注册服务chmod 700 memcachechkconfig --level 345 memcache on#指定服务在3、4、5级别运行 4,简单测试# telnet 127.0.0.1 11211# 存一个简单的key1,值为123456Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.set key1 0 0 6123456STORED#存储成功quitConnection closed by foreign host.# telnet 127.0.0.1 11211# 去获取这个key1的值Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.get key1VALUE key1 0 6123456#获取成功END 5,memcache的使用有些是转载的,原文地址:http://blog.iyunv.com/heiyeshuwu 6,memcache性能监控6.1,安装python插件下载地址:http://download.iyunv.com/detail/wufongming/1159646tar -xvf python-memcached-latest.tar.gzcd python-memcached-1.43python setup.py install 运行上面的命令的时候出现如下错误Traceback (most recent call last):File "setup.py", line 3, in ?from setuptools import setupImportError: No module named setuptools解决办法:yum -y install python-setuptools安装成功后再次 python setup.py install 安装就可以成功了。
6.2,下载安装插件# wget http://s1.dlnws.com/dealnews/developers/cacti-memcached-1.0.tar.gz解压缩:# tar -xvf cacti-memcached-1.0.tar.gzcacti-memcached-1.0/cacti-memcached-1.0/cacti_memcached_host_template.xmlcacti-memcached-1.0/INSTALLcacti-memcached-1.0/memcached.pycacti-memcached-1.0/README# 将监控文件memcached.py复制到cacti的scripts文件目录下# pwd/root/soft/cacti-memcached-1.0# cp memcached.py /var/www/html/cacti/scripts/# 赋予执行用户权限# chown -R apache.apache /var/www/html/cacti/scripts/memcached.py# 6.3,在cacti界面导入memcache模板文件将解压缩的cacti_memcached_host_template.xml文件copy到本地E:\u\memcache,然后进入“console”,再进入“Import Templates”,再进入“选择文件”,选择E:\u\memcache下的cacti_memcached_host_template.xml文件,然后点击右下角的“Import”按钮。导入完后,会在Graph Templates看到memcache的6项监控服务,如下图所示:
6.4,在界面添加memcache主机服务进入“Devices”,点击右上角的“Add”按钮, 填写主机名称和主机ip地址,在“Host Template”下拉框里面选择“Memcached Server”选项,点击右下角的“Save”按钮创建memcache服务主机,如下图所示。
6.5,给memcache主机添加监控图选择“Devices”,点击主机名称连接“xx.xx_memcache”,在新的界面中,点击右上角的“Create Graphs for this Host”,然后在新的页面中选择6个Memcache监控选项,点击右下角的“Create”按钮,就创建好了memcache监控图,如下图所示:
6.6,查看memcache监控图 选择“monitor”,再选择右边的“Tree View”,再选择左边的memcache主机名称,就会在右边出现6个监控图,如下所示:(1) Memcached - Bytes Used
(2)Memcached - Cache Hits and Misses
(3)Memcached - Current Connections
(4)Memcached - Items Cached (5)Memcached - Network Traffic (bits/sec) (6)Memcached - Requests/sec (get/set) 以上设置只是针对默认端口11211,但是当你的端口不是11211,而是其他的端口,比如我的是12000,这样的话你就要对你的cacti的data source做下小更改了,操作如下:Console---Data Input Methods--Memcached – Statistics找到Input String的值python /scripts/memcached.py更改成:python /scripts/memcached.py –p 12000如果你是其他端口的,只要将端口号更改成其他的值就可以了! 6.7,遇到的问题总结(1)有图出不来数据,显示为nan值,问题出在,没有安装 python-memcached-latest.tar.gz插件导致。安装完插件后,重启cacti服务,图上的数据显示出来了。 (2)网卡监控流量选项选择不了,报错: This data query returned 0 rows, perhaps there was a problem executing this data query. You can run this data query in debug mode to get more information.
解决方案如下:a,第一种
打开默认的/etc/snmp/snmpd.conf文件,更改如下配置:
1、查找以下字段:
sec.namesource community
com2sec notConfigUserdefault public
将"comunity"字段改为你要设置的密码.比如"public". 2、查找以下字段:
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read writenotif
accessnotConfigGroup "" any noauth exactall none none
将"systemview"字段改为all.3、查找以下字段:
# incl/excl subtree mask
#view all included.1 80
将该行前面的"#"去掉.然后重启snmpd服务,就OK了。 b,另外还有一种办法如下:如下:
编辑linux主机下的/etc/snmp/snmpd.conf文件
找到62行:
accessnotConfigGroup "" any noauth exactsystemview none none
修改成:(如果有#号,把#号去掉)
accessnotConfigGroup "" any noauth exactmib2 none none
找到89行,把改行的#去掉:
#view mib2 included.iso.org.dod.internet.mgmt.mib-2 fc
修改成:
view mib2 included.iso.org.dod.internet.mgmt.mib-2 fc
重起snmpd服务,service snmpd restart
参考文章地址:http://blog.chinaunix.net/uid-20639775-id-154601.htmlhttps://code.google.com/p/memcached/wiki/NewStart简介Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。Memcache官方网站:http://memcached.org/
1,安装下载地址: http://www.memcached.org/downloads,我们线上使用的比较稳定的版本是1.4.15,如果官网找不到以前的版本了,可以去我的csdn资源里面下载此版本,下载地址:memcache1.4.15 :http://download.iyunv.com/detail/mchdba/7562193libevent2:http://download.iyunv.com/detail/mchdba/7562201或者去官网下载最新的:wgethttp://memcached.org/latest#tar -xvf memcached-1.4.15.tar.gz# cd memcached-1.4.15# ./configure && make && make test && sudo make install……checking for library containing clock_gettime... -lrtchecking for library containing socket... none requiredchecking for library containing gethostbyname... none requiredchecking for libevent directory... configure: error: libevent is required.You can get it from http://www.monkey.org/~provos/libevent/ If it's already installed, specify its path using --with-libevent=/dir/ 看到提示,需要先安装libevent包,lebevent主要用于socket的处理, wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar -xvf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure--prefix=/usr/local/libevent make make install #删除原来的目录,重新解压缩进行编译安装#rm -rf /root/memcached-1.4.15/# tar -xvf memcached-1.4.15.tar.gz# cd /root/memcached-1.4.15/# ./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcache# make# make test# make install 2,如何运行memcache/usr/local/bin/memcached -d -m 10-u root -l 10.xx.xx.xx -p 12000 -c 1024 –P /tmp/memcached.pid##相关选项说明-d 表示启动一个守护进程-m 是分配给memcached使用的内存-u 运行memcached的用户-l 是memcached监听的ip-p 是memcached监听的端口-c memcache运行的最大并发连接数-P 是设置memcache的pid文件 # /usr/local/memcache/bin/memcached -d -u nobody -m 1024 -t 64 -c 2048 -k -I 1M -L -l 127.0.0.1 -p11211 -P /var/memcached/memcached_11211.pidCannot enable large pages on this system(There is no Linux support as of this version)#Cannot enable large pages,启动命令不合适,换成如下/usr/local/memcache/bin/memcached -d -m 1024 -u root -l 10.xx.xx.xx -p 11211 -c 2048 -P /var/memcached/memcached.pid 3,实现service启动停止以及查看状态然后执行如下,加载到启动项:chkconfig --add memcache#注册服务chmod 700 memcachechkconfig --level 345 memcache on#指定服务在3、4、5级别运行 4,简单测试# telnet 127.0.0.1 11211# 存一个简单的key1,值为123456Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.set key1 0 0 6123456STORED#存储成功quitConnection closed by foreign host.# telnet 127.0.0.1 11211# 去获取这个key1的值Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.get key1VALUE key1 0 6123456#获取成功END 5,memcache的使用有些是转载的,原文地址:http://blog.iyunv.com/heiyeshuwu 6,memcache性能监控6.1,安装python插件下载地址:http://download.iyunv.com/detail/wufongming/1159646tar -xvf python-memcached-latest.tar.gzcd python-memcached-1.43python setup.py install 运行上面的命令的时候出现如下错误Traceback (most recent call last):File "setup.py", line 3, in ?from setuptools import setupImportError: No module named setuptools解决办法:yum -y install python-setuptools安装成功后再次 python setup.py install 安装就可以成功了。6.2,下载安装插件# wget http://s1.dlnws.com/dealnews/developers/cacti-memcached-1.0.tar.gz解压缩:# tar -xvf cacti-memcached-1.0.tar.gzcacti-memcached-1.0/cacti-memcached-1.0/cacti_memcached_host_template.xmlcacti-memcached-1.0/INSTALLcacti-memcached-1.0/memcached.pycacti-memcached-1.0/README# 将监控文件memcached.py复制到cacti的scripts文件目录下# pwd/root/soft/cacti-memcached-1.0# cp memcached.py /var/www/html/cacti/scripts/# 赋予执行用户权限# chown -R apache.apache /var/www/html/cacti/scripts/memcached.py# 6.3,在cacti界面导入memcache模板文件将解压缩的cacti_memcached_host_template.xml文件copy到本地E:\u\memcache,然后进入“console”,再进入“Import Templates”,再进入“选择文件”,选择E:\u\memcache下的cacti_memcached_host_template.xml文件,然后点击右下角的“Import”按钮。导入完后,会在Graph Templates看到memcache的6项监控服务,如下图所示:
6.4,在界面添加memcache主机服务进入“Devices”,点击右上角的“Add”按钮, 填写主机名称和主机ip地址,在“Host Template”下拉框里面选择“Memcached Server”选项,点击右下角的“Save”按钮创建memcache服务主机,如下图所示。6.5,给memcache主机添加监控图选择“Devices”,点击主机名称连接“xx.xx_memcache”,在新的界面中,点击右上角的“Create Graphs for this Host”,然后在新的页面中选择6个Memcache监控选项,点击右下角的“Create”按钮,就创建好了memcache监控图,如下图所示:
6.6,查看memcache监控图选择“monitor”,再选择右边的“Tree View”,再选择左边的memcache主机名称,就会在右边出现6个监控图,如下所示:(1) Memcached - Bytes Used
(2)Memcached - Cache Hits and Misses
(3)Memcached - Current Connections
(4)Memcached - Items Cached (5)Memcached - Network Traffic (bits/sec) (6)Memcached - Requests/sec (get/set) 以上设置只是针对默认端口11211,但是当你的端口不是11211,而是其他的端口,比如我的是12000,这样的话你就要对你的cacti的data source做下小更改了,操作如下:Console---Data Input Methods--Memcached – Statistics找到Input String的值python /scripts/memcached.py更改成:python /scripts/memcached.py –p 12000如果你是其他端口的,只要将端口号更改成其他的值就可以了! 6.7,遇到的问题总结(1)有图出不来数据,显示为nan值,问题出在,没有安装 python-memcached-latest.tar.gz插件导致。安装完插件后,重启cacti服务,图上的数据显示出来了。 (2)网卡监控流量选项选择不了,报错: This data query returned 0 rows, perhaps there was a problem executing this data query. You can run this data query in debug mode to get more information.
解决方案如下:a,第一种
打开默认的/etc/snmp/snmpd.conf文件,更改如下配置:
1、查找以下字段:
sec.namesource community
com2sec notConfigUserdefault public
将"comunity"字段改为你要设置的密码.比如"public". 2、查找以下字段:
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read writenotif
accessnotConfigGroup "" any noauth exactall none none
将"systemview"字段改为all.3、查找以下字段:
# incl/excl subtree mask
#view all included.1 80
将该行前面的"#"去掉.然后重启snmpd服务,就OK了。 b,另外还有一种办法如下:如下:
编辑linux主机下的/etc/snmp/snmpd.conf文件
找到62行:
accessnotConfigGroup "" any noauth exactsystemview none none
修改成:(如果有#号,把#号去掉)
accessnotConfigGroup "" any noauth exactmib2 none none
找到89行,把改行的#去掉:
#view mib2 included.iso.org.dod.internet.mgmt.mib-2 fc
修改成:
view mib2 included.iso.org.dod.internet.mgmt.mib-2 fc
重起snmpd服务,service snmpd restart
页:
[1]