Centos安装Memcached


        Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据.简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。 
安装Memcached步骤: 
因为Memcache用到了libevent这个库用于Socket的处理,所以首先需要安装libevent
1.编译安装Libevent 
wget https://github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz
tar -zxvf libevent-2.0.19-stable.tar.gz
cd libevent-2.0.19-stable
./configure --prefix=/usr/local/libevent/
make
make install
ln -s /usr/local/libevent/lib/libevent-2.0.so.5  /lib64/libevent-2.0.so.5


2.安装Memcache 
cd ~
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
tar -zxvf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
make
make install


3、配置memcached
①下载启动脚本
wget http://www.centos.bz/wp-content/uploads/2011/11/memcached -O /etc/init.d/memcached
②创建文件/usr/local/memcached/memcached.conf,并写入以下代码
PORT="11211"
USER="memcached"
MAXCONN="2048"
CACHESIZE="64"
OPTIONS=""
PORT="11211":指定端口为11211
USER="memcached":以memcached用户运行
MAXCONN="2048":最大连接数
CACHESIZE="64":设置缓存内存为64M
③建立用户memcached,加入启动项,并启动memcached
groupadd memcached
useradd -g memcached memcached
chkconfig --add memcached
chkconfig memcached on
service memcached start


ps:/etc/init.d/memcached

#!/bin/bash
# Init file for memcached

# chkconfig: - 80 12
# description: Distributed memory caching daemon
#
# processname: memcached
## config: /etc/sysconfig/memcached
## config: /etc/memcached.conf
# config: /usr/local/memcached/memcached.conf
# pidfile: /var/run/memcached.pid


source /etc/init.d/functions


### Default variables
PORT="11211"
USER="memcached"
MAXCONN="2048"
CACHESIZE="64"
OPTIONS=""


#BIN="/usr/local/bin"
BIN="/usr/local/memcached/bin"
SYSCONFIG="/usr/local/memcached/memcached.conf"


### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"


RETVAL=0
prog="memcached"
desc="Distributed memory caching"


start() {
echo -n $"Starting $desc ($prog) on port $PORT: "
daemon $BIN/$prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}


stop() {
echo -n $"Shutting down $desc ($prog): "
kill `ps -aef | grep $PORT | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}


restart() {
stop
start
}


reload() {
echo -n $"Reloading $desc ($prog): "
killproc $prog -HUP
RETVAL=$?
echo
return $RETVAL
}


case "$1" in
start)
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
reload)
reload
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac


exit $RETVAL 










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值