Linux上设置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=11211 USER=root #最大连接数,根据实际需求修改 MAXCONN=1024 #最大内存量,单位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/memcached /usr/local/memcached/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 $?
将以上这段中的内容的中文部分去掉即可,只是用来在代码中做注释。memcached的位置改成您自己的对应位置
将这段代码编辑在 /etc/init.d/memcached文件里面
然后执行脚本:
# chmod 755 /etc/init.d/memcached # chkconfig --add memcached # chkconfig memcached on # service memcached start
以上如成功则重启下系统后查看下memcached是否已随系统启动
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。