CentOS安装Memcached
CentOS安装Memcached
安装&配置
wget http://memcached.org/latest -O memcached.tar.gz
tar -zxvf memcached.tar.gz
cd memcached
./configure --prefix=/usr/local/memcached
make && sudo make install
ln -sf /usr/local/memcached/bin/memcached /usr/bin/memcached
如果不存在`/var/lock/subsys`,则创建`mkdir -p /var/lock/subsys`
配置系统服务
添加文件:vim /etc/init.d/memcached
#! /bin/bash
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
### BEGIN INIT INFO
# Provides: memcached
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: memcached - Memory caching daemon
# Description: memcached - Memory caching daemon
### END INIT INFO
#如果IP为127.0.0.1则限制仅本机可访问
#如果IP为本机的内网IP,则只能内网能访问
#IP为应用程序访问Memcached使用的IP,一般为127.0.0.1或本机内网IP或本机外网IP
IP=127.0.0.1
PORT=11211
USER=root
MAXCONN=1024
CACHESIZE=64
OPTIONS=""
RETVAL=0
prog="memcached"
start () {
echo -n $"Starting $prog: "
/usr/local/memcached/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached.pid $OPTIONS
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
touch /var/lock/subsys/memcached
echo " done"
fi
}
stop () {
echo -n $"Stopping $prog: "
if [ ! -e /var/run/$prog.pid ]; then
echo -n $"$prog is not running."
exit 1
fi
kill `cat /var/run/memcached.pid`
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
rm -f /var/lock/subsys/memcached
rm -f /var/run/memcached.pid
echo " done"
fi
}
restart () {
$0 stop
sleep 2
$0 start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload}"
exit 1
;;
esac
exit $?
赋予可执行权限:chmod +x /etc/init.d/memcached
防火墙设置
#设置规则
vim /etc/sysconfig/iptables
#如果限定某些机器能访问可如下设置:
-A INPUT -s 127.0.0.1,10.170.238.137,123.7.213.222/32 -p udp -m udp --dport 11211 -j ACCEPT
-A INPUT -s 127.0.0.1,10.170.238.137,123.7.213.222/32 -p tcp -m tcp --dport 11211 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 11211 -j DROP
-A INPUT -p udp -m udp --dport 11211 -j DROP
#重启iptables使得规则生效
service iptables restart
启动
/etc/init.d/memcached start
Memcached 的详细介绍:请点这里
Memcached 的下载地址:请点这里