http://www.cndba.cn/dave/article/193
1. 创建如下文件http://www.cndba.cn/dave/article/193
touch /etc/init.d/memcached[root@dave /]# chmod u+x /etc/init.d/memcached
2 在脚本里添加如下内容
注意脚本中memcached的路径和端口等信息。http://www.cndba.cn/dave/article/193
http://www.cndba.cn/dave/article/193
#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
start()
{
echo -n $"Starting memcached: "
daemon /usr/local/bin/memcached -d -m 2048 -u root -l 127.0.0.1 -p 22222 -c 1024 -P /tmp/memcached.pid
echo
}
stop()
{
echo -n $"Shutting down memcached: "
killproc memcached
echo
}
[ -f /usr/local/bin/memcached ] || exit 0
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart}"
exit 1
esac
exit 0
3 将memcached 启动脚本添加到chkconfighttp://www.cndba.cn/dave/article/193
[root@dave /]# chkconfig --add memcached
4 设置memcached 自启动http://www.cndba.cn/dave/article/193http://www.cndba.cn/dave/article/193
[root@dave /]# chkconfig --list | grep "memcached"
memcached 0:off 1:off 2:off 3:off 4:off 5:off 6:off[root@dave /]# chkconfig --level 235 memcached on[root@dave /]# chkconfig --list | grep "memcached"
memcached 0:off 1:off 2:on 3:on 4:off 5:on 6:off
5 使用服务启动memcached
5.1 使用/etc/init.d/memcached 脚本
[root@dave /]# /etc/init.d/memcached start
Starting memcached: [ OK ][root@dave /]# ps -ef|grep memcached
root 9875 1 0 16:27 ? 00:00:00 memcached -d -m 2048 -u root -l 192.168.1.14 -p 22222 -c 1024 -P /tmp/memcached.pid
root 9926 1901 0 16:36 pts/0 00:00:00 grep memcached[root@dave /]# /etc/init.d/memcached stop
Shutting down memcached: [ OK ][root@dave /]# ps -ef|grep memcached
root 9935 1901 0 16:36 pts/0 00:00:00 grep memcached[root@dave /]# /etc/init.d/memcached restart
Shutting down memcached: [FAILED]
Starting memcached: [ OK ][root@dave /]# ps -ef|grep memcached
root 9948 1 0 16:36 ? 00:00:00 /usr/local/bin/memcached -d -m 2048 -u root -l 192.168.1.14 -p 22222 -c 1024 -P /tmp/memcached.pid
root 9955 1901 0 16:36 pts/0 00:00:00 grep memcached[root@dave /]#
5.2 使用service
[root@dave /]# service memcached stop
Shutting down memcached: [ OK ][root@dave /]# ps -ef|grep memcached
root 9969 1901 0 16:37 pts/0 00:00:00 grep memcached[root@dave /]# service memcached start
Starting memcached: [ OK ][root@dave /]# ps -ef|grep memcached
root 9980 1 0 16:37 ? 00:00:00 /usr/local/bin/memcached -d -m 2048 -u root -l 192.168.1.14 -p 22222 -c 1024 -P /tmp/memcached.pid
root 9987 1901 0 16:37 pts/0 00:00:00 grep memcached[root@dave /]#
http://www.cndba.cn/dave/article/193
http://www.cndba.cn/dave/article/193
http://www.cndba.cn/dave/article/193
版权声明:本文为博主原创文章,未经博主允许不得转载。