centos6.5 redis3 开机自动启动命令设置

来源:互联网 发布:kd优化指标公式 编辑:程序博客网 时间:2024/06/07 03:48

原文链接: http://www.cnblogs.com/leechenxiang/p/5526693.html


修改redis.conf,打开后台运行选项:

# By default Redis does not run as a daemon. Use 'yes' if you need it.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.daemonize yes

编写脚本,vim /etc/init.d/redis:

复制代码
 1 # chkconfig: 2345 10 90 2 # description: Start and Stop redis 3  4 PATH=/usr/local/bin:/sbin:/usr/bin:/bin 5  6 REDISPORT=6379 #实际环境而定 7 EXEC=/usr/local/redis/src/redis-server #实际环境而定 8 REDIS_CLI=/usr/local/redis/src/redis-cli #实际环境而定 9 10 PIDFILE=/var/run/redis.pid11 CONF="/usr/local/redis/redis.conf" #实际环境而定12 13 case "$1" in14         start)15                 if [ -f $PIDFILE ]16                 then17                         echo "$PIDFILE exists, process is already running or crashed."18                 else19                         echo "Starting Redis server..."20                         $EXEC $CONF21                 fi22                 if [ "$?"="0" ]23                 then24                         echo "Redis is running..."25                 fi26                 ;;27         stop)28                 if [ ! -f $PIDFILE ]29                 then30                         echo "$PIDFILE exists, process is not running."31                 else32                         PID=$(cat $PIDFILE)33                         echo "Stopping..."34                         $REDIS_CLI -p $REDISPORT SHUTDOWN35                         while [ -x $PIDFILE ]36                         do37                                 echo "Waiting for Redis to shutdown..."38                                 sleep 139                         done40                         echo "Redis stopped"41                 fi42                 ;;43         restart|force-reload)44                 ${0} stop45                 ${0} start46                 ;;47         *)48                 echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&249                 exit 150 esac
复制代码

 

 

执行权限:

chmod +x /etc/init.d/redis

开机自启动:

# 尝试启动或停止redisservice redis startservice redis stop# 开启服务自启动chkconfig redis on

阅读全文
0 0
原创粉丝点击