重启redis需要很长时间

时间:2017-05-24 09:53:35

标签: python django redis celery

我在我的django项目中使用redis作为芹菜的经纪人。作为我的部署过程的一部分,我在最后重新启动服务,所以redis,celery,gunicorn(django)等以redis开头。但是我遇到了redis不会关闭的问题。

$ sudo systemctl restart redis
$ 

在写作15分钟的时候,它就会挂起。 journalctl显示没有条目(我假设日志已经过夜),systemctl status将redis单位显示为停用(sig-term)但没有显示它正在做什么,除了:

May 24 10:31:22 staging systemd[1]: Stopping Advanced key-value store...
May 24 10:31:22 staging run-parts[305]: run-parts: executing /etc/redis/redis-server.pre-down.d/00_example

我知道sig-term允许redis优雅地退出,所以想知道芹菜是否击败了任务或django服务器是否正在访问它,但是停止了这些服务它仍然挂起。是否有任何地方我不知道我可以在哪里查看状态/它在做什么?

编辑:啊哈,好吧事实证明redis并没有默认情况下实际登录到systemd,而是记录到/var/log/redis实际上会产生一些信息:

31602:M 24 May 10:59:56.097 * 1 changes in 900 seconds. Saving...
31602:M 24 May 10:59:56.101 * Background saving started by pid 1151
1151:C 24 May 10:59:56.103 # Failed opening .rdb for saving: Read-only file system
31602:M 24 May 10:59:56.204 # Background saving error

我使用dirdbfilename指令的默认值

# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

user@server:/var/lib/redis$ ls -l
total 252
-rw-r--r--  1 redis redis 249649 May 23 02:44 dump.rdb

它由redis拥有..为什么它会被设置为只读?

好的......所以

user@server:/var/lib/redis$ redis-cli config get dir
1) "dir"
2) "/var/spool/cron"
user@server:/var/lib/redis$ redis-cli config get dbfilename
1) "dbfilename"
2) "root"

这开始显得很奇怪。到底是什么原因可以解决这个问题?

1 个答案:

答案 0 :(得分:0)

它开始变得越来越像这是攻击的结果:https://github.com/antirez/redis/issues/3594

有趣的是,我在防火墙后面运行redis。目前还不确定配置是如何更改的。幸运的是,它是一个没有敏感信息的临时服务器,因此我可以将其删除,直到我确切地知道问题是什么。

更新:所以在进一步调查之后,我可以确定的是,在服务器上安装redis之后但在防火墙被激活之前,攻击必须在某个时刻发生。我使用的redis版本默认绑定到0.0.0.0。我使用部署脚本来设置服务器,因此漏洞时间必须为~10秒。经验教训,在安装软件包之前激活防火墙。

我会说我不喜欢redis绑定到0.0.0.0默认情况下,特别是当它暴露时能够完全破坏你的服务器。但根据我所读到的,已经对死亡进行了论证,并且在以后的版本中情况有所改善。