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. Jenkins pipeline中使用内置全局变量

    在pipeline中不像在windows batch command中直接%WORKSPACE%这样 需要写成这样: echo env.WORKSPACE

  2. 去掉easyui tree 的默认图标

    $(".tree-icon,.tree-file").removeClass("tree-icon tree-file"); $(".tree-ico ...

  3. python3.7使用models.ForeignKey时一定要传入实参on_delete=models.CASCADE

    models.ForeignKey 模型中最重要的部分——以及模型中唯一需要的部分——是它定义的数据库字段列表.字段由类属性指定.注意不要选择与模型API冲突的字段名称,如清除.保存或删除. from ...

  4. Oracle数据库exp和imp方式导数据

    这里导入导出路径都在D盘下,默认文件名为:example.dmpexp方式导出数据相关参数项如下: 关键字  说明  默认USERID                     用户名/口令FULL   ...

  5. abstract方法必须在abstract类中 这句话是对的还是错的?

    对 参考文章:https://zhidao.baidu.com/question/435526297.html interface中所有的方法都是抽象的,抽象类中部分方法是抽象的 实现interfac ...

  6. AtcoderExaWizards 2019题解

    传送门 \(A\ Regular\ Triangle\) 咕咕 \(B\ Red\ or\ Blue\) 咕咕咕 \(C\ Snuke\ the\ Wizard\) 我可能脑子真的坏掉了-- 容易发现 ...

  7. PHP中关于foreach的笔试题

    1,php与C++的不同之处是PHP中变量没有局部作用域,只有函数作用域和全局作用域.如下函数,在php中,$name的作用域是函数test():在C++中$name的作用域是for循环体,for循环 ...

  8. 通过Jenkins进行提权的一个思路

    作者:欧根亲王号   所属团队:Arctic Shell Jenkins是一款由Java编写的开源的持续集成工具,其本身具有执行脚本的功能 在Jenkins的说明信息中列出我们可以使用任意Groovy ...

  9. Android 线刷小白教程

    Android 线刷小白教程 再说一遍,绝不使用刷机精灵等软件. 一.概念 安卓系统一般把rom芯片分成7个区,如果再加上内置sd卡这个分区,就是8个: hboot分区----------负责启动. ...

  10. Cause: org.jetbrains.plugins.gradle.tooling.util.ModuleComponentIdentifierIm Lorg/gradle/api/artifacts/ModuleIdentifier;

    今天碰到一个问题, 正常的下载gradle到本地,然后到spring官网上通过他们提供的start.spring.io创建一个demo项目, 然后在idea中打开,并配置下载的gradle到idea中 ...