memcached installed on linux

使用的操作系统是centos6.5 (有桌面)

1 上传libebent和memcache到/usr/local/src

 [root@jt ~]# cd /usr/local/src
[root@jt src]# ls
libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz

2 安装libebent

解压

 [root@jt src]# tar -zvxf libevent-2.0.20-stable.tar.gz
libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz
[root@jt src]# cd libevent-2.0.20-stable
[root@jt libevent-2.0.20-stable]#

编译安装

 [root@jt libevent-2.0.20-stable]# ./configure --prefix=/usr
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/libevent-2.0.20-stable':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

缺少gcc库 安装

 [root@jt libevent-2.0.20-stable]#  yum -y install gcc
[root@jt libevent-2.0.20-stable]# yum -y install gcc-c++

再次编译安装

 [root@jt libevent-2.0.20-stable]# ./configure --prefix=/usr
[root@jt libevent-2.0.20-stable]# make
[root@jt libevent-2.0.20-stable]# make install

验证

 [root@jt libevent-2.0.20-stable]#  ls -al /usr/lib | grep libevent
lrwxrwxrwx. 1 root root 21 Sep 8 12:35 libevent-2.0.so.5 -> libevent-2.0.so.5.1.8
-rwxr-xr-x. 1 root root 968506 Sep 8 12:35 libevent-2.0.so.5.1.8
-rw-r--r--. 1 root root 1571554 Sep 8 12:35 libevent.a
lrwxrwxrwx. 1 root root 26 Sep 8 12:35 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.8
-rwxr-xr-x. 1 root root 585209 Sep 8 12:35 libevent_core-2.0.so.5.1.8
-rw-r--r--. 1 root root 978394 Sep 8 12:35 libevent_core.a
-rwxr-xr-x. 1 root root 968 Sep 8 12:35 libevent_core.la
lrwxrwxrwx. 1 root root 26 Sep 8 12:35 libevent_core.so -> libevent_core-2.0.so.5.1.8
lrwxrwxrwx. 1 root root 27 Sep 8 12:35 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.8
-rwxr-xr-x. 1 root root 404796 Sep 8 12:35 libevent_extra-2.0.so.5.1.8
-rw-r--r--. 1 root root 593232 Sep 8 12:35 libevent_extra.a
-rwxr-xr-x. 1 root root 975 Sep 8 12:35 libevent_extra.la
lrwxrwxrwx. 1 root root 27 Sep 8 12:35 libevent_extra.so -> libevent_extra-2.0.so.5.1.8
-rwxr-xr-x. 1 root root 933 Sep 8 12:35 libevent.la
lrwxrwxrwx. 1 root root 30 Sep 8 12:35 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.8
-rwxr-xr-x. 1 root root 18478 Sep 8 12:35 libevent_pthreads-2.0.so.5.1.8
-rw-r--r--. 1 root root 18678 Sep 8 12:35 libevent_pthreads.a
-rwxr-xr-x. 1 root root 996 Sep 8 12:35 libevent_pthreads.la
lrwxrwxrwx. 1 root root 30 Sep 8 12:35 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.8
lrwxrwxrwx. 1 root root 21 Sep 8 12:35 libevent.so -> libevent-2.0.so.5.1.8
[root@jt libevent-2.0.20-stable]#

安装成功

3 安装memcached

解压

 [root@jt libevent-2.0.20-stable]# cd /usr/local/src
[root@jt src]# ls
libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz
[root@jt src]# tar -zvxf memcached-1.4.10.tar.gz
libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10 memcached-1.4.10.tar.gz

编译安装

 [root@jt src]# cd memcached-1.4.10
[root@jt memcached-1.4.10]# ./configure --with-libevent=/usr --enable-threads
[root@jt memcached-1.4.10]# make
[root@jt memcached-1.4.10]# make install

验证:

 [root@jt memcached-1.4.10]# ls -al /usr/local/bin/mem*
-rwxr-xr-x. 1 root root 287883 Sep 8 12:38 /usr/local/bin/memcached

查看memcached的命令帮助

 [root@jt memcached-1.4.10]# /usr/local/bin/memcached -h
memcached 1.4.10
-p <num> TCP port number to listen on (default: 11211)
-U <num> UDP port number to listen on (default: 11211, 0 is off)
-s <file> UNIX socket path to listen on (disables network support)
-a <mask> access mask for UNIX socket, in octal (default: 0700)
-l <addr> interface to listen on (default: INADDR_ANY, all addresses)
<addr> may be specified as host:port. If you don't specify
a port number, the value you specified with -p or -U is
used. You may specify multiple addresses separated by comma
or by using -l multiple times
-d run as a daemon
-r maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num> max memory to use for items in megabytes (default: 64 MB)
-M return error on memory exhausted (rather than removing items)
-c <num> max simultaneous connections (default: 1024)
-k lock down all paged memory. Note that there is a
limit on how much memory you may lock. Trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u <username> user;
under sh this is done with 'ulimit -S -l NUM_KB').
-v verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/reponses)
-vvv extremely verbose (also print internal state transitions)
-h print this help and exit
-i print memcached and libevent license
-P <file> save PID in <file>, only used with -d option
-f <factor> chunk size growth factor (default: 1.25)
-n <bytes> minimum space allocated for key+value+flags (default: 48)
-L Try to use large memory pages (if available). Increasing
the memory page size could reduce the number of TLB misses
and improve the performance. In order to get large pages
from the OS, memcached will allocate the total item-cache
in one large chunk.
-D <char> Use <char> as the delimiter between key prefixes and IDs.
This is used for per-prefix stats reporting. The default is
":" (colon). If this option is specified, stats collection
is turned on automatically; if not, then it may be turned on
by sending the "stats detail on" command to the server.
-t <num> number of threads to use (default: 4)
如果有此项,说明已经支持了线程,就可以在启动的时候使用 -t 选项来启动多线程
-R Maximum number of requests per event, limits the number of
requests process for a given connection to prevent
starvation (default: 20)
-C Disable use of CAS
-b Set the backlog queue limit (default: 1024)
-B Binding protocol - one of ascii, binary, or auto (default)
-I Override the size of each slab page. Adjusts max item size
(default: 1mb, min: 1k, max: 128m)
-o Comma separated list of extended or experimental options
- (EXPERIMENTAL) maxconns_fast: immediately close new
connections if over maxconns limit
- hashpower: An integer multiplier for how large the hash
table should be. Can be grown at runtime if not big enough.
Set this based on "STAT hash_power_level" before a
restart.
[root@jt memcached-1.4.10]#

启动memcached服务并查看该进程

 [root@jt memcached-1.4.10]# /usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root
[root@jt memcached-1.4.10]# ps aux | grep memcached
root 9186 0.0 0.1 326888 1060 ? Ssl 12:44 0:00 /usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root

ok 安装成功

停止Memcache进程:kill `cat /tmp/memcached.pid`
# kill `cat /tmp/memcached.pid`

启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid
-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,
也可以启动多个守护进程,不过端口不能重复。

./usr/local/memcached/bin/memcached -d -m 256 -u root -p 11211 -c 1024 –P /tmp/memcached.pid

启动参数说明:
-d 选项是启动一个守护进程。
-u root 表示启动memcached的用户为root。
-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB。
-M return error on memory exhausted (rather than removing items)。
-u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口。
-c 选项是最大运行的并发连接数,默认是1024。
-P 是设置保存Memcache的pid文件。

常见问题:

1.如果启动Memcached服务的时候遇到了

/usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory;

解决方案:

[root@localhost bin]# LD_DEBUG=libs memcached -v
[root@localhost bin]# ln -s /usr/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1
[root@localhost bin]# /usr/local/bin/memcached -d -m 100 -u root -p 12000 -c 1000 -P /tmp/memcached.pid
[root@localhost bin]# ps -aux
可以看到启动的Memcached服务了.

2.把Memcached服务加载到Linux的启动项中.万一机器断电系统重启.那么Memcached就会自动启动了.

假如启动Memcache的服务器端的命令为:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid容来自17jquery

想开机自动启动的话,只需在/etc/rc.d/rc.local中加入一行,下面命令
/usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u apache -c 256
上面有些东西可以参考一下:即,ip不指定时,默认是本机,用户:最好选择是:apache 或 deamon
这样,也就是属于哪个用户的服务,由哪个用户启动。

