为什么有的时候开机,redis没有自动起来呢?

浏览:36日期:2022-09-02

问题描述

不常见,但有的时候开机redis没有自个启动,不知道如何查找原因,请高人指点

$ redis-cliCould not connect to Redis at 127.0.0.1:6379: Connection refused

我看了下日至,如下

[207] 29 Sep 18:22:41.020 * 1 changes in 900 seconds. Saving...[207] 29 Sep 18:22:41.099 * Background saving started by pid 2473[2473] 29 Sep 18:22:41.685 * DB saved on disk[207] 29 Sep 18:22:42.014 * Background saving terminated with success[207 | signal handler] (1380450274) Received SIGTERM, scheduling shutdown...[207] 29 Sep 18:24:34.759 # User requested shutdown...[207 | signal handler] (1380450274) Received SIGTERM, scheduling shutdown...[207] 29 Sep 18:24:34.899 * Saving the final RDB snapshot before exiting.[207] 29 Sep 18:24:35.050 * DB saved on disk[207] 29 Sep 18:24:35.050 * Removing the pid file.[207] 29 Sep 18:24:35.150 # Redis is now ready to exit, bye bye...[620] 29 Sep 21:50:35.953 * Max number of open files set to 10032_._ _.-``__ ’’-._ _.-`` `. `_. ’’-._ Redis 2.6.14 (00000000/0) 64 bit .-`` .-". "/ _.,_ ’’-._ ( ’ , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|’` _.-’| Port: 6379 | `-._ `._ / _.-’ | PID: 620 `-._ `-._ `-./ _.-’ _.-’ |`-._`-._ `-.__.-’ _.-’_.-’| | `-._`-.__.-’_.-’ | http://redis.io `-._ `-._`-.__.-’_.-’ _.-’ |`-._`-._ `-.__.-’ _.-’_.-’| | `-._`-.__.-’_.-’ | `-._ `-._`-.__.-’_.-’ _.-’ `-._ `-.__.-’ _.-’ `-.__.-’ `-.__.-’[620] 29 Sep 21:50:35.971 # Server started, Redis version 2.6.14[620] 29 Sep 21:50:35.984 * DB loaded from disk: 0.013 seconds[620] 29 Sep 21:50:35.984 * The server is now ready to accept connections on port 6379

好像也没有异常,上面提到的

[207] 29 Sep 18:24:35.050 * Removing the pid file.

因该是我关机的缘故,pid删除了,一般的情况下,开机会自动启动pid的,但是这次没有,上面启动界面是我最有一次手动启动的log信息

问题解答

回答1:

redis在启动的时候会为信号SIGTERM注册信号处理函数,该函数会让redis在结束运行之前做些资源清理工作,譬如保存RDB文件,删除PID文件(如果redis是以daemon方式运行)等等,当这些工作都做完后,调用exit函数退出

所以日志这段内容:

[207 | signal handler] (1380450274) Received SIGTERM, scheduling shutdown...[207] 29 Sep 18:24:34.759 # User requested shutdown...[207 | signal handler] (1380450274) Received SIGTERM, scheduling shutdown...[207] 29 Sep 18:24:34.899 * Saving the final RDB snapshot before exiting.[207] 29 Sep 18:24:35.050 * DB saved on disk[207] 29 Sep 18:24:35.050 * Removing the pid file.[207] 29 Sep 18:24:35.150 # Redis is now ready to exit, bye bye.

都是符合上述我说的流程,收到SIGTERM信号 -> 处理资源 -> 结束redis服务

但是后面这些日志,看时间应该和上面的不是同一个:

[620] 29 Sep 21:50:35.953 * Max number of open files set to 10032

所以我觉得问题的关键是为什么在Redis启动的时候会收到一个SIGTERM信号?

相关文章: