首页 > 解决方案 > Cronjob wget 在不可预知的时间间隔内多次触发 http 请求

问题描述

我使用 wget 在 ubuntu 服务器中为 php 服务设置了 crons,并且每 5 分钟运行一次 crons。这几天效果很好。最近,我遇到了一个问题,即服务运行了两次或三次(根据应用程序日志的输出),但 cron 只运行了一次(根据 syslog)。

我已经完成了链接为什么这个 cron 条目执行了两次?但这对我不起作用。我只有一个 PID(ps -aux | grep 'cron'),我重新启动、停止、启动了 cron 服务(service cron restart/stop/start),但它们都不适合我。所以最后我重新启动了服务器,因为 cron 作业是 init 服务,但在重新启动后,我也遇到了同样的问题。

cron 以 root 用户身份运行。

克朗:

*/5 * * * * /usr/bin/wget --no-check-certificate  https://**********/controlller/method

从系统日志:

Jul 31 12:05:01 web-server CRON[26997]: (root) CMD (/usr/bin/wget --no-check-certificate  https://xx.xx.xx.xx/controller/method)
Jul 31 12:10:01 web-server CRON[27222]: (root) CMD (/usr/bin/wget --no-check-certificate  https://xx.xx.xx.xx/controller/method)
Jul 31 12:15:01 web-server CRON[27470]: (root) CMD (/usr/bin/wget --no-check-certificate  https://xx.xx.xx.xx/controller/method)
Jul 31 12:20:01 web-server CRON[27768]: (root) CMD (/usr/bin/wget --no-check-certificate  https://xx.xx.xx.xx/controller/method)

ps -aux | grep 'cron'
root      1079  0.0  0.0  26012   696 ?        Ss   Jul30   0:03 cron

从应用程序日志:

31 Jul 2019 12:05:01 [26836] DEBUG [xx.xx.xx.xx]:entered into controller/method
31 Jul 2019 12:05:01 [26922] DEBUG [xx.xx.xx.xx]:entered into controller/method
31 Jul 2019 12:13:00 [27378] DEBUG [xx.xx.xx.xx]:entered into controller/method
31 Jul 2019 12:13:01 [27376] DEBUG [xx.xx.xx.xx]:entered into controller/method
31 Jul 2019 12:23:47 [27733] DEBUG [xx.xx.xx.xx]:entered into controller/method
31 Jul 2019 12:23:47 [27674] DEBUG [xx.xx.xx.xx]:entered into controller/method

从 Apache2 访问日志:

xx.xx.xx.xx - - [31/Jul/2019:12:05:01 +0200] "GET /controller/method HTTP/1.1" 200 6914 "-" "Wget/1.15 (linux-gnu)"
xx.xx.xx.xx - - [31/Jul/2019:12:05:01 +0200] "GET /controller/method HTTP/1.1" 200 6909 "-" "Wget/1.15 (linux-gnu)"
xx.xx.xx.xx - - [31/Jul/2019:12:13:01 +0200] "GET /controller/method HTTP/1.1" 200 6862 "-" "Wget/1.15 (linux-gnu)"
xx.xx.xx.xx - - [31/Jul/2019:12:13:00 +0200] "GET /controller/method HTTP/1.1" 200 6862 "-" "Wget/1.15 (linux-gnu)"
xx.xx.xx.xx - - [31/Jul/2019:12:23:47 +0200] "GET /controller/method HTTP/1.1" 200 6862 "-" "Wget/1.15 (linux-gnu)"
xx.xx.xx.xx - - [31/Jul/2019:12:23:47 +0200] "GET /controller/method HTTP/1.1" 200 6862 "-" "Wget/1.15 (linux-gnu)"

标签: phpapachecronubuntu-14.04

解决方案


推荐阅读