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!

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.

Redis supports a variety of data structures, including: 1. String, suitable for storing single-value data; 2. List, suitable for queues and stacks; 3. Set, used for storing non-duplicate data; 4. Ordered Set, suitable for ranking lists and priority queues; 5. Hash table, suitable for storing object or structured data.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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