一、memcache说明
memcached是一套开源分布式的高速缓存系统,memcached缺乏认证以及安全管制,这代表应该将memcached服务器放置在防火墙之后,以确保安全。
系统环境:CentOS6.8_x64
二、安装
1、安装gcc
yum install -y wget gcc
2、下载安装源码libevent
#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
#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
#!/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、添加到开机自启服务并启动服务
#chmod +x /etc/init.d/memcached #chkconfig --add memcached #chkconfig memcached on #service memcached start
本文出自 “學地止境” 博客,请务必保留此出处http://dyc2005.blog.51cto.com/270872/1942431
原文地址:http://dyc2005.blog.51cto.com/270872/1942431