Linux下NTP服务器端配置

本文详细介绍了如何在Linux系统下配置NTP服务器,包括使用ntpdate命令同步时间,备份并修改ntp.conf配置文件,设置本地服务器为根时间服务器,检查ntpd服务状态,以及解释了ntp配置文件中的关键参数。此外,还提到了driftfile的作用,以及如何同步硬件时钟。通过这些步骤,可以确保系统时间与外部标准时间源保持一致。
摘要由CSDN通过智能技术生成

一、ntp同步shell命令:ntpdate time.nist.gov(或填ip:132.163.4.103)


二、配置NTP服务器(默认NTP软件已安装)。

①备份原ntp配置文件

cp/etc/ntp.conf/etc/ntp.conf.bak


②修改配置文件

vi /etc/ntp.conf


我的ntp.conf配置:

logfile /var/log/ntp.log
restrict default nomodify
restrict 127.0.0.1
restrict 192.168.0.0 mask 255.255.255.0 nomodify
server 128.138.141.172 prefer


若设置本地服务器为根时间服务器,则最后的参数改为:

server 127.127.1.0

fudge  127.127.1.0 stratum 1


三、查看ntpd是否可用。(一般要等5~10分钟后才可用)

watch ntpq -p


四、其他

1. 配置文件中的driftfile是什么?
我们每一个system clock的频率都有小小的误差,这个就是为什么机器运行一段时间后会不精确. NTP会自动来监测我们时钟的误差值并予以调整.但问题是这是一个冗长的过程,所以它会把记录下来的误差先写入driftfile.这样即使你重新开机以后之前的计算结果也就不会丢失了

2. 如何同步硬件时钟?
NTP一般只会同步system clock. 但是如果我们也要同步RTC(hwclock)的话那么只需要把下面的选项打开就可以了
代码:
# vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes



参考网站:http://blog.csdn.net/love_life2011/article/details/8067652




以下为转载的

[root@bogon ~]# clear

[root@bogon ~]# lsb_release -a

LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch

Distributor ID: Fedora

Description: Fedora release 17 (Beefy Miracle)

Release: 17

Codename: BeefyMiracle

[root@bogon ~]# uname -a

Linux bogon 3.6.10-2.fc17.x86_64 #1 SMP Tue Dec 11 18:07:34 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

[root@bogon ~]# rpm -qa |grep ntp

fontpackages-filesystem-1.44-4.fc17.noarch

ntpdate-4.2.6p5-2.fc17.x86_64

ntp-4.2.6p5-2.fc17.x86_64

 

[root@bogon ~]# cat /etc/ntp.conf 

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 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 pool.ntp.org project.

Please consider joining the pool (http://www.pool.ntp.org/join.html).

server 0.fedora.pool.ntp.org iburst

server 1.fedora.pool.ntp.org iburst

server 2.fedora.pool.ntp.org iburst

server 3.fedora.pool.ntp.org iburst

 

#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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值