How to set redis to start automatically at boot under Linux
Linux设置redis开机自启具体方法
1、设置redis.conf中daemonize为yes,确保守护进程开启。
2、编写开机自启动脚本
vi /etc/init.d/redis
看清楚目录,是在 etc/init.d下新建redis文件 ,为什么,因为 linux开机会 执行这个目录中的文件
编写脚本,本人不会,但网上有人会,拿来就好
# 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
编写完成,保存
修改文件的权限为 可执行的 chmod 775 /etc/init.d/redis
测试一下redis 的启动
/etc/init.d/redis start
启动成功
设置自动启动
chkconfig redis on
此时就会自动启动了,系统会给你一些提示,创建了 XXX.service文件
如下图
这里要说一下 usr/lib/systemd/system/ 这个目录
刚开始我一直不知道 我的nginx mysql php 是怎么开机自动启动的 后来我进入了这个目录看了,才知道,原来它们都在这里,网上说这里linux centos 新的启动方式,我不怎么了解,但是我知道了,这里的 文件都是可以开机自启的服务
所以我们要想知道 本机开机都自启了什么服务 可以来这个文件夹下看一下。
Linux有哪些版本
Linux的版本有:Deepin、UbuntuKylin、Manjaro、LinuxMint、Ubuntu等版本。其中Deepin是国内发展最好的Linux发行版之一;UbuntuKylin是基于Ubuntu的衍生发行版;Manjaro是基于Arch的Linux发行版;LinuxMint默认的Cinnamon桌面类似Windows XP简单易用;Ubuntu则是以桌面应用为主的Linux操作系统。
The above is the detailed content of How to set redis to start automatically at boot under Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

Laravel 8 provides the following options for performance optimization: Cache configuration: Use Redis to cache drivers, cache facades, cache views, and page snippets. Database optimization: establish indexing, use query scope, and use Eloquent relationships. JavaScript and CSS optimization: Use version control, merge and shrink assets, use CDN. Code optimization: Use Composer installation package, use Laravel helper functions, and follow PSR standards. Monitoring and analysis: Use Laravel Scout, use Telescope, monitor application metrics.
