侧边栏壁纸
博主头像
CYC的个人博客博主等级

学习使人进步

  • 累计撰写 91 篇文章
  • 累计创建 11 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Redis将本地redis打成服务开机启动

Administrator
2023-12-03 / 0 评论 / 0 点赞 / 88 阅读 / 1767 字

Redis将本地redis打成服务开机启动

设置Redis开机启动需要如下几个步骤:

编写配置脚本 [ vim /etc/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#chkconfig: 2345 80 90
#description:auto_run
REDISPORT=6379
EXEC=/usr/local/bin/redis/src/redis-server
CLIEXEC=/usr/local/bin/redis/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/bin/redis/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
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac





修改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


修改文件执行权限
chmod +x /etc/init.d/redis

设置开机启动
# 尝试启动或停止 redis
./redis start
./redis stop
# 开启服务自启动
chkconfig redis on



5.异常处理
A. 执行 [ service redis start ] 提示服务不支持 chkconfig,在开机脚本前添加如下内容:

复制 
#chkconfig: 2345 80 90
#description:auto_run
-----------------------------------

0

评论区