diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 2795694..600b974 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -52,6 +52,7 @@ export default defineConfig({ items: [ { text: 'WebSocket', link: '/knowledge/ws' }, { text: 'SSE', link: '/knowledge/sse' }, + { text: '定时任务', link: '/knowledge/cron' }, ], }, ], diff --git a/docs/function/deploy+ssl.md b/docs/function/deploy+ssl.md index 43b7bf8..8e69c09 100644 --- a/docs/function/deploy+ssl.md +++ b/docs/function/deploy+ssl.md @@ -134,6 +134,8 @@ Congratulations, all renewals succeeded. The following certs have been renewed: 测试自动更新时他是需要80端口空出来的,如果当前nginx还占着80端口记得先把nginx关闭,测试完再重新启动nginx。 +或者在nginx配置上开放自动更新的 + ## 5.重新部署 @@ -168,4 +170,3 @@ Congratulations, all renewals succeeded. The following certs have been renewed: 重新启动后端 不过后端一般还包括mysql,mysql可以使用sql文件进行导入数据和表 - diff --git a/docs/knowledge/cron.md b/docs/knowledge/cron.md new file mode 100644 index 0000000..9064933 --- /dev/null +++ b/docs/knowledge/cron.md @@ -0,0 +1,75 @@ +# 定时任务设定 + +## 分情况使用 + +### 1.后端使用 + +`springboot`自带`@Scheduled`注解,就是用来执行定时任务的,根据传入的cron表达式定时执行添加注解的函数。 + +### 2.Linux服务器使用 + +在linux上使用`crontab`来执行定时任务。 + +查看当前Linux系统中的定时任务 +```shell +crontab -l +``` + +编辑当前Linux系统中的定时任务 +```shell +crontab -e +``` + +一般定时任务设定格式: + +`[cron表达式]` + `[用户身份]` + `[执行命令]` + +示例:0 0,12 * * * sudo -u root /sbin/hwclock --hctosys(每天0点与12点使用root用户执行系统时间与硬件时间同步任务) + +## Cron表达式 + +cron 表达式是一个字符串,该字符串由 6 个空格分为 7 个域,每一个域代表一个时间含义。 格式如下: + +``` +[秒] [分] [时] [日] [月] [周] [年] +``` +通常定义 “年” 的部分可以省略,实际常用的由 前六部分组成 + +### Cron 的各个域的定义 + +| 域 | 是否必填 | 值以及范围 | 通配符 | +| ----------- | ----------- | ----------- | ----------- | +| 秒 | 是 |0-59 | , - * / | +| 分 | 是 |0-59 | , - * / | +| 时 | 是 |0-23 | , - * / | +| 日 | 是 |1-31 | , - * ? / L W | +| 月 | 是 |1-12 或 JAN-DEC | , - * / | +| 周 | 是 |1-7 或 SUN-SAT | , - * ? / L # | +| 年 | 否 |1970-2099 | , - * / | + + +数字:表示对应的时间点值(如1表示1点) + +星号(*):表示该字段的所有可能值,如分钟字段中的星号表示每分钟的任何时间点 + +逗号(,):用于分割字段中的多个取值,如“2,5,10”表示取值为2、5、10的时间点 + +连接符(-):用于指定时间段,如“1-5”表示取值范围为1到5的所有时间点 + +斜杠(/):用于指定时间步长,如“*/10”表示每隔10个时间点执行一次任务 + + + +### 示例 + +每隔1分钟执行一次:`0 */1 * * * ?` + +每天22点执行一次:`0 0 22 * * ?` + +每月1号凌晨1点执行一次:`0 0 1 1 * ?` + +每月最后一天23点执行一次:`0 0 23 L * ?` + +每周周六凌晨3点实行一次:`0 0 3 ? * L` + +在24分、30分执行一次:`0 24,30 * * * ?`