Set the redis boot method steps under mac
- 2020-05-13 03:48:39
- OfStack
An overview of the
It has been a long time since redis was installed. You need to manually start redis in the command line every time you run it, and the window cannot be closed. It is very troublesome, so I want to set redis to boot. Because google can not open (the great GFW ah), so baidu several articles, follow the tutorial step by step to do but did not succeed, blame yourself too stupid.
I have built an VPN by myself in the past two days, and google can be used again. So I have solved this problem. Now redis can finally start up, and High1 can be used.
To set redis to boot, I used mac's launchd system, running redis as the user daemon (User Daemon) process in the background. In simple terms, a user daemon is a non-graphical program that runs in the background as part 1 of the system. The user daemon is not associated with the user account. If you only want to set redis to boot for a specific user, you'll need to use a user agent (User Agent).
Specific steps
Create an plist file
First we need to create an plist file in the /Library/LaunchDaemons directory using the following command:
sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist
Paste the following into the file created by the previous command
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/redis-server</string>
<string>/usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
After pasting, we need to make two changes to the above content: 1 is the "redis-server" path, which needs to be changed to your own installation path (you can use the "which redis-server" command to see the specific path). The other one is the path of the redis configuration file, which is optional. If the configuration file is not used, then delete the second one. If the configuration file is used, 1 must be changed to the correct path.
Load the plist file into launchd
After editing the plist file, we need to load the file into launchd and use the launchctl command. The specific command is as follows:
sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist
After restarting, redis is ready to boot. If you don't want to reboot, you can also use the following command:
sudo launchctl start io.redis.redis-server
Close the redis
If you want to close redis, use the following command:
sudo launchctl stop io.redis.redis-server
Set an alias
For ease of use, we can alias the open and close commands of redis:
alias redisstart='sudo launchctl start io.redis.redis-server'
alias redisstop='sudo launchctl stop io.redis.redis-server'
conclusion
Wasted a little kung fu, finally able to make redis boot up, ^_^. If you encounter any errors, you can go to the console and look at the redis log.