centos7 redis 开机自启动

1. 安装redis(步骤省)。

   redis.conf配置文件中设置属性为后台启动daemonize:yes。

2. 安装chkconfig.

3. 启动脚本.

   vi /etc/init.d/redis
   复制内容如下:

   

#!/bin/sh
#chkconfig: 2345 90 10
#description: Start and Stop redis

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/bin/redis.conf"

case "$1" in
start)
if [ -f $PIDFILE ];then
echo "$PIDFILE exists,process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ];then
echo "$PIDFILE does not exist,process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
"$0" stop
sleep 3
"$0" start
;;

*)
echo "Please use start or stop or restart as first argument"
;;
esac
  修改完成后按 Esc ,再按 :wq + Enter(回车) 保存并退出.
4. 启动redis

打开redis命令:service redis start

关闭redis命令:service redis stop

设为开机启动:chkconfig redis on

设为开机关闭:chkconfig redis off.

5. 创建软链接

     ln -snf /usr/local/redis/bin/redis-cli /usr/bin/redis

6. reboot

   然后ps -aux|grep redis 查看是否有redis进程。

 

    

 

posted @ 2021-04-27 10:35  三驾马车  阅读(496)  评论(0编辑  收藏  举报