Windows下配置NTP服务
详见:https://blog.csdn.net/hulangbotufei/article/details/125253825
#CentOS配置NTP服务器
为了避免主机时间因为长期运作下所导致的时间偏差,进行时间同步(synchronize)的工作是非常必要的。Linux系统下,一般使用ntp服务器 来同步不同机器的时间。一台机器,可以同时是ntp服务器和ntp客户机。在网络中,推荐使用像DNS服务器一样分层的时间服务器来同步时间。
同步时间,可以使用ntpdate命令,也可以使用ntpd服务
安装ntp包
[root@localhost ~]# yum install ntp ntpdate -y
查看ntp配置文件
cp /etc/ntp.conf /etc/ntp.conf.bak
vim /etc/ntp.conf
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery
restrict 10.10.10.0 mask 255.255.255.0 nomodify notrap
# 限制本地网络上的主机。限制10.10.10.0掩码255.255.255.0 nomodify notrap
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 127.127.1.0 iburst prefer
server times.aliyun.com iburst
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server cn.pool.ntp.org iburst
# 允许上层服务器主动修改本机时间
restrict times.aliyun.com nomodify notrap noquery
restrict ntp.aliyun.com nomodify notrap noquery
restrict ntp1.aliyun.com nomodify notrap noquery
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor
启动NTP服务
systemctl start ntpd
将NTP服务设置为开机启动
systemctl enable ntpd
检查 NTP检查设置
systemctl status ntpd
重启NTP服务
systemctl restart ntpd
其它
1.查看当前系统时间
date
2019年 01月 04日 星期五 17:59:20 CST
2.查看当前硬件时间
hwclock
3.设置系统时间,字符串形式
date -s "2018-01-01 11:20:30"
4.将系统时间同步到硬件
hwclock --systohc
#客户端 Client
[root@localhost ~]# yum install ntp ntpdate -y
查看ntp配置文件
cp /etc/ntp.conf /etc/ntp.conf.bak
[root@localhost ~]# vim /etc/ntp.conf
参考以下内容
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
#只需要指定ntp服务器IP即可
server 10.10.10.93 iburst prefer
#允许上层服务器主动修改本机时间
restrict 10.10.10.93 nomodify notrap noquery
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
注:10.10.10.93为时间服务器IP
[root@localhost ~]# ntpdate -u 10.10.10.93
返回:24 Apr 16:42:36 ntpdate[15780]: adjust time server 10.10.10.93 offset 0.010078 sec
##启动NTP服务
systemctl start ntpd
##将NTP服务设置为开机启动
systemctl enable ntpd
##检查 NTP检查设置
systemctl status ntpd
##重启NTP服务
systemctl restart ntpd
查看时间同步状态
一般需要5-10分钟后才能成功连接和同步。所以,服务启动后需要稍等下。
[root@localhost ~]# ntpq -p
其它
1.查看当前系统时间
date
2019年 01月 04日 星期五 17:59:20 CST
2.查看当前硬件时间
hwclock
3.设置系统时间,字符串形式(可略)
date -s "2018-01-01 11:20:30"
4.将系统时间同步到硬件
hwclock --systohc