手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2014-10-02] 来源:Linux社区  作者:黄杉 [字体:大 中 小]

简介

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

linux
相关资讯       memcache  Cacti监控 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法��
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款