如何在 CentOS 中设置 NTP 服务器

如何在 CentOS 中设置 NTP 服务器,第1张

1 Linux
NTP 客户端主机需要 ntpupdate 软件包来和服务器同步时间。可以轻松地使用 yum 或 apt-get 安装这个软件包。安装完软件包之后,用服务器的 IP 地址运行下面的命令。
# ntpdate <server-IP-address>
基于 RHEL 和 Debian 的系统命令都相同。
2 Windows
如果你正在使用 Windows,在日期和时间设置(Date and Time settings)下查找网络时间(Internet Time)。
3 Cisco 设备
如果你想要同步 Cisco 设备的时间,你可以在全局配置模式下使用下面的命令。
# ntp server <server-IP-address>
来自其它厂家的支持 NTP 的设备有自己的用于网络时间的参数。如果你想将设备和 NTP服务器同步时间,请查看设备的说明文档。

一、搭建时间服务器
1、在一台linux服务器安装ntp server
tar zxvf ntp-426targz
cd ntp-426
/configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install
2、修改ntpconf配置文件
vi /etc/ntpconf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system
#restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
(允许任何IP的客户机都可以进行时间同步,如果是只允许某个网段的客户机进行时间同步可以这样写
restrict 1058260 mask 2552552550 nomodify)
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface This could
# be tightened as well, but to do so would effect some of
# the administrative functions
restrict 127001
restrict -6 ::1
# Hosts on local network are less restricted
#restrict 19216810 mask 2552552550 nomodify notrap
# Use public servers from the poolntporg project
# Please consider joining the pool
#server 0rhelpoolntporg(默认时间服务器)
#server 1rhelpoolntporg(默认时间服务器)
#server 2rhelpoolntporg(默认时间服务器)
server 101281425 (手工设置的时间服务器)
(如果是可以直连外网,可以使用LINUX默认提供的三组标准时间服务器,否则可以自己指定一个同步时间源)
#broadcast 1921681255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224011 key 42 # multicast server
#multicastclient 224011 # multicast client
#manycastserver 239255254254 # manycast server
#manycastclient 239255254254 key 42 # manycast client
# Undisciplined Local Clock This is a fake driver intended for backup
# and when no outside source of synchronized time is available
server 12712710 # local clock
fudge 12712710 stratum 10
3、以守护进程启动ntpd
#/etc/rcd/initd/ntpd -c /etc/ntpconf -p /tmp/ntpdpid
#/etc/rcd/initd/ntpd start
#ps -ef|grep ntpd
4、在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令进行同步时会产生no server suitable for synchronization found的错误。
下面命令可以知道何时ntp server完成了和自身同步的过程
在ntp server上使用命令:
# watch ntpq -p
注意LOCAL的这个就是与自身同步的ntp server。
注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒5=320秒的时间。
二、配置时间同步客户机
vi /var/spool/cron/root(或crontab -e)
增加一行,在每天的1点10分、9点10分、17点10分与时间同步服务器进行同步并写入BIOS
10 1 ,9,17 root /usr/sbin/ntpdate 101281425; /sbin/hwclock -w
如果同步不正常,可以加输出日志或看系统日志
输出日志的方法:
10 1 ,9,17 root /usr/sbin/ntpdate 101281425>>/tmp/1txt; /sbin/hwclock -w
在1txt中可查看时间同步时的输出结果。
或者看/var/mail/root系统日志
Subject: Cron <root@tyzssq8> /usr/sbin/ntpdate 101281425;/sbin/hwclock -w
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20121127103001076FF2090E@tyzssq8site>
Date: Tue, 27 Nov 2012 18:30:01 +0800 (CST)
27 Nov 18:29:59 ntpdate[6917]: step time server 101281425 offset -1361968 sec
可以看到同步成功了,如果未成功会报出错误。
三、无法同步的问题
检查ntp server主机的防火墙。可能是ntp server的防火墙屏蔽了upd 123端口。
可以用命令
#service iptables stop

NTPD服务器
Network Time Protocol

一、时间服务器的重性
ntp 123/udp

二、配置时间服务器

ntp-424p8-3el6x86_64

NTP Server配置示例:

restrict default nomodify //不允许客户端登录,也不允许客户端修改
server 12712710 //使用本地的bios时间,自己跟自己同步
fudge 12712710 stratum 10 //定义级别,范围0-16,越小越精准

注释:时间服务器要读取本地的bios时间,所以会延迟5min左右才能同步成功

查看server的同步的状态:

unsynchronised
time server re-starting
polling server every 64 s

synchronised to local net at stratum 11
time correct to within 949 ms
polling server every 64 s

三、配置NTP客户端
方法一:

01 ntpdate 172161101

方法二:

server 172161101
fudge 172161101 stratum 5

==========================================================================
172161101 LOCAL(0) 11 u 36 64 3 0405 0046 0022

Mon Jan 20 14:44:25 CST 2014

Mon 20 Jan 2014 02:44:36 PM CST -0145485 seconds

方法一
采用Windows、linux等 *** 作系统自带的时间同步功能
对于Windows *** 作系统,自身已经集成了自动对时功能,在此仅以windows *** 作系统为例介绍一下。

双击系统托盘下方的时间在服务器地址栏输入NTP服务器的IP地址(1cnpoolntporg),然后点击“确定”按钮保存下来就行了。
方法二
修改注册表,提高时间同步精度
由于系统默认的时间同步间隔是7天,我们无法自由选择,使得这个功能在灵活性方面大打折扣。其实,我们也可以通过修改注册表来手动修改它的自动同步间隔以提高同步精度,以下以XP系统为例。
1 在“开始”菜单→“运行”项下输入“Regedit”进入注册表编辑器
2 展开[
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/TimeProviders/NtpClient
] 分支,并双击 SpecialPollInterval 键值,将对话框中的“基数栏”选择到“十进制”上
3
对话框中显示的数字正是自动对时的间隔(以秒为单位),比如默认的604800就是由7(天)×24(时)×60(分)×60(秒)计算来的。设定时间同步周期(建议设为900=15分钟或3600=1小时等周期值),填入对话框,点击确定保存关闭对话框。
4
在Parameters列表中,将NtpServer键值修改为NTP服务器的IP地址(1cnpoolntporg),然后点击“确定”按钮保存。
方法三,采用其他NTP客户端程序时间同步

可以在互联网上找到其他客户端程序实现电脑时间同步。

配置的时钟服务器的ip地址为192168100116

第一步  为服务器和客户机安装ntp  ntpdate

[root@sql-proxy1 app]#yum install ntp ntpdate -y第二步 查找时间同步服务器

>

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/12967879.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-29
下一篇 2023-05-29

发表评论

登录后才能评论

评论列表(0条)

保存