阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Memcache安装运行及Cacti监控Memcache实战

490次阅读
没有评论

共计 10869 个字符,预计需要花费 28 分钟才能阅读完成。

简介

Memcache 是 danga.com 的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。Memcache 官方网站:http://memcached.org/

Memcached 安装及启动脚本 http://www.linuxidc.com/Linux/2013-07/87641.htm

PHP 中使用 Memcached 的性能问题 http://www.linuxidc.com/Linux/2013-06/85883.htm

Ubuntu 下安装 Memcached 及命令解释 http://www.linuxidc.com/Linux/2013-06/85832.htm

Memcached 的安装和应用 http://www.linuxidc.com/Linux/2013-08/89165.htm

使用 Nginx+Memcached 的小图片存储方案 http://www.linuxidc.com/Linux/2013-11/92390.htm

Memcached 使用入门 http://www.linuxidc.com/Linux/2011-12/49516p2.htm

1,安装

下载地址:http://www.memcached.org/downloads,我们线上使用的比较稳定的版本是 1.4.15,如果官网找不到以前的版本了,可以去 Linux 公社资源网站里面下载此版本。

memcache1.4.15 与 libevent2 下载地址

—————————————— 分割线 ——————————————

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2014 年资料 /10 月 / 2 日 /Memcache 安装运行及 Cacti 监控 Memcache 实战

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

—————————————— 分割线 ——————————————

或者去官网下载最新的:

wget  http://memcached.org/latest

[root@localhost ~]#tar -xvf memcached-1.4.15.tar.gz

[root@localhost ~]# cd memcached-1.4.15

[root@localhost memcached-1.4.15]# ./configure && make && make test && sudo make install

……

checking for library containing clock_gettime… -lrt

checking for library containing socket… none required

checking for library containing gethostbyname… none required

checking 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

# 删除原来的目录,重新解压缩进行编译安装

[root@localhost ~]#rm -rf /root/memcached-1.4.15/

[root@localhost ~]# tar -xvf memcached-1.4.15.tar.gz

[root@localhost ~]# cd /root/memcached-1.4.15/

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

[root@localhost memcached-1.4.15]# make

[root@localhost memcached-1.4.15]# make test

[root@localhost memcached-1.4.15]# 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 文件

[root@localhost ~]# /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.pid

Cannot enable large pages on this system

(There is no Linux support as of this version)

[root@localhost ~]#

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 memcache

chkconfig –level 345 memcache on  #指定服务在 3、4、5 级别运行

4,简单测试

[root@localhost ~]# telnet 127.0.0.1 11211

# 存一个简单的 key1,值为 123456

Trying 127.0.0.1…

Connected to 127.0.0.1.

Escape character is ‘^]’.

set key1 0 0 6

123456

STORED  #存储成功

quit

Connection closed by foreign host.

[root@localhost ~]# telnet 127.0.0.1 11211

# 去获取这个 key1 的值

Trying 127.0.0.1…

Connected to 127.0.0.1.

Escape character is ‘^]’.

get key1

VALUE key1 0 6

123456  #获取成功

END

5,memcache 的使用

6,memcache 性能监控

6.1,安装 python 插件

下载地址见 Linux 公社资源网站(见本文上面的连接)

tar -xvf python-memcached-latest.tar.gz

cd python-memcached-1.43

python setup.py install

运行上面的命令的时候出现如下错误

Traceback (most recent call last):

File “setup.py”, line 3, in ?

from setuptools import setup

ImportError: No module named setuptools

解决办法:yum -y install python-setuptools

安装成功后再次 python setup.py install 安装就可以成功了。

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-10/107522p2.htm

6.2,下载安装插件
[root@squid-2 soft]# wget http://s1.dlnws.com/dealnews/developers/cacti-memcached-1.0.tar.gz
解压缩:
[root@squid-2 soft]# tar -xvf cacti-memcached-1.0.tar.gz
cacti-memcached-1.0/
cacti-memcached-1.0/cacti_memcached_host_template.xml
cacti-memcached-1.0/INSTALL
cacti-memcached-1.0/memcached.py
cacti-memcached-1.0/README
[root@squid-2 soft]#
 
将监控文件 memcached.py 复制到 cacti 的 scripts 文件目录下
[root@squid-2 cacti-memcached-1.0]# pwd
/root/soft/cacti-memcached-1.0
[root@squid-2 cacti-memcached-1.0]# cp memcached.py /var/www/html/cacti/scripts/
[root@squid-2 cacti-memcached-1.0]#
 
赋予执行用户权限
[root@squid-2 cacti-memcached-1.0]# chown -R apache.apache /var/www/html/cacti/scripts/memcached.py
[root@squid-2 cacti-memcached-1.0]#
 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 项监控服务,如下图所示:
 

