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

修改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.pid
11 CONF="/usr/local/redis/redis.conf" #实际环境而定
12 
13 case "$1" in
14         start)
15                 if [ -f $PIDFILE ]
16                 then
17                         echo "$PIDFILE exists, process is already running or crashed."
18                 else
19                         echo "Starting Redis server..."
20                         $EXEC $CONF
21                 fi
22                 if [ "$?"="0" ]
23                 then
24                         echo "Redis is running..."
25                 fi
26                 ;;
27         stop)
28                 if [ ! -f $PIDFILE ]
29                 then
30                         echo "$PIDFILE exists, process is not running."
31                 else
32                         PID=$(cat $PIDFILE)
33                         echo "Stopping..."
34                         $REDIS_CLI -p $REDISPORT SHUTDOWN
35                         while [ -x $PIDFILE ]
36                         do
37                                 echo "Waiting for Redis to shutdown..."
38                                 sleep 1
39                         done
40                         echo "Redis stopped"
41                 fi
42                 ;;
43         restart|force-reload)
44                 ${0} stop
45                 ${0} start
46                 ;;
47         *)
48                 echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
49                 exit 1
50 esac

 

 

执行权限:

chmod +x /etc/init.d/redis

开机自启动:

# 尝试启动或停止redis
service redis start
service redis stop

# 开启服务自启动
chkconfig redis on
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值