博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
memcached 学习笔记 5
阅读量:5096 次
发布时间:2019-06-13

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

 memcached installed on linux

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

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

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

2 安装libebent

解压

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

 

编译安装

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

缺少gcc库 安装

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

再次编译安装

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

验证

1 [root@jt libevent-2.0.20-stable]#  ls -al /usr/lib | grep libevent 2 lrwxrwxrwx.  1 root root      21 Sep  8 12:35 libevent-2.0.so.5 -> libevent-2.0.so.5.1.8 3 -rwxr-xr-x.  1 root root  968506 Sep  8 12:35 libevent-2.0.so.5.1.8 4 -rw-r--r--.  1 root root 1571554 Sep  8 12:35 libevent.a 5 lrwxrwxrwx.  1 root root      26 Sep  8 12:35 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.8 6 -rwxr-xr-x.  1 root root  585209 Sep  8 12:35 libevent_core-2.0.so.5.1.8 7 -rw-r--r--.  1 root root  978394 Sep  8 12:35 libevent_core.a 8 -rwxr-xr-x.  1 root root     968 Sep  8 12:35 libevent_core.la 9 lrwxrwxrwx.  1 root root      26 Sep  8 12:35 libevent_core.so -> libevent_core-2.0.so.5.1.810 lrwxrwxrwx.  1 root root      27 Sep  8 12:35 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.811 -rwxr-xr-x.  1 root root  404796 Sep  8 12:35 libevent_extra-2.0.so.5.1.812 -rw-r--r--.  1 root root  593232 Sep  8 12:35 libevent_extra.a13 -rwxr-xr-x.  1 root root     975 Sep  8 12:35 libevent_extra.la14 lrwxrwxrwx.  1 root root      27 Sep  8 12:35 libevent_extra.so -> libevent_extra-2.0.so.5.1.815 -rwxr-xr-x.  1 root root     933 Sep  8 12:35 libevent.la16 lrwxrwxrwx.  1 root root      30 Sep  8 12:35 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.817 -rwxr-xr-x.  1 root root   18478 Sep  8 12:35 libevent_pthreads-2.0.so.5.1.818 -rw-r--r--.  1 root root   18678 Sep  8 12:35 libevent_pthreads.a19 -rwxr-xr-x.  1 root root     996 Sep  8 12:35 libevent_pthreads.la20 lrwxrwxrwx.  1 root root      30 Sep  8 12:35 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.821 lrwxrwxrwx.  1 root root      21 Sep  8 12:35 libevent.so -> libevent-2.0.so.5.1.822 [root@jt libevent-2.0.20-stable]#

安装成功

 

3 安装memcached

解压

1 [root@jt libevent-2.0.20-stable]# cd /usr/local/src2 [root@jt src]# ls3 libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz4 [root@jt src]# tar -zvxf memcached-1.4.10.tar.gz 5 libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10 memcached-1.4.10.tar.gz

 

编译安装

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

验证:

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

 

查看memcached的命令帮助

1 [root@jt memcached-1.4.10]# /usr/local/bin/memcached -h 2 memcached 1.4.10 3 -p 
TCP port number to listen on (default: 11211) 4 -U
UDP port number to listen on (default: 11211, 0 is off) 5 -s
UNIX socket path to listen on (disables network support) 6 -a
access mask for UNIX socket, in octal (default: 0700) 7 -l
interface to listen on (default: INADDR_ANY, all addresses) 8
may be specified as host:port. If you don't specify 9 a port number, the value you specified with -p or -U is10 used. You may specify multiple addresses separated by comma11 or by using -l multiple times12 -d run as a daemon13 -r maximize core file limit14 -u
assume identity of
(only when run as root)15 -m
max memory to use for items in megabytes (default: 64 MB)16 -M return error on memory exhausted (rather than removing items)17 -c
max simultaneous connections (default: 1024)18 -k lock down all paged memory. Note that there is a19 limit on how much memory you may lock. Trying to20 allocate more than that would fail, so be sure you21 set the limit correctly for the user you started22 the daemon with (not for -u
user;23 under sh this is done with 'ulimit -S -l NUM_KB').24 -v verbose (print errors/warnings while in event loop)25 -vv very verbose (also print client commands/reponses)26 -vvv extremely verbose (also print internal state transitions)27 -h print this help and exit28 -i print memcached and libevent license29 -P
save PID in
, only used with -d option30 -f
chunk size growth factor (default: 1.25)31 -n
minimum space allocated for key+value+flags (default: 48)32 -L Try to use large memory pages (if available). Increasing33 the memory page size could reduce the number of TLB misses34 and improve the performance. In order to get large pages35 from the OS, memcached will allocate the total item-cache36 in one large chunk.37 -D
Use
as the delimiter between key prefixes and IDs.38 This is used for per-prefix stats reporting. The default is39 ":" (colon). If this option is specified, stats collection40 is turned on automatically; if not, then it may be turned on41 by sending the "stats detail on" command to the server.42 -t
number of threads to use (default: 4)43 如果有此项,说明已经支持了线程,就可以在启动的时候使用 -t 选项来启动多线程44 -R Maximum number of requests per event, limits the number of45 requests process for a given connection to prevent 46 starvation (default: 20)47 -C Disable use of CAS48 -b Set the backlog queue limit (default: 1024)49 -B Binding protocol - one of ascii, binary, or auto (default)50 -I Override the size of each slab page. Adjusts max item size51 (default: 1mb, min: 1k, max: 128m)52 -o Comma separated list of extended or experimental options53 - (EXPERIMENTAL) maxconns_fast: immediately close new54 connections if over maxconns limit55 - hashpower: An integer multiplier for how large the hash56 table should be. Can be grown at runtime if not big enough.57 Set this based on "STAT hash_power_level" before a 58 restart.59 [root@jt memcached-1.4.10]#

启动memcached服务并查看该进程

1 [root@jt memcached-1.4.10]# /usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root2 [root@jt memcached-1.4.10]# ps aux | grep memcached3  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
这样,也就是属于哪个用户的服务,由哪个用户启动。

 

转载于:https://www.cnblogs.com/wihainan/p/4792695.html

你可能感兴趣的文章
Python pandas 0.19.1 Intro to Data Structures 数据结构介绍 文档翻译
查看>>
《寿康宝鉴》
查看>>
CentOS7下安装jdk8环境
查看>>
Mongodb
查看>>
struts2 DMI
查看>>
管道和I/O重定向
查看>>
django重点url,视图函数,模板语言
查看>>
Base64编码与图片互转
查看>>
bzoj 3997 Dilworth定理
查看>>
web在线页面编辑实现-abtest可视化实验
查看>>
iOS直播技术学习笔记 iOS中实现推流(八)
查看>>
搞懂JavaScript引擎运行原理
查看>>
Java--语法
查看>>
设计模式(一)
查看>>
Java--面向对象
查看>>
线程池(二)
查看>>
Java--异常、反射
查看>>
NIO
查看>>
同步(二) - 锁
查看>>
Linux 简介和常用命令
查看>>