共计 2650 个字符,预计需要花费 7 分钟才能阅读完成。
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
CentOS 6.6 下 Memcached 源码安装配置 http://www.linuxidc.com/Linux/2015-09/123019.htm
Memcached 安装及启动脚本 http://www.linuxidc.com/Linux/2013-07/87641.htm
PHP 中使用 Memcached 的性能问题 http://www.linuxidc.com/Linux/2013-06/85883.htm
Ubuntu 下安装 Memcached 及命令解释 http://www.linuxidc.com/Linux/2013-06/85832.htm
Memcached 的安装和应用 http://www.linuxidc.com/Linux/2013-08/89165.htm
使用 Nginx+Memcached 的小图片存储方案 http://www.linuxidc.com/Linux/2013-11/92390.htm
Memcached 使用入门 http://www.linuxidc.com/Linux/2011-12/49516p2.htm
Memcached 的详细介绍 :请点这里
Memcached 的下载地址 :请点这里
更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-09/123565.htm