centos多台之间时间同步

1、描述

NTP:

来自百度百科:
NTP服务器【Network Time Protocol(NTP)】是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源
(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可
介由加密确认的方式来防止恶毒的协议攻击。时间按NTP服务器的等级传播。按照离外部UTC源的远近把所有服务器归入不同
的Stratum(层)中。

环境描述:

系统:
centos7

集群:
server1
server2
server3

让server1作为时间源,server2和server3向server1同步时间;

2、安装ntp

查看当前服务器时区&列出时区并设置时区(如已是正确时区,请略过):
timedatectl
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai

安装(所有主机):
yum -y install ntp

3、硬件时间问题

同步硬件时间:
date            #查看系统时间
hwclock --show         #查看硬件时间
timedatectl set-timezone Asia/Shanghai        #调整时区
hwclock --systohc --localtime            #将硬件时间调整为和系统时间一样
clock -w            #将日期写入CMOS

4、配置

server1

-----/etc/ntp.conf-----
#以server1的硬件时间作为时间源
server 127.127.1.0     # local clock 
fudge 127.127.1.0 stratum 10

#注释掉其他时间源
#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



#授权192.168.1.*网段可以同步

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

server2和server3

-----/etc/ntp.conf-----
#配置server1作为同步时间源
server server1

#注释掉其他时间源
#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

5、启动

systemctl start ntpd

6、查看

查看与时间源的偏差:

ntpdc -c loopinfo

查看同步的时间源:

ntpq -p
原文地址:https://www.cnblogs.com/weiyiming007/p/12170499.html