CentOS使用NTP同步时间

bridge
2020-12-01 / 0 评论 / 0 点赞 / 523 阅读 / 526 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-01-19,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

安装NTP服务

1.安装

# 既可做服务端也可做客户端
yum install -y ntp

# 开启服务,让其他客户端与本机同步,注意防火墙状态
systemctl start ntpd

# 开机自启
systemctl enable ntpd

2.ntp 常用命令

# 查看ntp版本
ntpq -c version

# 上层 ntp 的状态
ntpq -p

# ntp 同步状态
ntpstat

# 向 NTP 服务器同步时间,需关闭 ntpd 服务,-u 指定使用无特权的端口发送数据包 -d 调试
ntpdate -u ntp.aliyun.com

3.系统时钟与硬件时钟之间同步

# 设置硬件时钟
hwclock -w

# 设置系统时钟
hwclock -s

4.定时同步

vim /etc/ntp/step-tickers;

#List of NTP servers used by the ntpdate service.
ntp.aliyun.com
time2.aliyun.com
ntp2.aliyun.com

#使用crond
systemctl start crond

systemctl enable crond

# 添加
crontab -e

# 每两个小时同步一次
0 */2 * * * ntpdate s2m.time.edu.cn && hwclock -w

# 查看
crontab –l
0

评论区