Linux 服务构建 NTP 时间服务器

Linux 服务构建 NTP 时间服务器

1、构建 NTP 时间服务器


NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时性要求比较高的必须统一时间。

互联网的时间服务器也有很多,如 ntpdate ntp.fudan.edu.cn 复旦大学的NTP免费提供互联网时间同步。

NTP服务器监听端口为UDP的 123,那就需要在本地防火墙开启运行客户站访问123端口,vi /etc/sysconfig/ipabls 添加如下规则:

-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT


NTP 时间服务器配置:

yum install ntp ntpdate -y 即可!安装ntp ntpdate, -y 不提示的意思。

修改 ntp.conf 配置文件


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


vi /etc/ntp.conf 只修改下如下两行,把#号去掉即可!

server 127.127.1.0 #local clock

fudge 127.127.1.0 srtatum 10


LANG=UTF-8 设置utf-8


/etc/init.d/ntpd restart 重启 ntpd 服务


(注意*:ntpd 启动后,客户机要等几分钟再与其进行时间同步,否则会提示:"no server suitable for synchronizafion found" 错误。)


ntpq -p 查看NTP 状态


date 查看当前时间命令


ntpdate 同步服务器时间命令;ntpdate pool.ntp.org或192.168.138.129


配置时间同步客户机

crontab -e 计划任务,


增加一行,在每天的6点10分与时间同步服务器进行同步,格式:分;时;日;月;星期;10 06 ***


10 06 *** /usr/sbin/ntpdate ntp-server 的 ip>> /usr/local/logs/crontab/ntpdate/log


备注:如果客户机没有ntpdate ,可以 yum -y install ntp 即可!


以下是ntp 服务器配置文件内容(局域网NTP,如果需要跟外网同步,添加外网 server 即可)


driftfile /var/lib/ntp/drift

restrict dafult bod nomodify notrap noperr noquery

restrict -6 dafault kod nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict -6 ::1

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

Linux 服务构建 NTP 时间服务器

下面是参数详解:

restrict default ignore# 关闭所有的 NTP 要求封包restrict 127.0.0.1# 开启内部递归网络接口 lo

restrict 192.168.0.0 mask

255.255.255.0 nomodify

# 在内部子网里面的客户端可以进行网络校时,但不能修改NTP 服务器的时间参数。server 198.123.30.132#198.123.30.132 作为上级时间服务器参考restrict 198.123.30.132#开放 server 访问我们 ntp服务的权限driftfile /var/lib/ntp/drift# 在与上级时间服务器联系时所花费的时间,记录drftflile 参数后面的文件内broadcastdelay 0.008# 广播延迟时间


自此 NTP 服务器搭建完毕,在所有客户站端crontab 里面添加如下语句:

0 0 * * * /usr/sbin/ntpdate 10.0.0.155 >>/data/logs/ntp.log 2>&1

(10.0.0.155 这IP是服务端ntp 的服务器ip)


Linux 服务构建 NTP 时间服务器


分享到:


相關文章: