微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Centos6.5 配置NTP服务器

配置NTP-server

环境:

[root@LNMP~]#cat/etc/redhat-release
CentOSrelease6.5(Final)
[root@LNMP~]#uname-r
2.6.32-431.el6.x86_64
[root@LNMP~]#uname-m
x86_64

安装NTP软件:

[root@LNMP~]#yuminstall-yntp

检查远程ntp服务器是否可用:

[root@LNMP~]#ntpdate-qntp5.aliyun.com
server182.92.12.11,stratum2,offset-0.011808,delay0.03224
20Apr21:15:37ntpdate[3429]:adjusttimeserver182.92.12.11offset-0.011808sec

配置ntp服务之前,先手动同步一下时间:

[root@LNMP~]#ntpdatentp5.aliyun.com

编辑NTP配置文件:(文件位置在/etc/ntp.conf,编辑前备份)

[root@LNMP~]#cp/etc/ntp.conf/etc/ntp.conf.ori
[root@LNMP~]#vim/etc/ntp.conf
restrict192.168.22.0mask255.255.255.0nomodifynotrap
serverntp1.aliyun.com
serverntp2.aliyun.com
serverntp3.aliyun.com
serverntp4.aliyun.com
serverntp5.aliyun.com
serverntp6.aliyun.com
serverntp7.aliyun.com
#UndisciplinedLocalClock.Thisisafakedriverintendedforbackup
#andwhennooutsidesourceofsynchronizedtimeisavailable.
#外部时间服务器不可用时,以本地时间作为时间服务
server127.127.1.0#localclock
fudge127.127.1.0stratum10

把之前的参数注释掉:

#server0.centos.pool.ntp.orgiburst
#server1.centos.pool.ntp.orgiburst
#server2.centos.pool.ntp.orgiburst
#server3.centos.pool.ntp.orgiburst

检查服务状态:

[root@LNMP~]#netstat-lntup|grepntp
udp00192.168.22.134:1230.0.0.0:*1186/ntpd
udp00127.0.0.1:1230.0.0.0:*1186/ntpd
udp000.0.0.0:1230.0.0.0:*1186/ntpd
udp00fe80::20c:29ff:fe51:259b:123:::*1186/ntpd
udp00::1:123:::*1186/ntpd
udp00:::123:::*1186/ntpd
[root@LNMP~]#ntpq-p
remoterefidsttwhenpollreachdelayoffsetjitter
==============================================================================
*time5.aliyun.co10.137.38.862u1812563779.293-1.9901.154
+120.25.115.1910.137.38.862u13825637745.598-1.9241.010
+120.25.115.2010.137.38.862u15725637745.795-1.7131.113
-time4.aliyun.co10.137.38.862u24725637745.650-5.1362.278
-time6.aliyun.co10.137.38.862u625637774.0538.7283.008
LOCAL(0).LOCL.10l128m6400.0000.0000.000

ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。

[root@LNMP~]#ntpstat
synchronisedtoNTPserver(182.92.12.11)atstratum3
timecorrecttowithin30ms
pollingserverevery256s

如果服务器当前时间和远程ntp服务器时间相差很多或者服务器时间比远程ntp服务器时间要快的话,那么服务器是不会与远程ntp服务器同步时间的

需要在ntp.conf中加上一行参数:

tinkerpanic0

将同步的时间与硬件时钟进行同步:

[root@LNMP~]#vim/etc/sysconfig/ntpd
添加一行
SYNC_HWCLOCK="yes"
保存退出,重启ntp服务

至此,NTP-server时间服务器配置完成!


配置内网NTP-client

首先需要安装NTPD服务,然后配置为自启动(与NTP-Server完全一样)。然后找其中一台配置/etc/ntp.conf文件,配置完成验证通过后,拷贝到其他客户端机器,直接使用即可。

[root@Proxy~]#grep-Ev'#'/etc/ntp.conf
driftfile/var/lib/ntp/drift
restrict127.0.0.1
restrict-6::1
server192.168.22.134
restrict192.168.22.134nomodifynotrapnoquery
fudge127.127.1.0stratum10
includefile/etc/ntp/crypto/pw
keys/etc/ntp/keys

将同步的时间与硬件时钟进行同步:

[root@Proxy~]#vim/etc/sysconfig/ntpd
添加一行:
SYNC_HWCLOCK="yes"
保存退出,重启ntp服务。

检查ntp服务状态:

[root@Proxy~]#netstat-lntup|grepntp
udp00192.168.22.136:1230.0.0.0:*2833/ntpd
udp00127.0.0.1:1230.0.0.0:*2833/ntpd
udp000.0.0.0:1230.0.0.0:*2833/ntpd
udp00fe80::20c:29ff:feff:3bf5:123:::*2833/ntpd
udp00::1:123:::*2833/ntpd
udp00:::123:::*2833/ntpd
[root@Proxy~]#ntpq-p
remoterefidsttwhenpollreachdelayoffsetjitter
==============================================================================
192.168.22.134173.255.246.133u2064170.21824.1950.084
*LOCAL(0).LOCL.10l2464170.0000.0000.000
[root@Proxy~]#ntpstat
synchronisedtoNTPserver(192.168.22.134)atstratum4
timecorrecttowithin53ms
pollingserverevery128s

原文地址:https://www.jb51.cc/centos/377863.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。