在使用systemctl在CentOS7上启动Redis时遇到一些麻烦。我应该怎么做才能排除故障?
我可以使用普通命令启动Redis。喜欢:
# /etc/init.d/redis start
要么
/usr/local/bin/redis-server /etc/redis/config.conf
这是我放入/lib/systemd/system
的redis.service文件:
[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
答案 0 :(得分:0)
如果应用程序在服务文件中指定“ pidfile”属性,则在服务初始化完成之前,应用程序负责将主进程的pid写入该文件。您需要确保您的应用程序正在执行此操作。 Systemd将读取该值,并且如果用户执行“ systemctl start”并且pid文件已存在,则将阻止创建另一个分支进程。从您发布的输出中,似乎systemd认为redis进程已经在运行(由于pid文件的存在,并且没有创建新的进程)。您可以在服务文件的“ ExecStartPost”子句中设置pid。像这样:
ExecStartPost=/bin/sh -c 'umask 022; pgrep YOURSERVICE > /var/run/YOURSERVICE.pid'
答案 1 :(得分:0)
选项必须为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.