Server:192.168.88.135 Client:192.168.88.136、137

相关服务:日本站群服务器租用

1、所有服务器安装ntp服务并设置为自启动

sudo yum install ntp ntpdate ntp-doc

systemctl enable ntpd

2、所有服务器关闭防火墙和SELINUX(粗暴方法,生产环境不推荐)

systemctl stop firewalld

systemctl disable firewalld

vi /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled,wq保存。

3、配置Server:192.168.88.135

1)配置前,先使用命令同步时间。本机与外部时间服务器时间差距太大,会出现内网ntpd不能正常同步的情况:

2)修改/etc/ntp.conf文件

# 允许内网其他机器同步时间,如果不添加该约束默认允许所有IP访问本机同步服务

restrict 192.168.88.0 mask 255.255.255.0 nomodify notrap

# 配置和上游标准时间同步

server 101.201.72.121 # 中国国家授时中心

server 133.100.11.8 #日本[福冈大学]

# 配置允许上游时间服务器主动修改本机(内网ntp Server)的时间

restrict 101.201.72.121 nomodify notrap noquery

restrict 133.100.11.8 nomodify notrap noquery

restrict Fukuda NTP Server nomodify notrap noquery

restrict 3.asia.pool.ntp.org nomodify notrap noquery

#下面这个配置,建议NTP Client关闭,建议NTP Server打开。因为Client如果打开,

#可能导致NTP自动选择合适的最近的NTP Server、也就有可能选择了LOCAL作为Server进行同步,而不与远程Server进行同步。

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

3)修改完成后启动服务

systemctl start ntpd

4)查看网络中的NTP服务器,同时显示客户端和每个服务器的关系:

7 centos 时钟跟物理机同步_Centos7-NTP时钟同步服务配置

ntpq -p

5)查看时间同步状态

ntpstat

这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。

刚启动的时候,执行ntpstat,会显示unsynchronised:

同步成功以后,会显示:

# ntpstat

synchronised to NTP server (202.112.10.36) at stratum 3

time correct to within 275 ms

polling server every 256 s

4、配置Client:192.168.88.136、137

1)修改/etc/ntp.conf文件:

vi /etc/ntp.conf

#配置上游时间服务器为本地的ntpd Server服务器

server 192.168.88.135

# 配置允许上游时间服务器主动修改本机的时间

restrict 192.168.88.135 nomodify notrap noquery

保存文件

2)先和本地ntpd Server同步一下

#ntpdate -u 192.168.88.135

3)启动ntpd服务

#systemctl start ntpd

4)查看状态

# ntpq -p