我安装了redis并将redis-server放在/ usr / local / bin:
-rwxr-xr-x 1 redis redis 11044232 Sep 24 00:30 redis-server
我在同一文件夹/ usr / local / bin中有redis.conf:
-rwxr-xr-x 1 redis redis 120 Oct 6 21:30 redis.conf
我在/ etc / systemd / system中创建了redis.service:
-rw-r--r-- 1 root root 192 Oct 6 21:46 redis.service
cat redis.conf:
Description=Redis
After=network.target
[Service]
User=redis
Group=redis
Type=Simple
ExecStart=/usr/local/bin/redis-server /usr/local/bin/redis.conf
[Install]
WantedBy=multi-user.target
但是当我跑步
sudo systemctl restart redis
sudo systemctl status redis
它显示:无法打开仅附加文件:权限被拒绝
如果我在redis.service上将服务单元中的用户和组更改为“ root”,然后再次重新启动,则redis服务器已成功启动。
我确实添加了用户redis:
sudo useradd --no-create-home --shell /bin/false redis
是什么原因?我想使用专用的用户redis来启动服务器。
答案 0 :(得分:0)
原因
用户redis
无权访问/usr/local/bin/appendonly.aof
,因为它位于/usr/local/bin
中。
默认情况下,Redis工作目录是相对于redis.conf
的,如以下行所示:
dir ./
解决方案
dir ./
中的redis.conf
更改为redis
用户可写的目录redis.conf
放置在redis
用户可写的目录中(无论如何,只有可执行文件应驻留在/usr/local/bin
中)