Memcache 安装运行及 Cacti 监控 Memcache 实战


6.4,在界面添加 memcache 主机服务
进入“Devices”,点击右上角的“Add”按钮,填写主机名称和主机 ip 地址,在“Host Template”下拉框里面选择“Memcached Server”选项,点击右下角的“Save”按钮创建 memcache 服务主机,如下图所示。

Memcache 安装运行及 Cacti 监控 Memcache 实战


6.5,给 memcache 主机添加监控图
选择“Devices”,点击主机名称连接“xx.xx_memcache”,在新的界面中,点击右上角的“Create Graphs for this Host”,然后在新的页面中选择 6 个 Memcache 监控选项,点击右下角的“Create”按钮,就创建好了 memcache 监控图,如下图所示:

Memcache 安装运行及 Cacti 监控 Memcache 实战


6.6,查看 memcache 监控图
      选择“monitor”,再选择右边的“Tree View”,再选择左边的 memcache 主机名称,就会在右边出现 6 个监控图,如下所示:
(1)Memcached – Bytes Used
Memcache 安装运行及 Cacti 监控 Memcache 实战
(2)Memcached – Cache Hits and Misses

Memcache 安装运行及 Cacti 监控 Memcache 实战


(3)Memcached – Current Connections

Memcache 安装运行及 Cacti 监控 Memcache 实战


(4)Memcached – Items Cached

Memcache 安装运行及 Cacti 监控 Memcache 实战


 
 
(5)Memcached – Network Traffic (bits/sec)

Memcache 安装运行及 Cacti 监控 Memcache 实战


 
 
(6)Memcached – Requests/sec (get/set)

Memcache 安装运行及 Cacti 监控 Memcache 实战


 
 
以上设置只是针对默认端口 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.name  source          community
com2sec notConfigUser  default      public
将 ”comunity” 字段改为你要设置的密码. 比如 ”public”. 
2、查找以下字段:
# Finally, grant the group read-only access to the systemview view.
#      group          context sec.model sec.level prefix read  write  notif
access  notConfigGroup “”      any      noauth    exact  all none none
将 ”systemview” 字段改为 all.
3、查找以下字段:
#          incl/excl subtree                          mask
#view all    included  .1                              80
将该行前面的 ”#” 去掉.
然后重启 snmpd 服务,就 OK 了。
 
b,另外还有一种办法如下:
如下:
编辑 linux 主机下的 /etc/snmp/snmpd.conf 文件
找到 62 行:
access  notConfigGroup “”      any      noauth    exact  systemview none none
修改成:(如果有 #号,把# 号去掉)
access  notConfigGroup “”      any      noauth    exact  mib2 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://www.linuxidc.com/Linux/2014-10/107521.htm
https://code.google.com/p/memcached/wiki/NewStart

————————————– 分割线 ————————————–

RHEL6.4 中使用 Cacti+Spine 监控主机实现发送邮件报警 http://www.linuxidc.com/Linux/2013-11/92795.htm

RHEL6.4 中使用 Cacti+Spine 监控远程主机 http://www.linuxidc.com/Linux/2013-11/92796.htm

CentOS 5.5 完整安装 Cacti+Spine http://www.linuxidc.com/Linux/2011-12/49701.htm

CentOS 6 下 Cacti 搭建文档 http://www.linuxidc.com/Linux/2013-06/86595.htm

RHEL5.9 下 Cacti 监控部署详解 http://www.linuxidc.com/Linux/2013-06/85427.htm

CentOS 6.3 下 Cacti 安装详解 http://www.linuxidc.com/Linux/2013-05/84279.htm

CentOS Linux 下快速安装配置 Cacti 中文版 http://www.linuxidc.com/Linux/2013-03/81627.htm

————————————– 分割线 ————————————–

Cacti 的详细介绍:请点这里
Cacti 的下载地址:请点这里

 

简介

Memcache 是 danga.com 的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。Memcache 官方网站:http://memcached.org/

Memcached 安装及启动脚本 http://www.linuxidc.com/Linux/2013-07/87641.htm

PHP 中使用 Memcached 的性能问题 http://www.linuxidc.com/Linux/2013-06/85883.htm

Ubuntu 下安装 Memcached 及命令解释 http://www.linuxidc.com/Linux/2013-06/85832.htm

Memcached 的安装和应用 http://www.linuxidc.com/Linux/2013-08/89165.htm

使用 Nginx+Memcached 的小图片存储方案 http://www.linuxidc.com/Linux/2013-11/92390.htm

Memcached 使用入门 http://www.linuxidc.com/Linux/2011-12/49516p2.htm

1,安装

下载地址:http://www.memcached.org/downloads,我们线上使用的比较稳定的版本是 1.4.15,如果官网找不到以前的版本了,可以去 Linux 公社资源网站里面下载此版本。

memcache1.4.15 与 libevent2 下载地址

—————————————— 分割线 ——————————————

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2014 年资料 /10 月 / 2 日 /Memcache 安装运行及 Cacti 监控 Memcache 实战

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

—————————————— 分割线 ——————————————

或者去官网下载最新的:

wget  http://memcached.org/latest

[root@localhost ~]#tar -xvf memcached-1.4.15.tar.gz

[root@localhost ~]# cd memcached-1.4.15

[root@localhost memcached-1.4.15]# ./configure && make && make test && sudo make install

……

checking for library containing clock_gettime… -lrt

checking for library containing socket… none required

checking for library containing gethostbyname… none required

checking 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

# 删除原来的目录,重新解压缩进行编译安装

[root@localhost ~]#rm -rf /root/memcached-1.4.15/

[root@localhost ~]# tar -xvf memcached-1.4.15.tar.gz

[root@localhost ~]# cd /root/memcached-1.4.15/

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

[root@localhost memcached-1.4.15]# make

[root@localhost memcached-1.4.15]# make test

[root@localhost memcached-1.4.15]# 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 文件

[root@localhost ~]# /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.pid

Cannot enable large pages on this system

(There is no Linux support as of this version)

[root@localhost ~]#

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 memcache

chkconfig –level 345 memcache on  #指定服务在 3、4、5 级别运行

4,简单测试

[root@localhost ~]# telnet 127.0.0.1 11211

# 存一个简单的 key1,值为 123456

Trying 127.0.0.1…

Connected to 127.0.0.1.

Escape character is ‘^]’.

