首页 > 系统 > CentOS > 正文

CentOS安装Memcached

2024-06-28 14:32:01
字体:
来源:转载
供稿:网友

安装&配置

wget http://memcached.org/latest -O memcached.tar.gztar -zxvf memcached.tar.gzcd memcached./configure --PRefix=/usr/local/memcachedmake && sudo make installln -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或本机外网IPIP=127.0.0.1PORT=11211USER=rootMAXCONN=1024CACHESIZE=64OPTIONS=""RETVAL=0prog="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        ;;esacexit $?

赋予可执行权限: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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表