memcached 学习笔记 5的更多相关文章

  1. memcached学习笔记——存储命令源码分析下篇

    上一篇回顾:<memcached学习笔记——存储命令源码分析上篇>通过分析memcached的存储命令源码的过程,了解了memcached如何解析文本命令和mencached的内存管理机制 ...

  2. memcached学习笔记——存储命令源码分析上篇

    原创文章,转载请标明,谢谢. 上一篇分析过memcached的连接模型,了解memcached是如何高效处理客户端连接,这一篇分析memcached源码中的process_update_command ...

  3. Memcached 学习笔记(二)——ruby调用

    Memcached 学习笔记(二)——ruby调用 上一节我们讲述了怎样安装memcached及memcached常用命令.这一节我们将通过ruby来调用memcached相关操作. 第一步,安装ru ...

  4. Memcached学习笔记

    [TOC] 前言 此为学习笔记汇总,如有纰漏之处,还望不吝指出,谢谢. 启动流程 调用settings_init()设定初始化参数 从启动命令中读取参数来设置setting值 设定LIMIT参数 开始 ...

  5. memcached学习笔记2--安装及命令

    学习memcached的原理: 用户一 -> 访问浏览器 -> 服务器Apache -> PHP文件(该文件应用了memcached技术) -> [第一次]到数据库DB中查找数 ...

  6. memcached学习笔记6--浅谈memcached的机制 以及 memcached细节讨论

    附:请浅谈memcached的机制 答: ①基于C/S架构,协议比较简单 c/s架构,此时memcached为服务器端,我们可以使用如PHP,c++/c等程序连接memcached服务器. memca ...

  7. memcached学习笔记5--socke操作memcached 缓存系统

    使用条件:当我们没有权限或者不能使用服务器的时候,我们需要用socket操作memcached memcached-client操作 特点: 无需开启memcache扩展 使用fsocketopen( ...

  8. memcached学习笔记4--memcache扩展操作memcached

    1. 安装并配置memcache扩展库 找到php.ini文件 添加: extendsion= php_memcache.dll 并把对应的dll文件拷贝到ext目录 2. 使用PHP对Memcahc ...

  9. memcached学习笔记3--telnet操作memcached

    方式: 一.telnet访问memcached缓存系统(主要用于教学,不讨论) telnet 127.0.0.1 11211     => telnet IP地址 端口号 //往Memcache ...

  10. memcached学习笔记1--概念

    1.memcached是danga的一个项目,最早是LiveJournal服务的,最初为了加速LiveJournal访问速度而开发,后来被很多大型网站采用 官网: http://www.danga.c ...

随机推荐

  1. [转]解决Mysql InnoDB: Failing assertion: ret || !assert_on_error问题

    国庆回来后,发现mysql停止服务了,没办法继续启动了.查看日志,看到: 131008 09:56:03 mysqld_safe Starting mysqld daemon with databas ...

  2. [c# 20问] 2.如何转换XML文件

    添加System.Xml引用 使用XmlReader转换字符串 DEMO #region Parse Xml private static void ParseXml(string xmlString ...

  3. TSQL--自增键和索引对表的插入效率测试

    问题描述:数据库操作中,需要对表频繁插入数据,但发现插入效率不高. 解决思路:将数据缓存在服务器上,积攒到一定条数后批处理发送到数据库,在插入时考虑并发和索引对插入效率的影响. 测试结果:      ...

  4. ffmpeg学习(一)——在window7下编译ffmpeg

    FFmpeg是一个开源免费跨平台的视频和音频流项目,它提供了录制.转换以及流化音视频的完整解决方案.本文作者将尝试使用该库实现一个可适应复杂网络环境的, 支持标准rtsp协议的流媒体服务器.由于Vis ...

  5. 使用 pdf.js 查看发票时,显示不了台头和印章的解决办法

    系统中使用了 pdf.js 来查看 PDF 文件,发现在查看 电子发票时, 缺失了很多信息, 刚开始以为是 PDF.JS 的 BUG, 后来调试发现只需要在 IIS 里添加一个 bcmap 后缀的 m ...

  6. c#中sealed修饰符

    sealed 修饰符表示密封 用法: 1.用于类时,表示该类不能再被继承,不能和abstract同时使用,因为这两个修饰符在含义上互相排斥 2.用于方法和属性时,表示该方法或属性不能再被重写,必须和o ...

  7. python--深浅拷贝 join() 列表和字典的删除 fromkeys建立字典

    北京的冬天雾霾依旧很重,依稀记得人生初见雾霾时的样子,那时的回忆也是有些尴尬,不过雾霾也伴随了我的成长,成为了我肺泡中不可分割的一部分. 今天我想写的是拷贝的问题,不过在这之前我想先补充一点关于字符串 ...

  8. MyBatis入门程序(基于XML配置)

    创建一个简单的MyBatis入门程序,实现对学生信息的增删改查功能(基于XML配置) 一.新建一个Java工程,导入MyBatis核心jar包.日志相关的jar包以及连接Oracle数据库所需驱动包, ...

  9. 1087 1 10 100 1000(打表 set 数学)

    1087 1 10 100 1000 题目来源: Ural 1209 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 1,10,100,1000... ...

  10. Java多线程编程 — 锁优化

      阅读目录 一.尽量不要锁住方法 二.缩小同步代码块,只锁数据 三.锁中尽量不要再包含锁 四.将锁私有化,在内部管理锁 五.进行适当的锁分解 正文 并发环境下进行编程时,需要使用锁机制来同步多线程间 ...