1、NTP网络时间协议
Network Time Protocol
NTP服务器为客户机提供标准时间
NTP客户机需要与NTP服务器保持沟通
服务端: 提供相应功能的程序
软件包:chrony
配置文件:/etc/chrony.conf
系统服务:chronyd
案例:
客户端:访问服务端程序
1)安装客户端程序chrony
[root@server0 /]# rpm -q chrony
yum -y install chrony
2)配置chrony指定服务端位置,修改配置文件, 注释:解释文字,以#开头的行
[root@server0 /]# vim /etc/chrony.conf
3)重起客户端服务chronyd
[root@server0 /]# systemctl restart chronyd #重起服务
[root@server0 /]# systemctl enable chronyd #设置开机自起服务
4)验证时间同步
[root@server0 /]# date
[root@server0 /]# date -s "2000-9-9" #设置一个错误的时间
[root@server0 /]# systemctl restart chronyd
[root@server0 /]# date
[root@server0 ~]# date +%F
2017-12-08
2、cron计划任务概述
• 用途:按照设置的时间间隔为用户反复执行某一项固定的系统任务
• 软件包:cronie、crontabs
• 系统服务:crond
• 日志文件:/var/log/crond
格式:
时间 任务
分 时 日 月 周 命令或脚本程序
* * * * *
0 22 * * *
0 8 * * 1-5
* 匹配范围内任意时间
,分隔多个不连续的时间点
- 指定连续时间范围
/n 指定时间频率,每n ...
每分钟记录当前的系统时间,写入到/opt/time.txt
使用 crontab 命令
– 编辑:crontab -e [-u 用户名]
– 查看:crontab -l [-u 用户名]
– 清除:crontab -r [-u 用户名]
[root@server0 /]# date > /opt/time.txt
[root@server0 /]# cat /opt/time.txt
[root@server0 /]# crontab -e -u root
*/1 * * * * date >> /opt/time.txt
[root@server0 /]# watch -n 1 cat /opt/time.txt
#每一秒钟运行cat /opt/time.txt
NTP,cron计划任务
原文:https://www.cnblogs.com/cp-linux/p/13339749.html