linux 下配置 redis开机自动启动

原文:https://blog.csdn.net/hjh15827475896/article/details/90321646

1、设置redis.conf中daemonize为yes,确保守护进程开启。

2、编写开机自启动脚本

vi /etc/init.d/redis
仔细查看该目录,它是etc/init.d下的一个新的redis文件,为什么,因为Linux有机会执行该目录中的文件

[En]

Take a good look at the directory, it is a new redis file under etc/init.d, why, because linux has the opportunity to execute the files in this directory

我不知道怎么写剧本,但是网上有人可以,就拿来吧。

[En]

I don’t know how to write a script, but someone on the Internet can, just bring it.

# chkconfig: 2345 10 90
# description: Start and Stop redis

PATH=/usr/local/bin:/sbin:/usr/bin:/bin   #找到本机安装redis后,存放redis命令的目录
REDISPORT=6379                            #redis的默认端口, 要和下文中的redis.conf中一致
EXEC=/usr/redisbin/redis-server           #redis服务端的命令
REDIS_CLI=/usr/redisbin/redis-cli         #redis客户端的命令  这两个一般都在 PATH目录下
PIDFILE=/var/run/redis.pid                #reids的进程文件生成的位置
CONF="/usr/redisbin/redis.conf"           #redis的配置文件所在的目录
#AUTH="1234"  这句没什么用可以不要

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
                if [ "$?"="0" ]
                then
                        echo "Redis is running..."
                fi
                ;;
        stop)
                if [ ! -f $PIDFILE ]
                then
                        echo "$PIDFILE exists, process is not running."
                else
                        PID=$(cat $PIDFILE)
                        echo "Stopping..."
                       $REDIS_CLI -p $REDISPORT  SHUTDOWN
                        sleep 2
                       while [ -x $PIDFILE ]
                       do
                                echo "Waiting for Redis to shutdown..."
                               sleep 1
                        done
                        echo "Redis stopped"
                fi
                ;;
        restart|force-reload)
                ${0} stop
                ${0} start
                ;;
        *)
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
                exit 1
esac

写完,保存

[En]

Finish writing, save

将文件的权限修改为可执行的chmod 775/etc/init.d/redis

[En]

Modify the permissions of files to executable chmod 775 / etc/init.d/redis

测试Redis的启动

[En]

Test the startup of redis

/etc/init.d/redis start

已成功启动

[En]

Started successfully

设置自动启动

[En]

Set up automatic start

chkconfig redis on

此时会自动启动,系统会提示您创建XXX.service文件。

[En]

It will start automatically at this time, and the system will give you some prompts to create the XXX.service file.

下图如下:

[En]

The figure below is as follows

linux 下配置 redis开机自动启动

这里我们要讨论的是usr/lib/systemd/system/目录。

[En]

Here we want to talk about the usr/lib/systemd/system/ directory.

起初,我不知道我的nginx MySQL php是如何自动启动的,然后我进入了这个目录,然后我知道它们都在这里。我在网上说,我对linux centos的新启动模式不是很了解,但我知道这里的文件都是自启动服务。

[En]

At first, I didn’t know how my nginx mysql php started automatically, and then I went into this directory, and then I knew that they were all here. I said on the Internet that I didn’t know much about the new startup mode of linux centos, but I knew that the files here are all self-booting services.

因此,如果我们想知道这台机器上有哪些服务是自启动的,我们可以看看这个文件夹。

[En]

So if we want to know what services are self-booting on this machine, we can take a look at this folder.

Original: https://www.cnblogs.com/shihaiming/p/15028813.html
Author: 这个名字想了很久~
Title: linux 下配置 redis开机自动启动

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/7055/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总