代码狗

Memcached开机自启脚本

前面讲了如何按照memcached缓存系统,并且也成功配置了PHP的缓存支持,当我们重启服务器后会发现memcached缓存服务并没有随之启动,还需要我们手动开启,这样十分不方便,百度很多开机自启脚本都有错误,或者不管用,找到一份memcached官方的自启脚本,内容如下,复制保存到服务器/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

# Source function library - for other linux

#. /etc/rc.d/init.d/functions

# Source function library - for SUSE linux

. /lib/lsb/init-functions

PORT=你的缓存服务端口

USER=root

#最大连接数,根据实际需求修改

MAXCONN=256

#最大内存量,单位M

CACHESIZE=128

OPTIONS=""

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

. /etc/sysconfig/memcached

fi

# Check that networking is up.

if [ "$NETWORKING" = "no" ]

then

exit 0

fi

RETVAL=0

prog="memcached"

start () {

echo -n $"Starting $prog: "

# insure that /usr/local/memcached has proper permissions

chown $USER /usr/local/bin/memcached

/usr/local/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /usr/local/memcached/memcached.pid $OPTIONS

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached

}

stop () {

echo -n $"Stopping $prog: "

killproc memcached

RETVAL=$?

echo

if [ $RETVAL -eq 0 ] ; then

rm -f /var/lock/subsys/memcached

rm -f /usr/local/memcached/memcached.pid

fi

}

restart () {

stop

start

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status memcached

;;

restart|reload)

restart

;;

condrestart)

[ -f /var/lock/subsys/memcached ] && restart || :

;;

*)

echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"

exit 1

esac

exit $?

注意:上面的代码中/usr/local/bin/memcached是我的安装目录,需要替换成你们自己的,否则会出错启动不了。如果你是照着我前面的教程做的,可以不用修改,只需要改改memcached的端口即可。

上面需要配置的参数都用中文注释了,自己按需要修改即可。

修改文件权限

chmod 755 /etc/init.d/memcached

将其加入系统服务

chkconfig --add memcached
chkconfig memcached on

memcached启动、停止、重启命令

service memcached start
service memcached stop
service memcached restart

现在重启下服务器,终端输入netstat -tunlp,查看开放的端口,你的memcached服务端口是否开放了是否存在memcached相关字样,开放了一般就说明开机自启成功了。

Memcached开机自启脚本

Memcached开机自启脚本

感觉很棒!可以赞赏支持我哟~

赞(1) 打赏

请作者吃个烤肠

支付宝扫一扫打赏

微信扫一扫打赏