编写配置文件

vim/etc/memcached.conf

内容如下:

-m128-d-p11211-c1024

编写启动脚本

vim /etc/rc.d/init.d/memcached 
#!/bin/bash
#
# memcached This shell script takes care of starting and stopping
# standalone memcached.
# . /etc/rc.d/init.d/functions PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/bin/memcached DAEMONBOOTSTRAP=/usr/local/bin/start-memcached DAEMONCONF=/etc/memcached.conf NAME=memcached DESC=memcached PIDFILE=/var/run/$NAME.pid [-x$DAEMON]||exit0[-x$DAEMONBOOTSTRAP]||exit0RETVAL=0 start(){echo-n $"Starting $DESC: " daemon $DAEMONBOOTSTRAP$DAEMONCONFRETVAL=$?[$RETVAL-eq0]&&touch$PIDFILEechoreturn$RETVAL} stop(){echo-n $"Shutting down $DESC: " killproc $NAMERETVAL=$?echo[$RETVAL-eq0]&&rm-f$PIDFILEreturn$RETVAL}# See how we were called.case"$1"in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$?;; status) status $progRETVAL=$?;;*)echo $"Usage: $0 {start|stop|restart|status}"exit1esacexit$RETVAL

[编辑]编写start-memcached脚本

vim /usr/local/bin/start-memcached 
#!/usr/bin/perl -w# start-memcached use strict; if($>!= 0 and $<!= 0){ print STDERR "Only root wants to run start-memcached.\n"; exit; } my $etcfile = shift||"/etc/memcached.conf"; my $params = []; my $etchandle; # This script assumes that memcached is located at /usr/bin/memcached, and# that the pidfile is writable at /var/run/memcached.pid my $memcached = "/usr/local/bin/memcached"; my $pidfile = "/var/run/memcached.pid"; # If we don't get a valid logfile parameter in the /etc/memcached.conf file,# we'll just throw away all of our in-daemon output. We need to re-tie it so# that non-bash shells will not hang on logout. Thanks to Michael Renner for# the tip my $fd_reopened = "/dev/null"; sub handle_logfile { my ($logfile) = @_; $fd_reopened = $logfile; } sub reopen_logfile { my ($logfile) = @_; open *STDERR, ">>$logfile"; open *STDOUT, ">>$logfile"; open *STDIN, ">>/dev/null"; $fd_reopened = $logfile; }# This is set up in place here to support other non -[a-z] directives my $conf_directives = {"logfile" => \&handle_logfile }; if(open $etchandle, $etcfile){ foreach my $line(<$etchandle>){$line =~ s/\#.*//go;$line = join' ', split' ', $line; next unless $line; next if$line =~ /^\-[dh]/o; if($line =~ /^[^\-]/o){ my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/; $conf_directives->{$directive}->($arg); next; } push @$params, $line; }} unshift @$params, "-u root" unless (grep$_ eq '-u', @$params); $params = join" ", @$params; if(-e $pidfile){ open PIDHANDLE, "$pidfile"; my $localpid = <PIDHANDLE>; close PIDHANDLE; chomp $localpid; if(-d "/proc/$localpid"){ print STDERR "memcached is already running.\n"; exit; }else{`rm-f$localpid`; }} my $pid = fork(); if($pid == 0){ reopen_logfile($fd_reopened); exec"$memcached$params"; exit(0); } elsif (open PIDHANDLE,">$pidfile"){ print PIDHANDLE $pid; close PIDHANDLE; }else{ print STDERR "Can't write pidfile to $pidfile.\n"; }

修改权限

chmod 755 /etc/rc.d/init.d/memcached chmod 755 /usr/local/bin/start-memcached 

启动

service memcached start 
[root@localhost keepalived]# service memcached start
Starting memcached:                                        [确定]
[root@localhost keepalived]#  ps -aux | grep memcached
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root     10803  0.0  0.1 326900  1196 ?        Ssl  18:25   0:00 /usr/local/bin/memcached -u root -m 128 -d -p 11211 -c 1024
root     10811  0.0  0.0 103256   880 pts/1    S+   18:25   0:00 grep memcached

[编辑]艺搜参考

http://forums.eukhost.com/f15/memcached-best-caching-option-linux-web-servers-5269/

http://duntuk.com/how-install-memcached-centos-memcached-php-extension-centos

http://complitech.net/steps-for-install-memcached-on-fedoara-linux-platform-and-create-service-for-memcached/

