热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

memcached安装+绑定访问ip

安装:1.由于memcached是基于libevent的,需要安装libevent,libevent-devel$yum-yinstalllibeventlibevent-deve

安装:

1.由于memcached是基于libevent的,需要安装libevent,libevent-devel
$yum -y install libevent libevent-devel

2.下载解压emcached
$ wget http://memcached.org/latest
$ tar -zxvf memcached-1.4.32.tar.gz

3.编译安装
$ cd memcached-1.4.34
$ ./configure
$ make
$ make test
$ make install

4.编写memcached服务启停脚本
$ vim /etc/init.d/memcached

-#! /bin/sh
-#
-# chkconfig: – 55 45
-# description: The memcached daemon is a network memory cache service.
-# processname: memcached
-# config: /etc/sysconfig/memcached
-# pidfile: /var/run/memcached/memcached.pid

-# Standard LSB functions
-#. /lib/lsb/init-functions

-# Source function library.
-. /etc/init.d/functions

-PORT=11211
-USER=memcached
-MAXCOnN=1024
-CACHESIZE=64
-OPTIOnS=””
-IP=127.0.0.1

-if [ -f /etc/sysconfig/memcached ];then

  • . /etc/sysconfig/memcached
    -fi

-# Check that networking is up.
-. /etc/sysconfig/network

-if [ “$NETWORKING” = “no” ]
-then

  • exit 0
    -fi

-RETVAL=0
-prog=”memcached”
-pidfile=${PIDFILE-/var/run/memcached/memcached.pid}
-lockfile=${LOCKFILE-/var/lock/subsys/memcached}

-start () {
echo -n $”Starting $prog: “
-# Ensure that /var/run/memcached has proper permissions
if [ “stat -c %U /var/run/memcached” != “$USER” ]; then
chown $USER /var/run/memcached
fi

daemon --pidfile ${pidfile} /usr/local/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}

}
stop () {
echo -n $”Stopping $prog: “
killproc -p ${pidfile} /usr/local/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}

restart () {
stop
start
}

-# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} memcached
RETVAL=$?
;;
restart|reload|force-reload)
restart
;;
condrestart|try-restart)
[ -f ${lockfile} ] && restart || :
;;
*)
echo $”Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart}”
RETVAL=2
;;
esac

exit $RETVAL

5.启动服务+开机自动重启
$ service memcached start
$ chkconfig memcached on

6.绑定内网:
1).使用-l参数指定访问的地址.
2).使用iptables规则匹配访问的地址.


推荐阅读
author-avatar
木木的亦尘_283
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有