Linux】 构建NTP时间服务器具体操作步骤

2021-04-06 17:44发布

9条回答

构建NTP时间服务器

NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时性要求高的必须统一时间。
互联网的时间服务器也有很多,例如ntpdate ntp.fudan.edu.cn 复旦大学的NTP免费提供互联网时间同步。

NTP时间服务器安装:

yum install ntp ntpdate -y 即可!

修改ntp.conf配置文件

vi /etc/ntp.conf 只修改如下两行,把#号去掉即可!server 127.127.1.0     # local clockfudge  127.127.1.0 stratum 10以守护进程启动ntpd /etc/init.d/ntpd start 即可(注意*: ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。)配置时间同步客户机crontab -e 增加一行,在每天的6点10分与时间同步服务器进行同步10 06 * * * /usr/sbin/ntpdate ntp.pool.org的ip >>/usr/local/logs/crontab/ntpdate.log 备注:如果客户机没有ntpdate,可以yum –y install ntp 即可!以下是ntp服务器配置文件内容(局域网NTP,如果需要跟外网同步,添加外网server即可) driftfile /var/lib/ntp/driftrestrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1 restrict -6 ::1server  127.127.1.0     # local clockfudge   127.127.1.0 stratum 10includefile /etc/ntp/crypto/pwkeys /etc/ntp/keys

参数详解

restrict default ignore # 关闭所有的 NTP 要求封包restrict 127.0.0.1 # 开启内部递归网络接口 lorestrict 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  在与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内broadcastdelay 0.008  #广播延迟时间自此NTP服务搭建完毕,然后在所有客户端crontab里面添加如下语句:0  0   *  *  * /usr/sbin/ntpdate  10.0.0.155 >>/data/logs/ntp.log 2>&1

构建NTP时间服务器

一周热门 更多>