systemctl无法启动redis


#1

我在树莓派上安装redis时遇到了问题。手动执行

$ /usr/sbin/redis-server /etc/redis/default.conf

可以正常运行redis,但是使用systemd就fail。

系统信息是:

$ hostnamectl

  Operating System: openSUSE Leap 15.0
       CPE OS Name: cpe:/o:opensuse:leap:15.0
            Kernel: Linux 4.12.14-lp150.12.28-default
      Architecture: arm64

具体流程如下:

安装redis

$ sudo zypper in redis

安装完成,创建配置文件

$ sudo cp /etc/redis/default.conf.example /etc/redis/default.conf

执行:

$ sudo systemctl enable redis@default
$ sudo systemctl start redis@default
$ sudo systemctl status redis@default
● redis@default.service - Redis
   Loaded: loaded (/usr/lib/systemd/system/redis@.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis@default.service.d
           └─limits.conf
   Active: failed (Result: exit-code) since Fri 2019-01-11 16:53:45 CST; 32s ago
  Process: 1700 ExecStart=/usr/sbin/redis-server /etc/redis/default.conf (code=exited, status=1/FAILURE)
 Main PID: 1700 (code=exited, status=1/FAILURE)

1月 11 16:53:45 localhost systemd[1]: redis@default.service: Failed with result 'exit-code'.
1月 11 16:53:45 localhost systemd[1]: redis@default.service: Service RestartSec=100ms expired, scheduling restart.
1月 11 16:53:45 localhost systemd[1]: Stopped Redis.
1月 11 16:53:45 localhost systemd[1]: redis@default.service: Start request repeated too quickly.
1月 11 16:53:45 localhost systemd[1]: Failed to start Redis.
1月 11 16:53:45 localhost systemd[1]: redis@default.service: Unit entered failed state.
1月 11 16:53:45 localhost systemd[1]: redis@default.service: Failed with result 'exit-code'.

是我错过了什么么 T_T


#2
  1. redis配置文件中设置为

    daemonize yes
    supervised systemd
    
  2. /usr/lib/systemd/system/redis@.service

    Type=forking
    

#3

我把simple改为forking之后,现在运行

# systemctl restart redis@default
Job for redis@default.service failed because the control process exited with error code.
See "systemctl  status redis@default.service" and "journalctl  -xe" for details.

错误信息还和之前的一样…


#4

我觉得你还是重启一下再看看有没有自动启动了


#5

重启了之后,还是一样的错误。。。
这是修改后的redis@.service

[Unit]
Description=Redis
After=network.target
PartOf=redis.target

[Service]
Type=forking # simple
User=redis
Group=redis
PrivateTmp=true
PIDFile=/var/run/redis/%i.pid
ExecStart=/usr/sbin/redis-server /etc/redis/%i.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target redis.target

#6

看一下 journalctl -xe -u redis@default 有没有具体的报错


#7

抱歉这么久才看到。

这是输出的信息

--
-- 启动结果为“done”。
1月 11 18:44:23 localhost redis-server[1377]: 1377:C 11 Jan 18:44:23.577 # Fatal error, can't open config file '/etc/redis/default.conf'
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Main process exited, code=exited, status=1/FAILURE
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Unit entered failed state.
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Failed with result 'exit-code'.
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Service RestartSec=100ms expired, scheduling restart.
1月 11 18:44:23 localhost systemd[1]: Stopped Redis.
-- Subject: redis@default.service 单元已结束停止操作
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- redis@default.service 单元已结束停止操作。
1月 11 18:44:23 localhost systemd[1]: Started Redis.
-- Subject: redis@default.service 单元已结束启动
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- redis@default.service 单元已结束启动。
--
-- 启动结果为“done”。
1月 11 18:44:23 localhost redis-server[1380]: 1380:C 11 Jan 18:44:23.825 # Fatal error, can't open config file '/etc/redis/default.conf'
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Main process exited, code=exited, status=1/FAILURE
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Unit entered failed state.
1月 11 18:44:23 localhost systemd[1]: redis@default.service: Failed with result 'exit-code'.
1月 11 18:44:24 localhost systemd[1]: redis@default.service: Service RestartSec=100ms expired, scheduling restart.
1月 11 18:44:24 localhost systemd[1]: Stopped Redis.
-- Subject: redis@default.service 单元已结束停止操作
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- redis@default.service 单元已结束停止操作。
1月 11 18:44:24 localhost systemd[1]: redis@default.service: Start request repeated too quickly.
1月 11 18:44:24 localhost systemd[1]: Failed to start Redis.
-- Subject: redis@default.service 单元已失败
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- redis@default.service 单元已失败。
--
-- 结果为“failed”。
1月 11 18:44:24 localhost systemd[1]: redis@default.service: Unit entered failed state.
1月 11 18:44:24 localhost systemd[1]: redis@default.service: Failed with result 'exit-code'.

这是 /etc/redis/下的信息

# ll
-rw-r----- 1 root root  58832 Jan 11 18:40 default.conf
-rw-r----- 1 root redis 58832 May 17  2018 default.conf.example
-rw-r----- 1 root redis  7606 May 17  2018 sentinel.conf.example

#8

emmmm…

我修改了default.conf的权限

-rw-r----- 1 redis redis 58832 Jan 11 18:40 default.conf
-rw-r----- 1 root redis 58832 May 17  2018 default.conf.example
-rw-r----- 1 root redis  7606 May 17  2018 sentinel.conf.example

现在的报错信息是

-- The start-up result is done.
Jan 14 10:59:06 localhost redis-server[13825]: *** FATAL CONFIG FILE ERROR ***
Jan 14 10:59:06 localhost redis-server[13825]: Reading the configuration file, at line 172
Jan 14 10:59:06 localhost redis-server[13825]: >>> 'logfile /var/log/redis/default.log'
Jan 14 10:59:06 localhost systemd[1]: redis@default.service: Main process exited, code=exited, status=1/FAILURE
Jan 14 10:59:06 localhost systemd[1]: redis@default.service: Unit entered failed state.
Jan 14 10:59:06 localhost systemd[1]: redis@default.service: Failed with result 'exit-code'.
Jan 14 10:59:07 localhost systemd[1]: redis@default.service: Service RestartSec=100ms expired, scheduling restart.
Jan 14 10:59:07 localhost systemd[1]: Stopped Redis.
-- Subject: Unit redis@default.service has finished shutting down

这一行的配置有什么问题呢?


#9

:sweat_smile::sweat_smile:
我看了下,log文件的权限居然也是root的。。我把权限改成redis之后就正常运行了。。
头疼。。为什么他自己生成的文件权限是root的呢?


#10
  1. redis默认的配置文件不用修改。
daemonize no   # 默认是no,不需要改成yes
supervised systemd

2 . service文件,我改成forking之后不能运行,改回原来的simple了。

:kissing_closed_eyes:


#11

本主题在最后一个回复创建后60分钟后自动锁定。不再允许添加新回复。