Memcached 的编译安装过程请参考本站的《Linux下部署Memcached和PHP的Memcache扩展方法》
如 Memcached 已在 Linux 中安装完毕,且被部署到 /usr/local/memcached 这个路径下,接下来我们来开始为其安装用于启动和停止的服务管理脚本。
首先,通过 vi 在 /etc/rc.d/init.d 路径下新建一个名为 memcached 的脚本文件,命令如下:
vi /etc/rc.d/init.d/memcached
然后,向其中写入 Shell 脚本如下:
#!/bin/sh # # chkconfig: 2345 90 50 # description: Memcached Service Daemon # # processname: Memcached # # 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" start() { echo -n $"Starting Memcached: " daemon $MEMCACHED -u daemon -d -m 32 -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid echo } stop() { echo -n $"Shutting down Memcached: " killproc memcached echo } [ -f $MEMCACHED ] || exit 1 # 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
保存退出 vi 后,执行下面的命令来安装这个脚本
chmod 777 /etc/rc.d/init.d/memcached chkconfig --add memcached chkconfig --level 235 memcached on
然后可以通过下面的命令来检查是否安装成功
chkconfig --list | grep memcached service memcached start service memcached stop service memcached restart
阳光部落原创,更多内容请访问 http://www.sunbloger.com/