ntpdate

鸡汤: 过往不恋,未来不迎,当下不负,如此安好。

1. 介绍

1.1 NTP 简介

  Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步

1.2 ntp和ntpdate区别

  • ① 两个服务都是centos自带的(centos7中不自带ntp)。ntp的安装包名是ntp,ntpdate的安装包是ntpdate。他们并非由一个安装包提供。
  • ② ntp守护进程为ntpd,配置文件是/etc/ntp.conf
  • ③ ntpdate用于客户端的时间矫正,非NTP服务器可以不启动NTP。

本章节介绍简单ntpdate使用,因为只要机器能上网,就可以单独每个机器配置ntpdate直接去通过时间。

2. 部署

  ntpdate最大的亮点就是,ntpdate是客户端,直接crontab定时去同步时间即可。

2.1 安装

[root@slave2 ~]# yum install ntpdate -y

2.2 配置

[root@slave2 ~]# echo "*/5 * * * *  /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null 2>&1" >> /var/spool/cron/root
[root@slave2 ~]# crontab -l
*/5 * * * *  /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null 2>&1

2.3 ntp常用服务器

中国国家授时中心:210.72.145.44

NTP服务器(上海) :ntp.api.bz

若是同步有问题可以使用-u ntpdate -u ntp.api.bz

Name IP Location
210.72.145.44 210.72.145.44 中国(国家授时中心)
133.100.11.8 133.100.11.8 日本(福冈大学)
time-a.nist.gov 129.6.15.28 NIST,Gaithersburg,Maryland
time-b.nist.gov 129.6.15.29 NIST,Gaithersburg,Maryland
time-a.timefreq.bldrdoc.gov 132.163.4.101 NIST,Boulder,Colorado
time-b.timefreq.bldrdoc.gov 132.163.4.102 NIST,Boulder,Colorado
time-c.timefreq.bldrdoc.gov 132.163.4.103 NIST,Boulder,Colorado
utcnist.colorado.edu 128.138.140.44 UniversityofColorado,Boulder
time.nist.gov 192.43.244.18 NCAR,Boulder,Colorado
time-nw.nist.gov 131.107.1.10 Microsoft,Redmond,Washington
nist1.symmetricom.com 69.25.96.13 Symmetricom,SanJose,California
nist1-dc.glassey.com 216.200.93.8 Abovenet,Virginia
nist1-ny.glassey.com 208.184.49.9 Abovenet,NewYorkCity
nist1-sj.glassey.com 207.126.98.204 Abovenet,SanJose,California
nist1.aol-ca.truetime.com 207.200.81.113 TrueTime,AOLfacility,Sunnyvale,California
nist1.aol-va.truetime.com 64.236.96.53 TrueTime,AOLfacility,Virginia