设为首页 收藏本站
查看: 2431|回复: 0

[经验分享] Centos6.5 配置NTP服务器

[复制链接]

尚未签到

发表于 2018-4-22 16:45:52 | 显示全部楼层 |阅读模式
配置NTP-server

环境:

[root@LNMP ~]# cat/etc/redhat-release
CentOS release 6.5 (Final)
[root@LNMP ~]# uname -r
2.6.32-431.el6.x86_64
[root@LNMP ~]# uname -m
x86_64  
  安装NTP软件:
[root@LNMP ~]# yum install -yntp  检查远程ntp服务器是否可用:
[root@LNMP ~]# ntpdate -q ntp5.aliyun.com
server 182.92.12.11, stratum2, offset -0.011808, delay 0.03224
20 Apr 21:15:37ntpdate[3429]: adjust time server 182.92.12.11 offset -0.011808 sec  配置ntp服务之前,先手动同步一下时间:
[root@LNMP ~]# ntpdate ntp5.aliyun.com  编辑NTP配置文件:(文件位置在/etc/ntp.conf,编辑前备份)
[root@LNMP ~]# cp/etc/ntp.conf /etc/ntp.conf.ori
[root@LNMP ~]# vim/etc/ntp.conf
restrict 192.168.22.0 mask255.255.255.0 nomodify notrap
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
server ntp4.aliyun.com
server ntp5.aliyun.com
server ntp6.aliyun.com
server ntp7.aliyun.com
# UndisciplinedLocal Clock. This is a fake driver intended for backup
# and when nooutside source of synchronized time is available.
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10  把之前的参数注释掉:
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst  检查服务状态:
[root@LNMP ~]# netstat-lntup|grep ntp
udp        0     0 192.168.22.134:123         0.0.0.0:*                              1186/ntpd           
udp        0     0 127.0.0.1:123              0.0.0.0:*                              1186/ntpd           
udp        0     0 0.0.0.0:123                 0.0.0.0:*                               1186/ntpd           
udp        0     0 fe80::20c:29ff:fe51:259b:123 :::*                                   1186/ntpd           
udp        0     0 ::1:123                    :::*                                    1186/ntpd           
udp        0     0 :::123                     :::*                                   1186/ntpd[root@LNMP ~]# ntpq -p
     remote           refid      st t when poll reach   delay  offset  jitter
==============================================================================
*time5.aliyun.co10.137.38.86     2 u  181 256  377    9.293  -1.990   1.154
+120.25.115.19   10.137.38.86     2 u 138  256  377  45.598   -1.924   1.010
+120.25.115.20   10.137.38.86     2 u 157  256  377  45.795   -1.713   1.113
-time4.aliyun.co10.137.38.86     2 u  247 256  377   45.650  -5.136   2.278
-time6.aliyun.co10.137.38.86     2 u    6 256  377   74.053   8.728   3.008
LOCAL(0)       .LOCL.          10 l 128m   64   0    0.000    0.000  0.000  ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。
[root@LNMP ~]# ntpstat
synchronised to NTP server(182.92.12.11) at stratum 3
time correct to within 30 ms
polling server every 256 s  如果服务器当前时间和远程ntp服务器时间相差很多或者服务器时间比远程ntp服务器时间要快的话,那么服务器是不会与远程ntp服务器同步时间的
  需要在ntp.conf中加上一行参数:
tinker panic 0  将同步的时间与硬件时钟进行同步:
[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
restrict 127.0.0.1
restrict -6 ::1
server 192.168.22.134
restrict 192.168.22.134nomodify notrap noquery
fudge 127.127.1.0 stratum 10
includefile/etc/ntp/crypto/pw
keys /etc/ntp/keys  将同步的时间与硬件时钟进行同步:
[root@Proxy ~]# vim/etc/sysconfig/ntpd
添加一行:
SYNC_HWCLOCK="yes"
保存退出,重启ntp服务。  检查ntp服务状态:
[root@Proxy ~]# netstat-lntup|grep ntp
udp        0     0 192.168.22.136:123         0.0.0.0:*                              2833/ntpd           
udp        0     0 127.0.0.1:123               0.0.0.0:*                               2833/ntpd           
udp        0     0 0.0.0.0:123                0.0.0.0:*                              2833/ntpd           
udp        0     0 fe80::20c:29ff:feff:3bf5:123 :::*                                    2833/ntpd           
udp        0     0 ::1:123                    :::*                                   2833/ntpd           
udp        0     0 :::123                     :::*                                   2833/ntpd
[root@Proxy ~]# ntpq -p
     remote           refid      st t when poll reach   delay  offset  jitter
==============================================================================
192.168.22.134 173.255.246.13   3 u   20  64   17    0.218  24.195   0.084
*LOCAL(0)        .LOCL.          10 l  24   64   17   0.000    0.000   0.000
[root@Proxy ~]# ntpstat
synchronised to NTP server(192.168.22.134) at stratum 4
time correct to within 53 ms
polling server every 128 s  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-450602-1-1.html 上篇帖子: centos7 yum安装mysql 下篇帖子: centos7快速部署ceph
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表