Memcached启停脚本小结的更多相关文章

  1. Linux 程序启停脚本

    start.sh #!/bin/sh java -jar ./program.jar & echo $! > /var/run/program.pid stop.sh #!/bin/sh ...

  2. linux下的启停脚本

    linux下的根据项目名称,进行进程的启停脚本 #!/bin/bash JAVA=/usr/bin/java APP_HOME=/opt/program/qa/wechat APP_NAME=prog ...

  3. case编写的httpd简单启停脚本

    case编写的httpd简单启停脚本 #!/bin/bash HTTPD="/etc/init.d/httpd" . /etc/init.d/functions case &quo ...

  4. Oracle EBS R12的启停脚本

    以下脚本用root用户登录执行: 一.DB启停使用EBS提供的脚本ebs_start.shsu - oraprod -c "/d01/oracle/PROD/db/tech_st/10.2. ...

  5. Oracle BIEE启停脚本

    作为BI的开发人员,经常启停BI服务在所难免,启动的过程又比较长,命令需要不同目录切换,简直烦死人呢, 特意整理了linux中的启动脚本,将以下脚本存成biee.sh,后面的过程就相当简单了, 启动: ...

  6. python启停脚本的编写

    先占个位置,打算记录一下启停python 的脚本start.sh,stop.sh的写法. 内容包括启动python脚本的方式,日志的重定向,获取进程id,以及杀掉进程. 参考文章: http://bl ...

  7. mysql自己编写启停脚本

    一.场景 在实际生产环境中要求相对较高的企业对于root权限管控相对比较高,故而很多软件并非安装在root用户下(当然root用户权限也可管理,但正常情况下root权限并不会给业务使用方,而会给一个普 ...

  8. nginx启停脚本

    安装nginx时,源码包中未带官方的启动脚本,也就无法使用service nginxd start这种启动方式,查了下资料自己写了一个: #!/bin/bash #@version: #@author ...

  9. liunx weblogic服务启停脚本

    #!/bin/bash #sh xx.sh start xx项目 例如:sh autoWeblogic.sh start bius #经测试发现weblogic 启动大概需要完全启动成功35秒左右 停 ...

随机推荐

  1. LINUX下 my.cnf php.ini的位置

    my.cnf:/etc/ php.in:/usr/local/php/etc/

  2. C#路径总结

    [相对路径]   Request.ApplicationPath /src Path.GetDirectoryName(HttpContext.Current.Request.RawUrl ) //s ...

  3. 域名在微信朋友圈内分享需要ICP备案 杜绝不良信息传播

    就在刚刚,腾讯微信团队发布公告表示域名在朋友圈内分享需要ICP备案,杜绝打击不良互联网信息的传播.公告称根据互联网管理相关规定,即日起在微信朋友圈内分享的域名,请在2014年12月31日前完成ICP备 ...

  4. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  5. IOS APP的所有图标尺寸规范

    转自: http://blog.csdn.net/chonbj/article/details/25133247 像我一样记不住iOS应用图标像素尺寸的开发者不在少数,我经常需要查询不同设备上的应用尺 ...

  6. 暑假热身 B. 下载测速

    最近,nono终于结束了每年一次的为期12个月的冬眠,醒来的第一件事就是——看电影!!nono发现最近一年出现了各种很好很强大的电影,例如这个.这个.还有这个. 于是nono直接把这些电影全部扔进了下 ...

  7. 【Spring】Spring系列2之bean的配置

    2.bean的配置 2.1.IOC概述 2.2.bean的获取 2.3.依赖注入方式 2.4.属性注入细节 内部bean,不需要ID,ID无效,外部不能引用: 2.5.集合属性注入 2.6.使用p命名 ...

  8. Quartz作业调度框架

    Quartz 是一个开源的作业调度框架,它完全由 Java 写成,并设计用于 J2SE 和 J2EE 应用中.它提供了巨大的灵活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度.本 ...

  9. 跨域请求获取Solr json检索结果并高亮显示

    Solr提供了json格式的检索结果,然而在跨域的情况下如何调用呢?我们可以利用jquery提供的jsonp的方式获取Solr检索结果. <script type="text/java ...

  10. 对Java中字符串的进一步理解

    字符串在程序开发中无处不在,也是用户交互所涉及到最频繁的数据类型,那么字符串不仅仅就是我们简单的理解的String str = "abc";一起来更加深入的看一下 在Java中,字 ...