systemctl 启动redis

这次经历主要是一次错误原因的查看过程。
我登陆用户为root
进行了启动redis服务

redis-server /etc/redis.conf

然后杀死了redis服务后,想直接配置为系统启动方式–systemctl

systemctl enable redis
systemctl start redis

启动失败,开始提示我使用 journalctl -ex 可以查看详情
确实可以看到一个错误

-- Unit redis.service has begun starting up.
8月 20 10:58:40 VM_0_12_centos redis-server[4343]: *** FATAL CONFIG FILE ERROR ***
8月 20 10:58:40 VM_0_12_centos redis-server[4343]: Reading the configuration file, at line 163
8月 20 10:58:40 VM_0_12_centos redis-server[4343]: >>> 'logfile /var/log/redis/redis.log'
8月 20 10:58:40 VM_0_12_centos redis-server[4343]: Can't open the log file: Permission denied
8月 20 10:58:40 VM_0_12_centos systemd[1]: redis.service: main process exited, code=exited, status=1
8月 20 10:58:40 VM_0_12_centos redis-shutdown[4344]: Could not connect to Redis at 127.0.0.1:6379: C
8月 20 10:58:40 VM_0_12_centos systemd[1]: redis.service: control process exited, code=exited status
8月 20 10:58:40 VM_0_12_centos systemd[1]: Failed to start Redis persistent key-value database.
-- Subject: Unit redis.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit redis.service has failed.
--
-- The result is failed.

可以发现是对日志文件/var/log/redis/redis.log权限不足
查看了该文件属于root用户root组。
然后查看服务文件配置

cat /lib/systemd/system/redis.service
//显示
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
ExecStop=/usr/libexec/redis-shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

说明这个服务系统启动后是redis组的,所以改文件权限为redis组即可

chown redis:redis /var/log/redis/redis.log

你可能感兴趣的:(数据库)