码迷,mamicode.com
首页 > 其他好文 > 详细

配置NTP时间服务器2015-7-21

时间:2015-07-22 11:04:05      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:配置ntp时间服务器

服务器端配置:

IP 172.16.1.53

安装ntp

[root@sslinux ~]# yum install ntp

或者rpm安装

[root@sslinux Packages]# rpm -ivhntp-4.2.4p8-2.el6.centos.x86_64.rpm


[root@sslinux ~]# vim /etc/ntp.conf

# permit the source to query or modify the service on thissystem.

# restrict default kodnomodify notrap nopeer noquery   这行注释掉

restrict default nomodify        所有IP都能连接这台时间服务器

或者

restrict 172.16.1.0 mask255.255.255.0 nomodify   指定IP段连接这台时间服务器

restrict -6 default kod nomodify notrap nopeer noquery

# nomodify 客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时

# notrap  不提供trap 这个运程事件登入的功能

# noquery 客户端不能够使用ntpc 与ntpq等指令来查询时间服务器,不提供NTP的网络校时

# nopeer:不与其他同一层的NTP服务器进行时间同步

# Permit all access over the loopback interface.  This could

#server 0.centos.pool.ntp.org

#server 1.centos.pool.ntp.org

#server 2.centos.pool.ntp.org

server 210.72.145.44 prefer      210.72.145.44中国国家授时中心服务器

这里指定上级时间服务器,系统自带的可以注销,也可以保留,perfer是优先级的意思

# and when no outside source of synchronized time is available.

server  127.127.1.0     # local clock

fudge   127.127.1.0stratum 10  

这两行的注释去掉,意思是当连接上级时间服务器失败,就以本地时间为客户端提供时间服务

# Enable public key cryptography.

[root@sslinux ~]# /etc/init.d/ntpd start

正在启动 ntpd:                                            [确定]

[root@sslinux ~]# chkconfig ntpd on

[root@sslinux ~]# chkconfig --list ntpd

ntpd            0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭


客户端配置:

IP 172.16.1.59

安装ntp

[root@ss1linux ~]# yum install ntp

或者rpm安装

[root@ss1linux Packages]# rpm -ivhntp-4.2.4p8-2.el6.centos.x86_64.rpm


[root@ss1linux ~]# vim /etc/ntp.conf

#server 0.centos.pool.ntp.org

#server 1.centos.pool.ntp.org

#server 2.centos.pool.ntp.org

server 172.16.1.53

在这里添加远程时间服务器地址即可


[root@ss1linux ~]# /etc/init.d/ntpd start

正在启动 ntpd:                                            [OK]

[root@ss1linux ~]# chkconfig ntpd on    设置服务开机自启动

[root@ss1linux ~]# chkconfig --list ntpd  查看开机自启情况 3和5是on就行

ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off


初始同步时间需要5分钟左右,如果立即手工同步会有下面的报错

[root@ss1linux ~]# ntpdate 172.16.1.53

21 Jul 07:39:58 ntpdate[1184]: no server suitable forsynchronization found

[root@ss1linux ~]# ntpdate 172.16.1.53    手工同步时间服务器

21 Jul 07:43:24 ntpdate[1212]: the NTP socket is in use,exiting

检查时间服务器是否正确同步

[root@ss1linux ~]# ntpq -p

remote        refid         st t  whenpoll reach   delay   offset jitter

==============================================================================

*172.16.1.53    LOCAL(0)        11 u    6  64   377   0.238   -4.623   2.174


remote :本地主机所连接的上层NTP服务器,最左边的符号如下:

如果有[*] 代表目前正在使用当中的上层NTP服务器。

如果有[+] 代表也有连上上层NTP服务器,可以作为提高时间更新的候选ntp服务器                                 refid  :指的是给上层NTP服务器提供时间校对的服务器。

St:上层NTP服务器的级别。

When: 上一次与上层NTP服务器进行时间校对的时间(单位:s)

Poll :下一次本地主机与上层NTP服务器进行时间校对的时间(单位:s)

reach:已经向上层 NTP 服务器要求更新的次数

delay:网络传输过程当中延迟的时间,单位为 10^(-6) 秒

offset:时间补偿的结果,单位与 10^(-3) 秒

jitter:Linux 系统时间与 BIOS 硬件时间的差异时间,单位为 10^(-6) 秒


设置自动更新时间

以root身份运行周期性任务:

[root@ss1linux ~]# crontab -e

15 * * * * ntpdate172.16.1.53    每15分钟更新一下时间

:wq

到此全部配置完成


本文出自 “个人随笔” 博客,请务必保留此出处http://sz659918615.blog.51cto.com/9141346/1676916

配置NTP时间服务器2015-7-21

标签:配置ntp时间服务器

原文地址:http://sz659918615.blog.51cto.com/9141346/1676916

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!