Linux ntp ntpdate

简介

ntpdate指令通过轮询指定为服务器参数的网络时间协议(NTP)服务器来设置本地日期和时间,从而确定正确的时间。此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、Fedora。

安装

1. 中国NTP服务器

http://www.ntp.org.cn/pool

2. 安装ntp、ntpdate

yum install -y ntp
yum install -y ntpdate

3. 配置ntp

# 编辑NTP配置文件
vim /etc/ntp.conf

# 注释配置文件中原有的NTP服务器,并在其中添加自己所需的NTP服务器地址
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
server cn.ntp.org.cn iburst

4. 配置自启服务

systemctl enable ntpd.service

5. 启动ntp

systemctl start ntpd

6. 检查ntp运行状态

systemctl status ntpd
ntpstat
watch ntpq -p

7. 同步网络时间

# 中国
ntpdate -u cn.ntp.org.cn
# 中国教育网
ntpdate -u edu.ntp.org.cn
# 阿里云
ntpdate -u 120.25.108.11
ntpdate -u 182.92.12.11
ntpdate -u 203.107.6.88
ntpdate -u 120.25.115.20
ntpdate -u ntp1.aliyun.com
# 中国香港
ntpdate -u hk.ntp.org.cn
# 中国台湾
ntpdate -u tw.ntp.org.cn
posted @ 2022-05-22 15:20  逢生博客  阅读(669)  评论(0)    收藏  举报