多个Memcached服务器/etc/init.d启动脚本工作?

我通过源安装memcached服务器,可以为1个memcached服务器实例安装标准启动脚本,但通过谷歌尝试几个脚本,找不到一个pipe理自动启动启动多个memcached服务器实例。 我已经尝试了这两个脚本,都不工作,服务memcached启动只是返回到命令提示符没有启动memcached服务器实例

  • lullabot.com/articles/installing-memcached-redhat-or-centos
  • addmoremem.blogspot.com/2010/09/running-multiple-instances-of-memcached.html

然而,这个bash脚本的工作原理,但启动时不会启动memcached实例?

#!/bin/sh case "$1" in start) /usr/local/bin/memcached -d -m 16 -p 11211 -u nobody /usr/local/bin/memcached -d -m 16 -p 11212 -u nobody ;; stop) killall memcached ;; esac 

操作系统:Centos 5.5 64位Memcached = v1.4.5 Memcache = v2.2.5

任何人都可以指向我的工作/etc/init.d/启动脚本来pipe理多个memcached服务器? 谢谢

编辑:谢谢,这是代码,结束了工作

 #!/bin/sh # chkconfig: - 80 12 # description: The memcached daemon is a network memory cache service. # processname: memcached BIN=/usr/local/bin/memcached USER=nobody CON=2048 THREADS=4 $BIN -d -m 16 -p 11211 -c $CON -t $THREADS -u $USER $BIN -d -m 16 -p 11212 -c $CON -t $THREADS -u $USER case "$1" in start) $BIN -d -m 16 -p 11211 -c $CON -t $THREADS -u $USER $BIN -d -m 16 -p 11212 -c $CON -t $THREADS -u $USER ;; stop) killall $BIN ;; esac 

为了给chkconfig添加一个服务,你通常需要在shell脚本下面添加一些特殊的注释:

 #!/bin/sh # chkconfig: - 55 45 # description: The memcached daemon is a network memory cache service. # processname: memcached 

将这些行添加到/etc/init.d/memcached之后,就可以发布了

 chkconfig --add memcached 

当然还有一个过程可以开始,以检查你会发出的额外的运行水平

 chkconfig --list | grep "memcached" 

memcached的常见运行级别是

 chkconfig --level 345 memcached on 

这里是我用来启动多个memcached实例的脚本。 关键是我使用关联数组来启动全部或只是一个特定的实例:

 #! /usr/local/bash4/bin/bash # # chkconfig: - 55 45 # description: The memcached daemon is a network memory cache service. # processname: memcached # config: /etc/sysconfig/memcached # Standard LSB functions #. /lib/lsb/init-functions # Source function library. . /etc/init.d/functions if [ -f /etc/sysconfig/memcached ];then . /etc/sysconfig/memcached fi # Check that networking is up. . /etc/sysconfig/network if [ "$NETWORKING" = "no" ] then exit 0 fi typeset -A PIDS typeset -A MEMORYS typeset -A FACTORS typeset -A INSTANCES PORTS="11216 11217" USER=memcached basedir="/usr/local/memcached" MAXCONN=1024 OPTIONS="" INSTANCES=([11216]="session" [11217]="userdata") PIDS=([11216]="$basedir/var/run/sohaphimdetails.pid" [11217]="$basedir/var/run/sohamuzik-top.pid") MEMORYS=([11216]="1024" [11217]="2048") FACTORS=([11216]="1.25" [11217]="1.125") RETVAL=0 prog="memcached" cmd="/usr/local/memcached/bin/memcached" user="memcached" ip="192.168.6.66" peer="192.168.6.28" max_conn=2048 max_memory=512 threads=8 function start() { port="$1" if [ `ps -ef | grep "$cmd" | grep -c $port` -ge 1 ]; then action $"Starting the memcached server on port '$port'... " /bin/false else if [ ! -f $basedir/var/log/${INSTANCES[$port]}.log ]; then touch $basedir/var/log/${INSTANCES[$port]}.log /bin/chown memcached:memcached $basedir/var/log/${INSTANCES[$port]}.log fi $cmd -d -u $user -l $ip -c $max_conn -t $threads -m ${MEMORYS[$port]} -p $port -P $basedir/var/run/${INSTANCES[$port]}.pid -f ${FACTORS[$port]} -x $peer -X `expr $port '*' 10` -vv > $basedir/var/log/${INSTANCES[$port]}.log 2>&1 action $"Starting the memcached server on port '$port'... " /bin/true fi } function stop() { port="$1" if [ `ps -ef | grep "$cmd" | grep -c $port` -eq 0 ]; then action $"Stopping the memcached server on port '$port'... " /bin/false else kill -TERM `ps -ef | grep "$cmd" | grep $port | grep -v grep | awk '{ print $2 }'` action $"Stopping the memcached server on port '$port'... " /bin/true fi } case "$1" in start) if [ -n "$2" ]; then start $2 else for port in $PORTS; do start $port done fi ;; stop) if [ -n "$2" ]; then port="$2" stop $port else killproc $prog fi ;; restart) if [ -n "$2" ]; then stop $2 start $2 else for port in $PORTS; do stop $port start $port done fi ;; *) printf 'Usage: %s {start|stop|restart} <port>\n' "$prog" exit 1 ;; esac 

PS:我用repcached进行复制。

由于脚本正在工作,我假设它没有从/etc/rc.d链接,所以它不会在启动时执行。 假设你的启动脚本叫/etc/init.d/memcached,你应该执行

 chkconfig --add memcached 

将其添加到启动时要运行的脚本列表中。