无法使用systemctl在Centos 7上启动redis服务器
Cannot start redis server on Centos 7 with systemctl
我在 CentOS7 上使用 systemctl 启动 Redis 时遇到了一些问题。我应该如何解决问题?
我可以使用普通命令启动Redis。喜欢:
# /etc/init.d/redis start
要么
/usr/local/bin/redis-server /etc/redis/config.conf
这是我的 redis.service 文件,我将其放入 /lib/systemd/system
:
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
Type=forking
PIDFILE=/var/run/redis_6379.pid
ExecStart=/etc/init.d/redis start
ExecStop=/etc/init.d/redis stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
但是当我使用命令systemctl start redis
启动redis服务器时。我什么都没有。
我尝试使用 systemctl status redis
读取 systemctl 日志,它向我显示了这些消息:
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Active: active (exited) since Fri 2018-08-31 15:45:37 CST; 2 days ago
Aug 31 15:45:37 redisserver001 systemd[1]: Starting LSB: start and stop redis_6379...
Aug 31 15:45:37 redisserver001 systemd[1]: Started LSB: start and stop redis_6379.
Aug 31 15:45:37 redisserver001 redis[24755]: /var/run/redis_6379.pid exists, process is already running or crashed
Sep 03 10:31:21 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:6] Unknown lvalue 'PIDFILE' in section 'Service'
Sep 03 10:33:13 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:6] Unknown lvalue 'PIDFILE' in section 'Service'
Sep 03 10:45:32 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:7] Unknown lvalue 'PIDFILE' in section 'Service'
Sep 03 11:08:28 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:7] Unknown lvalue 'PIDFILE' in section 'Service'
以下各项是我认为可能影响redis的关键配置运行。但我不知道我在哪里犯了错误。请帮忙。非常感谢。
pidfile /var/run/redis_6379.pid
daemonize yes
supervised systemd
如果应用程序在服务文件中指定了"pidfile" 属性,那么应用程序有责任在服务初始化完成之前将主进程的pid写入该文件.您需要确保您的应用程序正在这样做。 Systemd 将读取此值,并且如果用户执行 "systemctl start " 并且 pid 文件已经存在,将阻止创建另一个分叉进程。从您发布的输出来看,systemd 似乎认为 redis 进程已经 运行(因为存在 pid 文件,并且不会创建新进程)。您可以在服务文件的 "ExecStartPost" 子句中设置 pid。类似于:
ExecStartPost=/bin/sh -c 'umask 022; pgrep YOURSERVICE > /var/run/YOURSERVICE.pid'
选项必须是PIDFile
(区分大小写)。来自手册页 man systemd.service
PIDFile=
Takes a path referring to the PID file of the service. Usage of this option is recommended for
services where Type= is set to forking. The path specified typically points to a file below /run/. If
a relative path is specified it is hence prefixed with /run/. The service manager will read the PID
of the main process of the service from this file after start-up of the service. The service manager
will not write to the file configured here, although it will remove the file after the service has
shut down if it still exists. The PID file does not need to be owned by a privileged user, but if it
is owned by an unprivileged user additional safety restrictions are enforced: the file may not be a
symlink to a file owned by a different user (neither directly nor indirectly), and the PID file must
refer to a process already belonging to the service.
我在 CentOS7 上使用 systemctl 启动 Redis 时遇到了一些问题。我应该如何解决问题?
我可以使用普通命令启动Redis。喜欢:
# /etc/init.d/redis start
要么
/usr/local/bin/redis-server /etc/redis/config.conf
这是我的 redis.service 文件,我将其放入 /lib/systemd/system
:
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
Type=forking
PIDFILE=/var/run/redis_6379.pid
ExecStart=/etc/init.d/redis start
ExecStop=/etc/init.d/redis stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
但是当我使用命令systemctl start redis
启动redis服务器时。我什么都没有。
我尝试使用 systemctl status redis
读取 systemctl 日志,它向我显示了这些消息:
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Active: active (exited) since Fri 2018-08-31 15:45:37 CST; 2 days ago
Aug 31 15:45:37 redisserver001 systemd[1]: Starting LSB: start and stop redis_6379...
Aug 31 15:45:37 redisserver001 systemd[1]: Started LSB: start and stop redis_6379.
Aug 31 15:45:37 redisserver001 redis[24755]: /var/run/redis_6379.pid exists, process is already running or crashed
Sep 03 10:31:21 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:6] Unknown lvalue 'PIDFILE' in section 'Service'
Sep 03 10:33:13 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:6] Unknown lvalue 'PIDFILE' in section 'Service'
Sep 03 10:45:32 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:7] Unknown lvalue 'PIDFILE' in section 'Service'
Sep 03 11:08:28 redisserver001 systemd[1]: [/usr/lib/systemd/system/redis.service:7] Unknown lvalue 'PIDFILE' in section 'Service'
以下各项是我认为可能影响redis的关键配置运行。但我不知道我在哪里犯了错误。请帮忙。非常感谢。
pidfile /var/run/redis_6379.pid
daemonize yes
supervised systemd
如果应用程序在服务文件中指定了"pidfile" 属性,那么应用程序有责任在服务初始化完成之前将主进程的pid写入该文件.您需要确保您的应用程序正在这样做。 Systemd 将读取此值,并且如果用户执行 "systemctl start " 并且 pid 文件已经存在,将阻止创建另一个分叉进程。从您发布的输出来看,systemd 似乎认为 redis 进程已经 运行(因为存在 pid 文件,并且不会创建新进程)。您可以在服务文件的 "ExecStartPost" 子句中设置 pid。类似于:
ExecStartPost=/bin/sh -c 'umask 022; pgrep YOURSERVICE > /var/run/YOURSERVICE.pid'
选项必须是PIDFile
(区分大小写)。来自手册页 man systemd.service
PIDFile=
Takes a path referring to the PID file of the service. Usage of this option is recommended for
services where Type= is set to forking. The path specified typically points to a file below /run/. If
a relative path is specified it is hence prefixed with /run/. The service manager will read the PID
of the main process of the service from this file after start-up of the service. The service manager
will not write to the file configured here, although it will remove the file after the service has
shut down if it still exists. The PID file does not need to be owned by a privileged user, but if it
is owned by an unprivileged user additional safety restrictions are enforced: the file may not be a
symlink to a file owned by a different user (neither directly nor indirectly), and the PID file must
refer to a process already belonging to the service.