NTP配置手册

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Linux客户端Ntp时间同步配置手册
1、NTP服务开机自动加载:
1.1首先查看ntpd的服务是否在客户端开机时自动重启:
chkconfig --list |grep ntpd //查看ntpd服务开启情况
1.2设置NTP服务在下一次开机运行状态:
chkconfig ntpd on //开机自动运行
chkconfig ntpd off //关闭开机自动运行ntp服务
2、修改/etc/ntp.conf文件:
2.1通过命令more /etc/ntp.conf查看ntp.conf文件下的内容
2.2指定时间同步服务器:
restrict 10.150.210.72 mask 255.255.255.0 nomodify notrap noquery server 10.150.210.72
备注:此命令必须加载到server 127.127.1.0 # local clock之前。

2.3指定NTP服务器日志文件:
logfile /var/log/ntp
2.4注销如下命令行:
#server
#server
#server
3、修改/etc/ntp/step-tickers文件
3.1通过more /etc/ntp/step-tickers查看文件内容;
3.2通过vi /etc/ntp/step-tickers进行编辑文件,增加如下内容
10.150.210.72 //ntp服务器地址
127.127.1.0 //Linux客户端本地地址
4、修改/etc/sysconfig/ntpd文件,允许BIOS与系统时间同步
4.1通过vi etc/sysconfig/ntpd进行编辑,更改如下内容:
SYNC_HWCLOCK=no改为yes
5、通过service ntpd start开启ntpd服务;
6、测试NTP时间同步
6.1通过ntpq –p 查看偏移量
6.2通过ntpdate –d 10.150.210.72进行测试
如果出现transmit(10.150.210.72)
receive(10.150.210.72) 则配置正确。

备注:如果不能同步可通过service ntpd restart命令重启ntpd服务。

7、附录(配置log文件):
[root@zqnyx-web-01 ~]# chkconfig --list |grep ntpd
ntpd 0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭[root@zqnyx-web-01 ~]# more /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# 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 -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the project.
# Please consider joining the pool (/join.html).
server
server
server
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file # by creating a temporary in the same directory and then rename()'ing # it to the file.
driftfile /var/lib/ntp/drift
# 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
[root@zqnyx-web-01 ~]# date
2012年03月12日星期一16:19:41 CST
以下为修改后/etc/ntp.conf文件:
[root@zqnyx-web-01 ~]# more /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system. restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# 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 -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the project.
# Please consider joining the pool (/join.html). #server
#server
#server
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
restrict 10.150.210.72 mask 255.255.255.0 nomodify notrap noquery server 10.150.210.72
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file # by creating a temporary in the same directory and then rename()'ing # it to the file.
driftfile /var/lib/ntp/drift
# 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
logfile /var/log/ntp
[root@zqnyx-web-01 ~]# cd /var/log/
[root@zqnyx-web-01 log]# ls -l |grep ntp
[root@zqnyx-web-01 log]# pwd
/var/log
[root@zqnyx-web-01 log]# touch ntp
[root@zqnyx-web-01 log]# more /etc/ntp/step-tickers
[root@zqnyx-web-01 log]# vi /etc/ntp/step-tickers
~
~
~
"/etc/ntp/step-tickers" 2L, 26C written
[root@zqnyx-web-01 log]# more /etc/ntp/step-tickers
10.150.210.72
127.127.1.0
[root@zqnyx-web-01 log]# vi /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"
# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=no
# Additional options for ntpdate
NTPDATE_OPTIONS=""
~
~
~
"/etc/sysconfig/ntpd" 8L, 210C written
[root@zqnyx-web-01 log]# more /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"
# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=yes
# Additional options for ntpdate
NTPDATE_OPTIONS=""
[root@zqnyx-web-01 log]# service ntpd start
ntpd: 同步时间服务器:[确定]
同步硬件时钟到系统时钟[确定]
启动ntpd:[确定]
[root@zqnyx-web-01 log]# date
2012年03月12日星期一16:28:01 CST
[root@zqnyx-web-01 log]# more /var/log/ntp
[root@zqnyx-web-01 log]# more /var/log/ntp
[root@zqnyx-web-01 log]# watch ntpq -p
[root@zqnyx-web-01 log]# ntpdate -d 10.150.210.72
12 Mar 16:29:00 ntpdate[22796]: ntpdate 4.2.2p1@1.1570-o Thu May 14 13:01:42 UTC 2009 (1)
Looking for host 10.150.210.72 and service ntp
host found : 10.150.210.72
transmit(10.150.210.72)
receive(10.150.210.72)
transmit(10.150.210.72)
receive(10.150.210.72)
transmit(10.150.210.72)
receive(10.150.210.72)
transmit(10.150.210.72)
receive(10.150.210.72)
transmit(10.150.210.72)
server 10.150.210.72, port 123
stratum 1, precision -19, leap 00, trust 000
refid [GPS], delay 0.02585, dispersion 0.00000
transmitted 4, in filter 4
reference time: d3083244.45d6c56d Mon, Mar 12 2012 16:28:52.272
originate timestamp: d308324d.04e5950a Mon, Mar 12 2012 16:29:01.019 transmit timestamp: d308324d.063a0839 Mon, Mar 12 2012 16:29:01.024
filter delay: 0.02603 0.02585 0.02585 0.02585
0.00000 0.00000 0.00000 0.00000
filter offset: -0.00524 -0.00532 -0.00533 -0.00533
0.000000 0.000000 0.000000 0.000000
delay 0.02585, dispersion 0.00000
offset -0.005329
12 Mar 16:29:01 ntpdate[22796]: adjust time server 10.150.210.72 offset -0.005329 sec [root@zqnyx-web-01 log]# ntpdate -s
[root@zqnyx-web-01 log]# ntpdate -s 10.150.210.72
[root@zqnyx-web-01 log]# more /var/log/ntp。

相关文档
最新文档