1、原理
内网的所有服务器都和时钟服务器进行同步时间
2、如何同步
(1)查看本机当前时间
date
(2)设置本机当前时间
date -s "2018-08-17 20:08:09"
(3)通过命名和时钟服务器同步时间:
网络计时协议(NTP) : net time protocal
ntpdate us.pool.ntp.org
如果提示找不到此命令,则证明你的电脑未安装ntpdate,执行下面命令进行安装
yum install -y ntpdate
(4)编辑定时任务
crontab -e
定时任务内容如下
*/1 * * * * /usr/sbin/ntpdate us.pool.ntp.org;
每隔1分钟执行指令一次
Crontab使用
- 格式说明
# 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
- 使用实例
实例1:每1分钟执行一次command 命令:* * * * * command 实例2:每小时的第3和第15分钟执行 命令:3,15 * * * * command 实例3:在上午8点到11点的第3和第15分钟执行 命令:3,15 8-11 * * * command 实例4:每隔两天的上午8点到11点的第3和第15分钟执行 命令:3,15 8-11 */2 * * command 实例5:每个星期一的上午8点到11点的第3和第15分钟执行 命令:3,15 8-11 * * 1 command
Crantab在线生成网址:在线Cron表达式生成器