使用./install_server.sh安装Redis时遇systemd相关错误求助
Hey there, I've run into this exact issue before—let's get your Redis set up properly with systemd since your system doesn't use the old sysvinit/upstart that the install_server.sh script was built for. Here's a step-by-step breakdown:
1. Locate the systemd service example file
You're already in the utils directory of your Redis source code, which has a pre-made systemd service template. Look for redis-server.service (it should be right there alongside the install_server.sh script).
2. Copy and customize the service file
First, copy the template to systemd's service directory (where systemd looks for service definitions):
sudo cp redis-server.service /etc/systemd/system/
Next, open the copied file to adjust paths to match your setup—this is crucial:
sudo vim /etc/systemd/system/redis-server.service
You'll need to tweak these key fields:
- ExecStart: Point this to your compiled
redis-serverbinary. If you built Redis from source, it's likely in thesrcfolder of your Redis source (e.g.,/path/to/redis-source/src/redis-server /etc/redis/redis.conf). Don't forget to include the path to yourredis.conffile too. - PIDFile: This should match the
pidfilesetting in yourredis.conf(default is/var/run/redis_6379.pid). - WorkingDirectory: Set this to your Redis data directory (common choices are
/var/lib/redisor thedatafolder in your source). - User/Group: Make sure these match the user/group you want Redis to run as (many setups use a dedicated
redisuser—create it first if you haven't withsudo useradd -r redis).
3. Prepare necessary directories (if missing)
If you're using standard paths like /var/lib/redis for data and /var/log/redis for logs, create them and set proper permissions:
sudo mkdir -p /var/lib/redis /var/log/redis sudo chown redis:redis /var/lib/redis /var/log/redis sudo chmod 770 /var/lib/redis /var/log/redis
4. Enable and start the Redis service
Reload systemd to recognize the new service file, then enable it to start on boot, and launch it:
sudo systemctl daemon-reload sudo systemctl enable redis-server sudo systemctl start redis-server
5. Verify everything works
Check the service status to confirm it's running:
sudo systemctl status redis-server
You can also test connectivity with Redis CLI:
redis-cli ping
If you get PONG back, you're good to go!
内容的提问来源于stack exchange,提问作者raywong

