Redis starts automatically on boot in centos7
Create the redis.service file in the system service directory
vi /etc/systemd/system/redis.service
Write the following content:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf (Fill in the path to your redis configuration file here)
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Test and add auto-start on boot
Close redis-server first
systemctl stop redis.service
Open redis-server
Systemctl start redis.service #If the service is on, using this command will Startup failed.
Successfully opened, add the service to start automatically at boot
Systemctl enable redis.service #Note that it cannot be followed by a space
Reboot #Restart
Check the service running status: systemctl status redis.service
All commands
Systemctl start redis.service #Start redis service
Systemctl enable redis.service #Set auto-start at boot
Systemctl disable redis.service #Stop auto-start at boot
systemctl status redis.service # View the current status of the service
Systemctl restart redis.service #Restart the service
Systemctl list-units –type=service #View all started services
Note: The above method is not only applicable to redis , also suitable for other service deployment
The above is the detailed content of How to set redis to enable auto-start on Linux. For more information, please follow other related articles on the PHP Chinese website!