
运维服务
docker离线安装
一、准备工作:确认架构并下载安装包 1.1 确认目标服务器架构 在目标服务器上执行以下命令,确认系统架构: 输出 x8664:对应 amd64 架构(Intel/AMD 64位服务
[root@wulaoer ~]# systemctl stop crond #关闭crond服务 [root@wulaoer ~]# systemctl start crond #开启crond服务 [root@wulaoer ~]# systemctl restart crond #重启crond服务 [root@wulaoer ~]# systemctl reload crond #热加载crond服务 [root@wulaoer ~]# systemctl status crond #查看crond服务状态 ● crond.service - Command Scheduler Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled) Active: active (running) since 一 2020-01-13 10:24:50 CST; 19s ago Process: 14010 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS) Main PID: 14002 (crond) CGroup: /system.slice/crond.service └─14002 /usr/sbin/crond -n 1月 13 10:24:50 wulaoer systemd[1]: Stopped Command Scheduler. 1月 13 10:24:50 wulaoer systemd[1]: Started Command Scheduler. 1月 13 10:24:50 wulaoer crond[14002]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 46% if used.) 1月 13 10:24:50 wulaoer crond[14002]: (CRON) INFO (running with inotify support) 1月 13 10:24:50 wulaoer crond[14002]: (CRON) INFO (@reboot jobs will be run at computer's startup.) 1月 13 10:25:01 wulaoer systemd[1]: Reloading Command Scheduler. 1月 13 10:25:01 wulaoer crond[14002]: (CRON) INFO (running with inotify support) 1月 13 10:25:01 wulaoer systemd[1]: Reloaded Command Scheduler.我们一般在操作定时任务时,不会管理是哪个文件,直接在crond里添加,下面说一下crond的定义方法:
[root@wulaoer ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) #以分钟为单位,最小单位是秒,如果想使用秒定义可以使用(*/定义的秒数) # | .------------- hour (0 - 23) #以小时为单位,最小单位是分钟,如果想在每天的几个时间段执行可以使用","连接 # | | .---------- day of month (1 - 31) #以月为单位,最小单位是天 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...#以年为单位,最小单位是月 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat #以周为单位,最小单位是星期几 # | | | | | # * * * * * user-name command to be executed下面我们根据上面的几个定时时间举个例子: 每天早上六点执行
0 6 * * * echo "hello, wulaoer." >> /tmp/test.txt每隔两个小时执行
0 */2 * * * echo "hello, wulaoer." >> /tmp/test.txt每晚11点到第二天早上8点之间,每两个小时和早上8点执行
0 23-7/2,8 * * * echo "hello, wulaoer." >> /tmp/test.txt每个月的4号和每周的周一到周三的早上11点
0 11 4 * 1-3 echo "hello, wulaoer." >> /tmp/test.txt1月1日早上4点
0 4 1 1 * echo "hello, wulaoer." >> /tmp/test.txt每天早上四点零二执行/opt/sh/log.sh
02 4 * * * bash /opt/sh/log.sh每星期执行/opt/sh/logs.sh
22 4 * * 0 bash /opt/sh/log.sh每天下午4点,5点,6点的5分,15分,25分,35分,45分,55分执行
5,15,25,35,45,55 16,17,18 * * * echo "hello, wulaoer." >> /tmp/test.txt每周一,三,五的下午三点重启系统
00 15 * * 1,3,5 shutdown -r +5每小时的10分,40分执行
10,40 * * * * echo "hello, wulaoer." >> /tmp/test.txt每小时的1分在执行
1 * * * * echo "hello, wulaoer." >> /tmp/test.txt每天早晨三点二十执行
20 3 * * * echo "hello, wulaoer." >> /tmp/test.txt每年的一月,四月,4号到9号的3点12和3点55执行
12,55 3 4-9 1,4 * echo "hello, wulaoer." >> /tmp/test.txt上面是添加的语句,下面说一下添加的方法,我们一般是在
[root@wulaoer ~]# crontab -e和使用vim命令一样直接把上面的定时任务添加进去即可,最后要reload一下,或者重启一下。
评论 0