redhat7.2 centos7.2怎么配置ntp服务器

redhat7.2 centos7.2怎么配置ntp服务器,第1张

在图图形化界面输入下面命令 ~# system-config-date 就会出现一个图形化的界面,我相信图形化的东西你应该看得懂的,设置NTP就可以了,需要的是,时间服务器的主机名 然后运行 ~# service ntpd restart ~# chkconfig ntpd on

Windows(2003)下配置NTP时间服务器
一、服务端设置:
因为默认情况下,WINDOWS SERVER 2003 是作为NTP客户端工作的 ,所以必须通过修改注册表,以使系统作为NTP服务器运行。注意,工作之前请先备份注册表文件。
1、通过开始菜单,输入regedit命令后打开注册表设定画面,此时请一定备份注册表文件。
2、修改以下选项的键值
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\
NtpServer内的「Enabled」设定为1,打开NTP服务器功能
3、修改以下键值
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config\
AnnounceFlags设定为5,该设定强制主机将它自身宣布为可靠的时间源,从而使用内置的互补金属氧化物半导体(CMOS) 时钟。
4、在dos命令行执行以下命令,确保以上修改起作用
net stop w32time
net start w32time
推荐计划;如果该服务器和internet连接,那么为了避免服务器和internet上的ntp同步,最好追加以下配置:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\
NtpClient的「enable」设定为0 以防止作为客户端自动同步外界的时间服务
二、客户设置:
1、指定主时间服务器。在DOS方式输入“net time /setsntp:ntpsjtueducn”,这里我们指定ntpsjtueducn是主时间服务器,也可以是其它地址(2107214544)。
2、自由设定XP时间同步间隔:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\
NtpClient的「SpecialPollInterval」默认设定为604800(或86400)
PS:
对话框中的“基数栏”选择到“十进制”上,显示的数字正是自动对时的间隔(以秒为单位),比如默认的604800就是由7(天)×24(时)×60(分)×60(秒)计算来的如果您想让WINODWS以多长时间自动对时,只要按这个公式算出具体的秒数

NTP(Network Time Protocol,网络时间协议)是基于RFC1305的协议,是一个跨越广域网或局域网的复杂的同步时间协议。一般情况下建议配置在路由器上,当然配置在其它设备上都是可以的。接下来我们根据下面的拓扑图来看一下在路由器上配置NTP服务器的方法以及交换机、windows服务器、Linux服务器如何设置NTP客户端。拓扑如下:
路由器NTPserver上配置如下:
R1>en
R1#conf t
Enter configuration commands, one per line End with CNTL/Z
R1(config)#hostname NTPserver
NTPserver(config)#no ip do lo
NTPserver(config)#line con 0
NTPserver(config-line)#exec-t 0 0
NTPserver(config-line)#logg syn
NTPserver(config-line)#exit
NTPserver(config)#int e0/1
NTPserver(config-if)#int e0/0
NTPserver(config-if)#exi
NTPserver(config)#int e0/0
NTPserver(config-if)#ip ad 19216811 2552552550
NTPserver(config-if)#no shut
NTPserver(config-if)#
Mar 1 00:02:39959: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to up
Mar 1 00:02:40959: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to up
NTPserver(config-if)#clock time
NTPserver(config-if)#do wr
Building configuration
[OK]
NTPserver(config-if)#exit
NTPserver(config)#cloc
NTPserver(config)#clock time
NTPserver(config)#clock timezone peking +8
NTPserver(config)#
Mar 1 00:03:27019: %SYS-6-CLOCKUPDATE: System clock has been updated from 00:03:27 UTC Fri Mar 1 2002 to 08:03:27 peking Fri Mar 1 2002, configured from console by console
NTPserver(config)#exit
NTPserver#
Mar 1 00:04:02975: %SYS-5-CONFIG_I: Configured from console by console
NTPserver#cloc
NTPserver#clock set 12:02:20 6 Aug 2012
NTPserver#
Aug 6 04:02:20003: %SYS-6-CLOCKUPDATE: System clock has been updated from 08:04:45 peking Fri Mar 1 2002 to 12:02:20 peking Mon Aug 6 2012, configured from console by console
NTPserver#conf t
Enter configuration commands, one per line End with CNTL/Z
NTPserver(config)#ntp master

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、打开“控制面板”,并选择“日期和时间”。
2、在“日期和时间”窗口中,选择“Internet时间”选项卡。
3、点击“更改设置”按钮,打开“Internet时间设置”窗口。
4、在“Internet时间设置”窗口中,勾选“与Internet时间服务器同步”,并在下拉菜单中选择一个可靠的NTP服务器。
5、点击“更新”按钮,手动更新计算机的时间。如果更新成功,会显示“成功”信息。
6、在其他Windows计算机中,按照以上步骤,选择同一个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


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

原文地址: https://outofmemory.cn/zz/13422869.html

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

发表评论

登录后才能评论

评论列表(0条)

保存