1. 程式人生 > >memcache安裝配置

memcache安裝配置

系統 memcached

一、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

memcache安裝配置