博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux memcached 安装
阅读量:7228 次
发布时间:2019-06-29

本文共 4247 字,大约阅读时间需要 14 分钟。

  hot3.png

1.下载包

1.1.到http://memcached.org/下载linux下的memcached的安装包.

1.2.到http://libevent.org/ 下载安装memcached前比需要的包libevent-2.0.22我安装的是这个版本.

2.安装libevent-2.0.22

[root@hnxz-vm-dg-s1 ~]# tar -zxvf libevent-2.0.22-stable.tar.gz[root@hnxz-vm-dg-s1 ~]# cd libevent-2.0.22-stable[root@hnxz-vm-dg-s1 libevent-2.0.22-stable]# pwd/root/libevent-2.0.22-stable[root@hnxz-vm-dg-s1 libevent-2.0.22-stable]# ./configure --prefix=/usr/local/libevent[root@hnxz-vm-dg-s1 libevent-2.0.22-stable]# make && make install

3.安装memcached

[root@hnxz-vm-dg-s1 ~]# tar -zxvf memcached-1.4.25.tar.gz[root@hnxz-vm-dg-s1 ~]# cd memcached-1.4.25[root@hnxz-vm-dg-s1 memcached-1.4.25]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent --enable-64bit[root@hnxz-vm-dg-s1 memcached-1.4.25]# make && make install

--with-libevent=??? 此路径可以使用命令查找lib位置

whereis libevent

4.测试是否成功安装memcached:

[root@hnxz-vm-dg-s1 memcached-1.4.25]# ls -al /usr/local/memcached/bin/total 360drwxr-xr-x 2 root root   4096 Jan 13 17:24 .drwxr-xr-x 5 root root   4096 Jan 13 17:24 ..-rwxr-xr-x 1 root root 360434 Jan 13 17:24 memcached[root@hnxz-vm-dg-s1 memcached-1.4.25]#

成功的话,会输出memcached 可执行程序

5.启动memcached

[root@hnxz-vm-dg-s1 bin]# lltotal 352-rwxr-xr-x 1 root root 360434 Jan 13 17:24 memcached[root@hnxz-vm-dg-s1 bin]# ./memcached -d -m 246 -l 10.207.238.61 -p 11211 -u root

如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。

我在启动过程中报这个错误找不到lib包,错误如下:

memcached: error while loading shared libraries: libevent-2.0.so.5: cannot 

使用命令,即可查看缺失的lib包位置以及错误的详细信息;

LD_DEBUG=libs ./memcached -v 2>&1 > /dev/null | less
[root@hnxz-vm-dg-s1 bin]# lltotal 352-rwxr-xr-x 1 root root 360434 Jan 13 17:24 memcached[root@hnxz-vm-dg-s1 bin]# LD_DEBUG=libs ./memcached -v 2>&1 > /dev/null | less[root@hnxz-vm-dg-s1 bin]#

最终确认为找不到libevent-2.0.so.5 使用ln -s软连接一个

ln -s /usr/local/lib/libevent.so /usr/lib64/libevent-2.0.so.5

6.给出memcached启动命令参数详解.

-d选项是启动一个守护进程,-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,-u是运行Memcache的用户,我这里是root,-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,-p 使用的TCP端口。默认为11211-m 最大内存大小。默认为64M-vv 用very vrebose模式启动,调试信息和错误输出到控制台-d 作为daemon在后台启动

如果要结束Memcache进程,执行:

# kill `cat /tmp/memcached.pid`

或是 通过ps -ef | grep memcached 找到pid ,然后kill

也可以启动多个守护进程,不过端口不能重复。

# ps -ef | grep memcached

root 28914 1 0 07:27 ? 00:00:00 memcached -d -m 128 -l localhost -p 11211 -u root (启动ok)

6.测试memcached

#telnet localhost 11211

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

对memecached的管理可以参考这篇文章

常用指令:

stats

memcached的作者给我们提供查看运行情况的命令。主要是“stats”,使用方法为 “telnet ip 端口号”,登录后使用“stats”命令。

以下是引用片段:

pid = process iduptime = number of seconds since the process was startedtime = current timeversion = memcached versionrusage_user = seconds the cpu has devoted to the process as the userrusage_system = seconds the cpu has devoted to the process as the systemcurr_items = total number of items currently in memcachetotal_items = total number of items that have passed through the cachebytes = total number of bytes currently in use by curr_itemscurr_connections = total number of open connections to memcachedconnection_structures = ???cmd_get = total GET commands issued to the servercmd_set = total SET commands issued to the serverget_hits = total number of times a GET command was able to retrieve andreturn dataget_misses = total number of times a GET command was unable to retrieve andreturn databytes_read = total number of bytes input into the serverbytes_written = total number of bytes written by the serverlimit_maxbytes = total storage bytes available to the server.
着重说一下几个对观测很有用的项。    limit_maxbytes、bytes    memcached在存储的时候是可以设置失效时间的,但如果存储已经满了,那旧数据即使没有到过期时间,也会被移除。所以需要观察memcached存储是否已经满了,同时这对扩容也是有意义的参考。limit_maxbytes即总的存储大小,而bytes    就是已经使用的大小,从这两个数据就可以看出在memcached启动时,我们为它分配的内存是否足够使用。    cmd_get、cmd_set    memcached启动后,我们对它一共做了多少次读取操作呢?从这两个参数可以观察出来。    get_hits、get_misses    使用memcached后,我们需要评估我们使用的策略是否合理。不能够使用中间缓存后,后端的数据库还是有较大的访问量,这样的话中间缓存就变得没有意义了。get_hits表示命中了多少次读取,即来memcached取到了多少有效数据;get_m    isses表示没有命中的次数,即此次来取数据的时候,memcached并没有你所查询的数据。如果没有清零统计数据的话,cmd_get = get_hits + get_misses。

转载于:https://my.oschina.net/ambari/blog/602005

你可能感兴趣的文章
Protostuff 介绍
查看>>
一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别...
查看>>
参数验证其实可以更简明一点
查看>>
Set up Mule runtime env with mule-standalone-3.6.0
查看>>
Linux基础-linux命令:csplit
查看>>
core_framework —— 基于libev的轻量级lua网络开发框架
查看>>
回到顶部
查看>>
DES/3DES(TripleDES)加密、解密测试数据
查看>>
Maven项目标准目录结构
查看>>
Tomcat 系统架构与设计模式,第 1 部分: 工作原理
查看>>
Hadoop输出参数信息详解(16)
查看>>
ERROR 2002 (HY000): Can't connect to local MySQL错误
查看>>
Java版冒泡排序法
查看>>
关于FB4.6插件安装后默认语言环境的更改问题
查看>>
免费分区助手
查看>>
Javascript通过Name调用Function
查看>>
统计当前在线用户数量
查看>>
IntelliJ IDEA 乱码解决方案 (项目代码、控制台等)
查看>>
PHP项目记录
查看>>
.net面试题系列文章七(附答案)
查看>>