Linux同步时间服务器
2016-12-23 22:53
204 查看
在集群中同步时间,可以使用ntpd服务器
安装服务器:
1. 安装ntpd服务,可通过一下命令安装
2. 修改配置如下:
3. 启动ntpd服务
可通过`watch ntpq -p`查看是否启动正确
安装客户端:
1. 安装ntpdate客户端
2. 运行ntpdate server同步时间,server即为ntpd服务器地址或主机名
疑难问题:
错误1.Server dropped: Strata too high
解决办法:
在ntp客户端运行ntpdate serverIP,出现no
server suitable for synchronization found的错误。
在ntp客户端用ntpdate –d serverIP查看,发现有“Server
dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。
这是因为NTP server还没有和其自身或者它的server同步上。
以下的定义是让NTP Server和其自身保持同步,如果在/ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。
在ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。
那么如何知道何时ntp server完成了和自身同步的过程呢?
在ntp server上使用命令:
显示内容中:
注意LOCAL的这个就是与自身同步的ntp server。
注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒*5=320秒的时间。
如果之后从ntp客户端同步ntp server还失败的话,用ntpdate –d来查询详细错误信息,再做判断
错误2.Server dropped: no data
出现这个问题的原因可能有2:
1. 检查ntp的版本,如果你使用的是ntp4.2(包括4.2)之后的版本,在restrict的定义中使用了notrust的话,会导致以上错误。
使用以下命令检查ntp的版本:
下面是来自ntp官方网站的说明:
The behavior of notrust changed between versions 4.1 and 4.2.
In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".
In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd
解决:
把notrust去掉。
2. 检查ntp server的防火墙。可能是server的防火墙屏蔽了upd 123端口。
可以用命令
来关掉iptables服务后再尝试从ntp客户端的同步,如果成功,证明是防火墙的问题,需要更改iptables的设置。
微信公众号:
安装服务器:
1. 安装ntpd服务,可通过一下命令安装
yum install ntp -y
2. 修改配置如下:
# 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
# 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.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap
# 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 127.127.1.0
fudge 127.127.1.0 stratum 8
#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
3. 启动ntpd服务
systemctl start ntpd
可通过`watch ntpq -p`查看是否启动正确
安装客户端:
1. 安装ntpdate客户端
yum install ntpdate -y
2. 运行ntpdate server同步时间,server即为ntpd服务器地址或主机名
疑难问题:
错误1.Server dropped: Strata too high
解决办法:
在ntp客户端运行ntpdate serverIP,出现no
server suitable for synchronization found的错误。
在ntp客户端用ntpdate –d serverIP查看,发现有“Server
dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。
这是因为NTP server还没有和其自身或者它的server同步上。
以下的定义是让NTP Server和其自身保持同步,如果在/ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。
server 127.127.1.0
fudge 127.127.1.0 stratum 8
在ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。
那么如何知道何时ntp server完成了和自身同步的过程呢?
在ntp server上使用命令:
# watch ntpq -p
显示内容中:
注意LOCAL的这个就是与自身同步的ntp server。
注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒*5=320秒的时间。
如果之后从ntp客户端同步ntp server还失败的话,用ntpdate –d来查询详细错误信息,再做判断
错误2.Server dropped: no data
出现这个问题的原因可能有2:
1. 检查ntp的版本,如果你使用的是ntp4.2(包括4.2)之后的版本,在restrict的定义中使用了notrust的话,会导致以上错误。
使用以下命令检查ntp的版本:
# ntpq -c version
下面是来自ntp官方网站的说明:
The behavior of notrust changed between versions 4.1 and 4.2.
In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".
In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd
解决:
把notrust去掉。
2. 检查ntp server的防火墙。可能是server的防火墙屏蔽了upd 123端口。
可以用命令
#service iptables stop
来关掉iptables服务后再尝试从ntp客户端的同步,如果成功,证明是防火墙的问题,需要更改iptables的设置。
微信公众号:
相关文章推荐
- Linux 服务器之间时间同步
- linux 修改服务器时间更新同步,和定时任务
- linux同步ntpd服务器时间方式
- Linux 服务器时间同步
- Linux 服务器时间同步
- 同步linux服务器的时间
- Linux 自动同步服务器时间
- 如何用linux一台服务器时间去同步其他服务器的时间
- linux 服务器时间同步
- linux 服务器时间同步的方法(同步外网或局域网)
- linux ntp 服务器,时间同步
- 企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)
- 配置Linux下的时间服务器,让一批机器和一台机器时间同步【设置一台专门用来同步时间的服务器名为timeserver,很实用】
- Linux 服务器时间同步
- Linux内网服务器从Windows通过NTP同步时间
- 在各种Linux系统的服务器上设置时间同步的方法
- linux 时间服务器,同步组织内部服务器时间
- linux 服务器时间同步
- Linux 服务器时间同步设置
- Linux 局域网内服务器时间同步