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. 自我介绍+github注册

    我是网络工程141的蒋易,学号是1413042018 个人兴趣:打篮球,打羽毛球,打游戏 github注册流程 id:Scorpio1 注册困难:1.刚开始网页没打开. 2.全英文的界面无法看懂,要查 ...

  2. js练习计算器

    js练习计算器,支持鼠标点击.键盘操作 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  3. windows本地代码上传github

    1.下载Git工具 https://www.git-scm.com/download/win 2.进到项目目录 cd /dir/dir/dir/file 3.初始化 git init 4.添加远程仓库 ...

  4. .Net WebApi部署问题

    在IIS上部署web api 完成后,浏览时出现了“The compiler failed with error code -2146232576.”的错误(有时会出现这个情况).主要是 我们在.Ne ...

  5. iOS 内嵌 View 的响应

    遇到一个问题就是我有一个 UITextField,点击后不能编辑而是会显示一个自定义的 dialog. 但发现问题是,UITextField 的对点击事件的反应非常吃顿,有时候好使有时候不好使. 后来 ...

  6. Mounting VMDK files in Linux

    1.用 loop 方式挂载 vmdk 文件 losetup /dev/loop0 docker_pull-flat.vmdk 2.查看分区 [root@localhost]# parted /dev/ ...

  7. LOJ#6038. 「雅礼集训 2017 Day5」远行(LCT)

    题面 传送门 题解 要不是因为数组版的\(LCT\)跑得实在太慢我至于去学指针版的么--而且指针版的完全看不懂啊-- 首先有两个结论 1.与一个点距离最大的点为任意一条直径的两个端点之一 2.两棵树之 ...

  8. Word2007文档中怎么输入上标下标

    1.Word中输出Z = X2 + Y2 此公式流程: 首先在Word中写入:Z = X2 + Y2: 方法1:选中X后面的2,再按组合键“Ctrl+Shift+加号键”即可,如此操作Y后面的2即可.

  9. jdk1.6 支持 tls1.2协议 并忽略身份验证

    jdk1.6不支持tls1.2协议,jdk1.8默认支持,比较好的解决方案是升级jdk,但是升级jdk风险极大.不能升级jdk的情况下,可以使用如下方式. 引入依赖 <dependency> ...

  10. SpringAOP的应用实例与总结

    一:AOP的背景 面试的时候面试官让我解释一下什么是AOP,当时不懂,在路上就查了,AOP:面向切面的编程技术,困惑了,JAVA是OOP:面向对象的编程技术.那么自己就立刻查了几个为题:1.什么是面向 ...