set key1 0 0 6

123456

STORED  #存储成功

quit

Connection closed by foreign host.

[root@localhost ~]# telnet 127.0.0.1 11211

# 去获取这个 key1 的值

Trying 127.0.0.1…

Connected to 127.0.0.1.

Escape character is ‘^]’.

get key1

VALUE key1 0 6

123456  #获取成功

END

5,memcache 的使用

6,memcache 性能监控

6.1,安装 python 插件

下载地址见 Linux 公社资源网站(见本文上面的连接)

tar -xvf python-memcached-latest.tar.gz

cd python-memcached-1.43

python setup.py install

运行上面的命令的时候出现如下错误

Traceback (most recent call last):

File “setup.py”, line 3, in ?

from setuptools import setup

ImportError: No module named setuptools

解决办法:yum -y install python-setuptools

安装成功后再次 python setup.py install 安装就可以成功了。

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-10/107522p2.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计10869字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19350
评论数
4
阅读量
7963194
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
手把手教你,购买云服务器并且安装宝塔面板

手把手教你,购买云服务器并且安装宝塔面板

手把手教你,购买云服务器并且安装宝塔面板 前言 大家好,我是星哥。星哥发现很多新手刚接触服务器时,都会被“选购...
星哥带你玩飞牛NAS-16:不再错过公众号更新,飞牛NAS搭建RSS

星哥带你玩飞牛NAS-16:不再错过公众号更新,飞牛NAS搭建RSS

  星哥带你玩飞牛 NAS-16:不再错过公众号更新,飞牛 NAS 搭建 RSS 对于经常关注多个微...
星哥带你玩飞牛NAS-5:飞牛NAS中的Docker功能介绍

星哥带你玩飞牛NAS-5:飞牛NAS中的Docker功能介绍

星哥带你玩飞牛 NAS-5:飞牛 NAS 中的 Docker 功能介绍 大家好,我是星哥,今天给大家带来如何在...
飞牛NAS玩转Frpc并且配置,随时随地直连你的私有云

飞牛NAS玩转Frpc并且配置,随时随地直连你的私有云

飞牛 NAS 玩转 Frpc 并且配置,随时随地直连你的私有云 大家好,我是星哥,最近在玩飞牛 NAS。 在数...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级 大家好,我是星哥,之前写了一篇文章 自己手撸一...
多服务器管理神器 Nexterm 横空出世!NAS/Win/Linux 通吃,SSH/VNC/RDP 一站式搞定

多服务器管理神器 Nexterm 横空出世!NAS/Win/Linux 通吃,SSH/VNC/RDP 一站式搞定

多服务器管理神器 Nexterm 横空出世!NAS/Win/Linux 通吃,SSH/VNC/RDP 一站式搞...
你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你 为什么要用宝塔跑分? 宝塔跑分其实就是对 CPU、内存、磁盘、IO 做...
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...
150元打造低成本NAS小钢炮,捡一块3865U工控板

150元打造低成本NAS小钢炮,捡一块3865U工控板

150 元打造低成本 NAS 小钢炮,捡一块 3865U 工控板 一块二手的熊猫 B3 工控板 3865U,搭...