使用supervisor启动Redis

13
当使用supervisor启动redis时,redis进程正在运行,但在supervisor中显示为“backoff”。
vagrant@jinming:~$ sudo supervisorctl -c /etc/conf/supervisor/supervisord.conf
redis                            BACKOFF   Exited too quickly (process log may have details)

在主管日志中,显示如下:

2015-06-09 07:09:28,407 CRIT Supervisor running as root (no user in config file)
2015-06-09 07:09:28,407 WARN Included extra file "/etc/conf/supervisor/conf.d/redis_local.conf" during parsing
2015-06-09 07:09:28,407 INFO RPC interface 'supervisor' initialized
2015-06-09 07:09:28,407 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2015-06-09 07:09:28,407 INFO supervisord started with pid 23191
2015-06-09 07:09:29,410 INFO spawned: 'redis' with pid 23332
2015-06-09 07:09:29,416 INFO exited: redis (exit status 0; not expected)
2015-06-09 07:09:30,418 INFO spawned: 'redis' with pid 23334
2015-06-09 07:09:30,425 INFO exited: redis (exit status 0; not expected)
2015-06-09 07:09:32,429 INFO spawned: 'redis' with pid 23336  
2015-06-09 07:09:32,434 INFO exited: redis (exit status 0; not expected)
2015-06-09 07:09:36,067 INFO spawned: 'redis' with pid 23342
2015-06-09 07:09:36,072 INFO exited: redis (exit status 0; not expected)
2015-06-09 07:09:37,073 INFO gave up: redis entered FATAL state, too many start retries too quickly
2015-06-09 07:11:04,079 CRIT Supervisor running as root (no user in config file)
2015-06-09 07:11:04,079 WARN Included extra file "/etc/conf/supervisor/conf.d/redis_local.conf" during parsing
2015-06-09 07:11:04,080 INFO RPC interface 'supervisor' initialized
2015-06-09 07:11:04,080 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2015-06-09 07:11:04,080 INFO supervisord started with pid 23191
2015-06-09 07:11:05,083 INFO spawned: 'redis' with pid 23486
2015-06-09 07:11:05,089 INFO exited: redis (exit status 0; not expected)

有人能帮我吗,谢谢。


2
我已经解决了,只需将daemonize设置为no,然后使用supervisor启动redis即可。 - zimmer
你好, 能告诉我你的 /etc/conf/supervisor/conf.d/redis_local.conf 配置是什么吗?我似乎无法将路径传递给 /etc/redis/redis.conf,以便可执行文件启动 Redis 并成功运行。谢谢! - eco
@einarc,这只是redis配置文件,您可以使用sudo启动supervisor并使用sudo启动redis,这可能会对您有所帮助。 - zimmer
我发现问题是由于redis.conf文件的配置问题导致redis二进制文件无法启动服务。一旦修复了这个问题,supervisor就能够正确地加载redis了。没有必要进行任何更改。谢谢! - eco
2个回答

13

当使用Supervisord管理像数据库这样经常生成或守护进程的服务器程序时,请查找启动命令或配置文件中的标志。对于像MySQL这样的数据库,有一个例外,建议使用代理来启动mysqld_safe并让其管理子进程。

在较新版本(即3.x)的redis.conf中,默认情况下禁用守护程序,但可能已被您的软件包编辑。还要确保您没有使用upstart脚本进行安装,因为它将重新生成。

Redis配置文件部分

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

示例Supervisor配置


我在下面的另一个解决方案中留下了评论,但值得在这里注意的是发生了一些奇怪的事情。没有指定配置文件,Redis将使用其默认配置。然而,这并没有使用默认的配置文件。默认配置规格为daemonize no,而默认配置文件(/etc/redis/redis.conf)规格为daemonize yes。我的想法是最好的解决方案是使用配置文件,但更新它以具有daemonize no - gerowam
请注意,此帖子已经五年了,事情可能已经发生了变化,但是您会看到“但它可能已被您的软件包编辑”,所以最好明确地设置为您所需的内容。;-) - Mike S.

6

问题

redis-server在以下的supervisord.conf配置文件下无法工作

特别是,使用配置文件位置参数的redis-server命令

redis-server --version

Redis server v=2.8.17 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=5b70b85861dcf95e

supervisord.conf

[program:redis-server]
command=redis-server /etc/redis/redis.conf # PLEASE NOTE THIS LINE
autostart=true
autorestart=true
user=root
stdout_logfile=/var/log/redis/stdout.log
stderr_logfile=/var/log/redis/stderr.log

my_redis.conf

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

Dockerfile

RUN cp -f my_redis.conf /etc/redis/redis.conf &&\

supervisorctl

supervisorctl状态

通过命令行进行测试

输入图像描述

解决方案

如果没有自定义的conf文件位置,一切都很顺利。

在我的情况下,我用my_redis.conf覆盖了默认的/etc/redis/redis.conf文件。

[program:redis-server]
command=redis-server # JUST REMOVE EXTRA CONF FILE LOCATION, EVERYTHING WORKS WELL
autostart=true
autorestart=true
user=root
stdout_logfile=/var/log/redis/stdout.log
stderr_logfile=/var/log/redis/stderr.log

PS. 这个 Redis 版本有 bug 吗?还是我的配置出了问题?


1
这里的情况是当Redis在没有配置文件的情况下启动时,它不会daemonize(即daemonize no)。但是,默认/包含的配置文件使其daemonize(即daemonize yes)。此解决方案将使用Redis的默认配置,而不是默认配置文件。更好的解决方案是保留配置文件的指定,并更新它以包括daemonize no - gerowam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接