一、memcache说明
memcached是一套开源分布式的高速缓存系统,memcached缺乏认证以及安全管制,这代表应该将memcached服务器放置在防火墙之后,以确保安全。
系统环境:CentOS6.8_x64
二、安装
1、安装gcc
yum install -y wget gcc
2、下载安装源码libevent
1
2
3
4
5
|
#wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz #如找不到请下最新版本
#tar zxvf libevent-2.0.21-stable.tar.gz
#cd libevent-2.0.21-stable
#./configure --prefix=/usr/local/libevent
#make && make install
|
3、下载源码memcached
1
2
3
4
5
6
|
#wget http://www.memcached.org/files/memcached-1.4.24.tar.gz #如找不到请下载最新版本
#tar zxvf memcached-1.4.24.tar.gz
#cd memcached-1.4.24
#./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
#make && make install
#ln -s /usr/local/memcached/bin/memcached /usr/local/bin/
|
三、编写服务脚本
1、脚本内容如下:
cat /etc/init.d/memcached
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
# Source function library.
# Author: pkey san 2015/12/07
.
/etc/rc
.d
/init
.d
/functions
.
/etc/sysconfig/network
prog=memcached
pidfile=${PIDFILE-
/var/run/memcached
.pid}
start()
{
echo
-n $
"Starting memcached: "
daemon --pidfile=${pidfile}
/usr/local/bin/memcached
-u daemon -d -m 512 -l 10.1.0.6 -c 4096 -p 11211
echo
`
ps
aux |
grep
memcached |
grep
11211 |
grep
-
v
grep
|
awk
'{print $2}'
` >$pidfile
echo
}
stop()
{
echo
-n $
"Shutting down memcached: "
killproc $prog
echo
}
rh_status(){
status -p ${pidfile} $prog
}
[ -f
/usr/local/bin/memcached
] ||
exit
0
# See how we were called.
case
"$1"
in
start)
start
;;
stop)
stop
;;
status)
rh_status
;;
restart|reload)
stop
start
;;
*)
echo
$
"Usage: $0 {start|stop|status|restart|reload|}"
exit
1
esac
exit
0
|
2、说明:
daemon --pidfile=${pidfile} /usr/local/bin/memcached -u daemon -d -m 512 -l 10.1.0.6 -c 4096 -p 11211
-m:指定memcache缓存内存大小
-l:指定memcache的侦听地址一般内网
-c: 最大并发连接数。
-p:侦听端口
3、添加到开机自启服务并启动服务
1
2
3
4
|
#chmod +x /etc/init.d/memcached
#chkconfig --add memcached
#chkconfig memcached on
#service memcached start
|
本文转自 dyc2005 51CTO博客,原文链接:http://blog.51cto.com/dyc2005/1942431,如需转载请自行联系原作者