您的位置:首页 > 数据库 > Memcache

Memcached 安装

2015-10-03 18:47 429 查看
安装Memcached

安装Memcached前要先安装 libevent库
安装环境:
[root@MEM ~]# uname -a
Linux MEM 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@MEM ~]#

安装libevent库
mkdir -p /home/lvnian/tools/
cd /home/lvnian/tools/
rz -y
ls libevent-1.4.13-stable.tar.gz
tar xf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure
make && make install

注意,也可以yum安装libevent库
yum install libevent* -y
#######################################################

安装Memcached

cd /home/lvnian/tools/
rz -y
tar xf Memcached-1.4.13.tar.gz
cd Memcached-1.4.13
./configure
make && make install

#安装完毕
其中Memcacheds是服务端
memcache 是客户端
#######################################################

启动Memcached服务
1、配置ld.so.conf路径防止启动Memcached时报错
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig

如果是centos 5.8 可以不做

2.启动Memcached
which Memcached
/usr/local/bin/memcached -h
/usr/local/bin/memcached -p

/usr/local/bin/memcached -p 11211 -u root -m 32m -c 10240 -d
netstat -lnt |grep 11211
lsof -i :11211

/usr/local/bin/memcached -p 11233 -u root -m 32m -c 10240 -d
netstat -lnt |grep 11233
lsof -i :11233
##可以同时启动多个Memcached进程

===========================
-p 指定TCP的端口号,默认是11211
-U 指定TCP的端口号,默认是11211
-d 以守护进程方式启动
-m Memcached以多大内存方式启动,默认是64M
-u 指定运行Memcached的用户
-c 指定最大的并发连接数,默认是1024
-vv 以very werbose模式启动,也就是把调试信息和错误输出到控制台
-P 设置保存Memcached的pid文件
-l 指定监听的服务器IP地址

#######################
查看Memcached路径
[root@MEM ~]# which memcached
/usr/local/bin/memcached
[root@MEM ~]#
[root@MEM ~]# /usr/local/bin/memcached -h
Memcached 1.4.13
-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)
-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@MEM ~]#
[root@MEM ~]# /usr/local/bin/memcached -p 11211 -u root -m 32m -c 10240 -d
[root@MEM ~]# netstat -lnt |grep 11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN
tcp 0 0 :::11211 :::* LISTEN
[root@MEM ~]# lsof -i :11211
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Memcached 10915 root 26u IPv4 20462 0t0 TCP *:memcache (LISTEN)
Memcached 10915 root 27u IPv6 20463 0t0 TCP *:memcache (LISTEN)
Memcached 10915 root 28u IPv4 20466 0t0 UDP *:memcache
Memcached 10915 root 29u IPv6 20467 0t0 UDP *:memcache
[root@MEM ~]#
[root@MEM ~]# /usr/local/bin/memcached -p 11233 -u root -m 32m -c 10240 -d
[root@MEM ~]# netstat -lnt |grep 11233
tcp 0 0 0.0.0.0:11233 0.0.0.0:* LISTEN
tcp 0 0 :::11233 :::* LISTEN
[root@MEM ~]# lsof -i :11233
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Memcached 10938 root 26u IPv4 21056 0t0 TCP *:11233 (LISTEN)
Memcached 10938 root 27u IPv6 21057 0t0 TCP *:11233 (LISTEN)
Memcached 10938 root 28u IPv4 21060 0t0 UDP *:11233
Memcached 10938 root 29u IPv6 21061 0t0 UDP *:11233
[root@MEM ~]#
-p 指定TCP的端口号,默认是11211
-U 指定TCP的端口号,默认是11211
-d 以守护进程方式启动
-m Memcached以多大内存方式启动,默认是64M
-u 指定运行Memcached的用户
-c 指定最大的并发连接数,默认是1024
-vv 以very werbose模式启动,也就是把调试信息和错误输出到控制台
-P 设置保存Memcached的pid文件
-l 指定监听的服务器IP地址

#######################################################

把Memcached服务设置开机自启动

echo "#######Memcached starting" >> /etc/rc.local
echo "/usr/local/bin/memcached -p 11233 -u root -m 32m -c 10240 -d" >> /etc/rc.local

本文出自 “奋斗吧” 博客,请务必保留此出处http://lvnian.blog.51cto.com/7155281/1700044
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: