「Cron(定时运行守护进程)」:修訂間差異
Yucheng Hu(留言 | 貢獻) 無編輯摘要 |
Yucheng Hu(留言 | 貢獻) |
||
(未顯示同一使用者於中間所作的 8 次修訂) | |||
第1行: | 第1行: | ||
{{Installing Moodle}} | {{Installing Moodle}} | ||
Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个 | Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个 进程 必须定时在后台运行。 | ||
Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。 | Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。 | ||
第16行: | 第16行: | ||
== 基本讨论 == | == 基本讨论 == | ||
针对你使用的操作系统,请对应查看你后面的内容,这部分仅仅讨论一些的基本背景信息。 | |||
使用下面 2 步可以对守护进程进行一些有效的配置: | |||
# | # 确定运行的正确命令行 | ||
# | # 在你的操作系统中找到正确的位置来存放这个命令 | ||
=== | === 配置 Moodle cron 命令行工作 === | ||
Moodle | Moodle 可以使用2 个不同的方法来在你的系统中部署定时运行脚本。 | ||
下面是相关内容: | |||
# 命令行脚本:命令行脚本在路径<pre>/path/to/moodle/admin/cli/cron.php</pre>如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:<pre>/usr/bin/php /path/to/moodle/admin/cli/cron.php</pre>你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。 | |||
# 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:'''http://your.moodle.site/admin/cron.php'''。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:<pre>/usr/bin/wget http://your.moodle.site/admin/cron.php</pre>这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。 | |||
=== | === 找到放置你定时运行命令行的正确路径 === | ||
找到定时任务的放置路径和你使用的操作系统有很大的关系,请参考你的操作系统文档和主机文档。 | |||
一般来说如果成功配置 Moodle 的定时任务正确运行,你需要考虑你的命令是否正确,然后将命令放置到正确的位置,希望运行任务的正确时间和一些文件。 | |||
在进行修改的时候,你可能会有用户界面来进行编辑配置,也可能没有用户界面编辑配置,你需要使用字符环境来进行配置。 | |||
'' | 如果你使用命令行的方式来运行你的计划任务,你需要考虑用户的权限,用户是否具有正确的权限来运行这个命令,对于采用 Web 来运行的话,就没有用户权限的问题。 | ||
例如,在 Ubuntu/Debian Linux 系统中进行安装,你使用的是 root 用户。 | |||
'' 为 www-data 用户使用 crontab 命令来打开一个 crontab 命令编辑窗口。这是应为 Apache (Web 服务器)使用这个用户来在 Debian 系统中运行'' | |||
<pre> | <pre> | ||
$ crontab -u www-data -e | $ crontab -u www-data -e | ||
</pre> | </pre> | ||
'' | '' 这个将会打开一个编辑窗口。如果希望每15分钟来运行一次命令,请添加下面的内容:'' | ||
<pre> | <pre> | ||
*/15 * * * * /usr/bin/php /path/to/moodle/admin/cli/cron.php >/dev/null | */15 * * * * /usr/bin/php /path/to/moodle/admin/cli/cron.php >/dev/null | ||
</pre> | </pre> | ||
注意:命令的最后 '''>/dev/null''' 将所有命令的输出发送到'bin' 目录,同时阻止你每 15 分钟获得一个电子邮件。 | |||
== | == 在你的系统中设置 Moodle Cron == | ||
为你的服务器选择正确的信息: | |||
*[[ | *[[Moodle Unix 或者 Linux 的 Cron]] - 基于 UNIX 和 Linux 的定时运行任务服务配置。 | ||
*[[Cron with Windows OS]] - | *[[Cron with Windows OS]] - Windows 的定时运行任务。 | ||
*''Apple OSX'' - | *''Apple OSX'' - 内建的 'crontab' 服务与 [[Moodle Unix 或者 Linux 的 Cron]] 完全一致。但是,你可能需要遵守 'Apple 的特定运行方式' 来运行,请查看[[Cron with MAC OS X]] 。 | ||
*[[Cron with web hosting services]]- | *[[Cron with web hosting services]] - 一系列的虚拟主机定时运行任务。 | ||
下面是一些特定主机的特定指南,请在使用之前确定这些信息是最新的版本,否则可能会导致配置错误: | |||
*[[Cron on 1and1 shared servers]] | *[[Cron on 1and1 shared servers]] | ||
== | == 使用第三方 cron 服务 == | ||
除了可以使用你自己服务器的 cron 服务之外,你还可以使用第三方的 crone 服务,这个服务可以通过调用 webcron 来实现: | |||
*[http://www.easycron.com EasyCron] - 一个 webcron 服务提供商,通常用户实现 crontab 或者其他需要定时运行的任务。 | |||
=== Moodle 的 cron 设置=== | |||
在 Moodle 中有一些设置来控制 cron 的操作: | |||
*[ | *[[Cron settings]] - Moodle cron 处理密码和命令脚本设置。 | ||
=== | === 远程 cron=== | ||
使用 '基于 web' 的 cron 版本,对于需要执行的 cron 任务放置到不同的机器上进行调用非常有效。 | |||
例如,调用 cron 定时任务的服务器是在 Unix 机器上可以调用 Moodle 的 web 页面,但是你的 Moodle 是部署在 Windows 服务器上的。 | |||
通过远程 cron 调用,我们可以实现跨平台的调用方式。 | |||
== | == 请参考== | ||
* [http://en.wikipedia.org/wiki/Cron | * [http://en.wikipedia.org/wiki/Cron 维基百科中有关 cron 的介绍] | ||
使用 Moodle 论坛中有关的讨论: | |||
*[http://moodle.org/mod/forum/discuss.php?d=41827 Cron - can someone give me a quick confirmation of function?] | *[http://moodle.org/mod/forum/discuss.php?d=41827 Cron - can someone give me a quick confirmation of function?] | ||
*[http://moodle.org/mod/forum/discuss.php?d=97684 Cronjob Question] | *[http://moodle.org/mod/forum/discuss.php?d=97684 Cronjob Question] | ||
*[http://moodle.org/mod/forum/discuss.php?d=97457 Slow cron : avoiding simultaneous cron] | *[http://moodle.org/mod/forum/discuss.php?d=97457 Slow cron : avoiding simultaneous cron] | ||
*[http://moodle.org/mod/forum/discuss.php?d=117168 Visibility of cron.php] | *[http://moodle.org/mod/forum/discuss.php?d=117168 Visibility of cron.php] | ||
*[http://moodle.org/mod/forum/discuss.php?d=139263#p609060 How to log the output of a Scheduled Task on Windows] - | *[http://moodle.org/mod/forum/discuss.php?d=139263#p609060 How to log the output of a Scheduled Task on Windows] - 这个讨论解释了一个非常有用的小技巧,这个小技巧在你使用 Windows 的计划任务时,你希望 log 程序输出非常有效。 | ||
*[http://www.ossez.com/forum-54-1.html OSS 计算技术有关 Moodle 功能的讨论社区] | |||
[[es:Cron]] | [[es:Cron]] | ||
[[fr:Cron]] | [[fr:Cron]] | ||
[[ja:Cron]] | [[ja:Cron]] |
於 2013年8月24日 (六) 14:38 的最新修訂
Moodle 'cron' 守護進程是一個 PHP 的腳本,這個腳本是 Moodle 安裝的一部分,這個進程必須定時在後台運行。
Moodle cron 守護進程腳本運行不同的任務同時被計劃進行內部調度。
重要:不要嘗試忽略在你的 Moodle 站點中設置Cron(定時運行守護進程)。沒有這個守護進程,你的站點將不會完全正常工作。
一個特殊的程序(通常稱為'cron')被用來定時運行 Moodle 腳本。Moodle 的定時運行腳本可以運行發送郵件,更新 Moodle 報表,RSS,完成活動,發布論壇消息和其他任務。因為不同的任務在 Moodle 系統中不是同時運行的,換句話說,這些任務不是同時被觸發的,而是分時被觸發的。
定時任務(運行 Moodle 腳本)是基於 Unix 系統的核心組件,這作業系統包括(Linux 和 OSX)。定時任務使用者管理所有基於時間的服務。在 Widows 中,也有類似的功能,這個功能在 Windows 中被稱為 Windows 任務計劃,這個被設置用來按照時間計劃來運行。
如果你使用的是共享主機服務,你可以諮詢你的服務管理員或者相關文檔來配置定時任務。
實際上,計劃任務包含當個命令行,這個命令行通常設置在系統中的 cron 激活列表中。在基於 Unix 的作業系統中,這個配置文件被配置在'crontab'中。
基本討論
針對你使用的作業系統,請對應查看你後面的內容,這部分僅僅討論一些的基本背景信息。
使用下面 2 步可以對守護進程進行一些有效的配置:
- 確定運行的正確命令行
- 在你的作業系統中找到正確的位置來存放這個命令
配置 Moodle cron 命令行工作
Moodle 可以使用2 個不同的方法來在你的系統中部署定時運行腳本。
下面是相關內容:
- 命令行腳本:命令行腳本在路徑
/path/to/moodle/admin/cli/cron.php
如果你有所懷疑這個是不是正確的運行腳本。需要在你的系統中運行 'PHP CLI'程序。所以最終的運行腳本如下:/usr/bin/php /path/to/moodle/admin/cli/cron.php
你應該在你的機器上嘗試運行這個腳本命令來確定這個命令能正常運行。 - 基於 WEB 的腳本。這個命令需要從瀏覽器上來運行,你需要從瀏覽器上來訪問,訪問的地址和下面的的類似:http://your.moodle.site/admin/cron.php。你可以使用一些類似瀏覽器的命令(例如:wget)。最終的命令如下所示:
/usr/bin/wget http://your.moodle.site/admin/cron.php
這種運行方式的好處在於你可以在*任何*地方運行。如果你不能在你的機器上運行計劃任務,這個將會是一個非常好的方法。
找到放置你定時運行命令行的正確路徑
找到定時任務的放置路徑和你使用的作業系統有很大的關係,請參考你的作業系統文檔和主機文檔。
一般來說如果成功配置 Moodle 的定時任務正確運行,你需要考慮你的命令是否正確,然後將命令放置到正確的位置,希望運行任務的正確時間和一些文件。
在進行修改的時候,你可能會有使用者界面來進行編輯配置,也可能沒有使用者界面編輯配置,你需要使用字符環境來進行配置。
如果你使用命令行的方式來運行你的計劃任務,你需要考慮使用者的權限,使用者是否具有正確的權限來運行這個命令,對於採用 Web 來運行的話,就沒有使用者權限的問題。
例如,在 Ubuntu/Debian Linux 系統中進行安裝,你使用的是 root 使用者。
為 www-data 使用者使用 crontab 命令來打開一個 crontab 命令編輯窗口。這是應為 Apache (Web 伺服器)使用這個使用者來在 Debian 系統中運行
$ crontab -u www-data -e
這個將會打開一個編輯窗口。如果希望每15分鐘來運行一次命令,請添加下面的內容:
*/15 * * * * /usr/bin/php /path/to/moodle/admin/cli/cron.php >/dev/null
注意:命令的最後 >/dev/null將所有命令的輸出發送到'bin'目錄,同時阻止你每 15 分鐘獲得一個電子郵件。
在你的系統中設置 Moodle Cron
為你的伺服器選擇正確的信息:
- Moodle Unix 或者 Linux 的 Cron - 基於 UNIX 和 Linux 的定時運行任務服務配置。
- Cron with Windows OS - Windows 的定時運行任務。
- Apple OSX - 內建的 'crontab' 服務與 Moodle Unix 或者 Linux 的 Cron 完全一致。但是,你可能需要遵守 'Apple 的特定運行方式'來運行,請查看Cron with MAC OS X。
- Cron with web hosting services - 一系列的虛擬主機定時運行任務。
下面是一些特定主機的特定指南,請在使用之前確定這些信息是最新的版本,否則可能會導致配置錯誤:
使用第三方 cron 服務
除了可以使用你自己伺服器的 cron 服務之外,你還可以使用第三方的 crone 服務,這個服務可以通過調用 webcron 來實現:
- EasyCron - 一個 webcron 服務提供商,通常使用者實現 crontab 或者其他需要定時運行的任務。
Moodle 的 cron 設置
在 Moodle 中有一些設置來控制 cron 的操作:
- Cron settings - Moodle cron 處理密碼和命令腳本設置。
遠程 cron
使用 '基於 web' 的 cron 版本,對於需要執行的 cron 任務放置到不同的機器上進行調用非常有效。
例如,調用 cron 定時任務的伺服器是在 Unix 機器上可以調用 Moodle 的 web 頁面,但是你的 Moodle 是部署在 Windows 伺服器上的。
通過遠程 cron 調用,我們可以實現跨平台的調用方式。
請參考
使用 Moodle 論壇中有關的討論:
- Cron - can someone give me a quick confirmation of function?
- Cronjob Question
- Slow cron : avoiding simultaneous cron
- Visibility of cron.php
- How to log the output of a Scheduled Task on Windows - 這個討論解釋了一個非常有用的小技巧,這個小技巧在你使用 Windows 的計劃任務時,你希望 log 程序輸出非常有效。
- OSS 計算技術有關 Moodle 功能的討論社區