签到成功

知道了

CNDBA社区CNDBA社区

创建memcached 自启动脚本并添加的linux 服务中

2016-09-06 00:37 3046 0 原创 Memcached
作者: dave


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

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2261
    原创
  • 3
    翻译
  • 578
    转载
  • 191
    评论
  • 访问:7971796次
  • 积分:4346
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