Linux上设置memcached自启动

#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
#[ ${NETWORKING} = "no" ] && exit 0
#[ -r /etc/sysconfig/dund ] || exit 0
#. /etc/sysconfig/dund
#[ -z "$DUNDARGS" ] && exit 0
MEMCACHED="/usr/local/memcached/bin/memcached"
SERVER_IP="127.0.0.1"
SERVER_PORT="11211"
[ -f $MEMCACHED ] || exit 1
start()
{
echo -n $"Starting memcached: "
daemon $MEMCACHED -u daemon -d -m 2048 -l $SERVER_IP -p $SERVER_PORT -P /tmp/memcached.pid
echo
}
stop()
{
echo -n $"Shutting down memcached: "
killproc memcached
echo
} # See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

  

将以上这段中的内容的中文部分去掉即可,只是用来在代码中做注释。memcached的位置改成您自己的对应位置

将这段代码编辑在 /etc/init.d/memcached文件里面

然后执行脚本:

#  chmod 755 /etc/init.d/memcached
# chkconfig --add memcached
# chkconfig memcached on
# service memcached start
#  chkconfig --list memcached  #查看是否设置成功

  

以上如成功则重启下系统后查看下memcached是否已随系统启动

#服务管理命令

service memcached start   # 启动memcached

service memcached stop   # 关闭memcached

service memcached restart   # 重启memcached

  

上一篇:静态库lib调试


下一篇:roadhog resolve alias 绝对路径 别名使用