Linux – 将memcached注册为服务

1、编写脚本

编写脚本文件如下(memcached):

#!/bin/sh
#
# memcached: Start/Stop/Restart memcached
# chkconfig: 35 33 84
# description: memcached server
MEMCACHED=/usr/local/bin/memcached
# memcached 分配的内存大小,单位M
MEMSIZE=128
USER=nobody

# memcached使用的端口
PORT01=11211
# 每个memcache 提供的最大连接数
MAXCONN=1024
# 每个memcache 的进程ID
PID01=/var/run/memcached/memcached$PORT01.pid
RETVAL=0

start() {
         echo -n $"Starting $prog: "
         $MEMCACHED -d -m $MEMSIZE -u $USER -p $PORT01 -c $MAXCONN -P $PID01
     if [ $? -eq 0 ];then
            echo "memcacheds$PORT01 servers is start ok..."
         else
            echo "memcacheds$PORT01 server not runing......"
         fi

        }

stop() {

      for i in $PID01
      do 
       kill `cat $i`
       rm -f $i
           echo  $"Stopping $prog: "
      done

     }

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
;;
esac
exit $RETVAL

2、将其放入/etc/init.d/目录下

3、为文件赋予被执行的权限

chmod /etc/init.d/memcached

4、将memcached加入chkconfig管理列表

执行命令:

chkconfig --add memcached

chkconfig memcached on

5、启动memcached服务

service memcached start
标签:LinuxMemcache 发布于:2019-11-07 22:54:44