sudo nano /etc/systemd/system/redis.service
2. 添加以下内容到文件中:
[Unit] Description=Redis In-Memory Data Store After=network.target
[Service] User=redis Group=redis ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf ExecStop=/usr/local/bin/redis-cli shutdown Restart=always
[Install] WantedBy=multi-user.target
确保`ExecStart`中的路径是你的Redis服务可执行文件的正确路径,同样`redis.conf`配置文件的路径也要正确。
3. 重新加载systemd管理器配置:
sudo systemctl daemon-reload
4. 启动Redis服务:
sudo systemctl start redis.service
5. 设置Redis服务在启动时自动运行:
sudo systemctl enable redis.service