编写配置文件

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. POJ 1836 Alignment

    Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...

  2. Charm Bracelet

    Charm Bracelet Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  3. Server Application Unavailable出现的原因及解决方案集锦

    iis ServerAppl 共存 应用程序池 站点  在Asp.net站点中经常出现这种提示 Server Application Unavailable The web application y ...

  4. PHP 上传文件和读取文件崎岖路

    今天php上传文件和读取文件没有搞出来,全靠后来大神来帮忙,总结一下:主要涉及到一下几个方面,在ubuntu下mkdir文件夹的时候要注意权限问题,一般情况下php是以一个较低的权限去执行的,所以如果 ...

  5. 使用HTML5 Web存储的localStorage和sessionStorage方式

    localStorage(本地存储),可以长期存储数据,没有时间限制,一天,一年,两年甚至更长,数据都可以使用.sessionStorage(会话存储),只有在浏览器被关闭之前使用,创建另一个页面时同 ...

  6. ubuntu上完全卸载package

    inux上完整的卸载apt方式安装软件的办法. 假设你的包叫做: your_pkg apt-get --purge remove your_pkg apt-get autoremove apt-get ...

  7. Kruskal vs Borůvka

    做了个对比.Borůvka算法对于稠密图效果特别好.这两个都是求生成森林的算法.Prim+heap+tarjan过于难写不写了. V=200,E=1000 Kruskal method 4875048 ...

  8. mysql如何设置密码

    1.用root 进入mysql后mysql>set password =password('你的密码');mysql>flush privileges;2.使用GRANT语句 mysql& ...

  9. sublime text多文件夹查找关键字

    Ctrl+shift+F 快捷键在文件夹内查找,与普通编辑器不同的地方是sublime允许添加多个文件夹进行查找 转自:http://www.douban.com/note/362268947/

  10. Java for LeetCode 142 Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...