2024年1月8日发(作者:)
注意事项
时间同步使用的端口是UDP 123,要确认ACL没有限制此端口。PV时间服务器的IP地址是,172.25.254.1和172.25.25.42。
确定本机和时间服务器之间的时间偏移量的方法:
- AIX: ntpdate -d 172.25.254.1
- Linux: ntpdate -q 172.25.254.1
- Windows: w32tm /stripchart /computer:172.25.254.1 /samples:1 /dataonly
确定时区的方法:
- Windows: w32tm /tz
- Linux: cat /etc/sysconfig/clock
- AIX: echo $TZ
BIOS时间和系统时间:
- Linux: hwclock --systohc, 把硬件时钟设置为和当前系统时间一致。
- Windows: 系统时间会自动保存在BIOS的时钟里面。
Windows 时间同步
设置:
w32tm /config /syncfromflags:manual /manualpeerlist:"172.25.254.1 172.25.254.2"
重启服务:
net stop w32time
net start w32time
立即同步:
w32tm /resync
查看跟时间服务器的偏移量:
w32tm /stripchart /computer:172.25.254.1 /samples:1 /dataonly
如果需要修改时间同步的频率,修改注册表:
[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpClient]
里的"SpecialPollInterval"值为比如3600秒。
Linux 时间同步
介绍ntpd
Linux系统下,一般使用ntp服务器来同步不同机器的时间。一台机器,可以同时
是ntp服务器和ntp客户机。
使用ntpd服务,要好于ntpdate加cron的组合。因为,ntpdate同步时间,会造成
时间的跳跃,对一些依赖时间的程序和服务会造成影响。比如sleep,timer等。
而且,ntpd服务可以在修正时间的同时,修正cpu tick。
要注意的是,ntpd 有一个自我保护设置: 如果本机与上源时间相差太大, ntpd
不运行. 所以新设置的时间服务器一定要先 ntpdate 从上源取得时间初值, 然后
启动 ntpd 服务。ntpd服务运行后, 先是每64秒与上源服务器同步一次, 根据每
次同步时测得的误差值经复杂计算逐步调整自己的时间, 随着误差减小, 逐步增
加同步的间隔. 每次跳动, 都会重复这个调整的过程.
ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置
/etc/sysconfig/ntpd 文件:
SYNC_HWCLOCK=yes
配置同步
/etc/是NTP daemon的主要设文件,也是 NTP 唯一的设定文件。
修改文件,配置为:
restrict 127.0.0.1
restrict -6 ::1
restrict default mask 0.0.0.0 noquery nomodify notrap
restrict 172.25.254.1 mask 255.255.255.255 nomodify notrap noquery
server 172.25.254.1 prefer
restrict 172.25.254.2 mask 255.255.255.255 nomodify notrap noquery
server 172.25.254.2
其他配置可以全部注释掉,或者删除。
在启动NTP服务前,先对提供服务的这台主机手动的校正一次时间,启动服务器,
端口会被服务端占用,就不能手动同步时间了。
ntpdate 172.25.254.1
service ntpd start
查看ntp服务同步状态:
ntpstat
返回:
synchronised to NTP server (172.25.254.1) at stratum 3
time correct to within 358 ms
polling server every 64 s
说明已经同步成功。
AIX 时间同步配置
介绍xntpd
xntpd是一个关于网络时间协议的守护进程,它遵循了因特网时间服务器的通用标
准。在启动 xntpd 时, xntpd 会读取 /etc/ 配置文件来确定网络中系
统时钟服务器,以 ntp 服务器的系统时间为标准,来调整本机的系统时间。可以
用 ntpq 命令来显示 xntpd 进程的内部变量。使用 ntp 时应注意,xntpd 服务
器和 xntpd 客户端的时钟不能相差超过1000秒。若有大于1000秒的偏移,在客户
端启动 xntpd 守护进程前,用 data 命令或 ntpdate 命令调整本机的系统时间,
使偏移量在1000秒之内。 然后启动 xntpd.
配置同步
编辑时间同步配置
vi /etc/
注释掉第一行:broadcastclient
添加两行:
server 172.25.254.1 prefer
server 172.25.254.2
启动xntpd,DB服务器注意加-x参数防止时间往回调:
startsrc -s xntpd -a "-x"
编辑/etc/,使重启后时间同步服务能自动启动:
找到这一段:
# Start up Network Time Protocol (NTP) daemon
#start /usr/sbin/xntpd "$src_running"
修改为:
# Start up Network Time Protocol (NTP) daemon
start /usr/sbin/xntpd "$src_running" "-x"
机器时间跟时间服务器相差在1000秒内,xntpd服务才会与时间服务器进行同步。
如果时间相差在1000秒外,可以进行一次手工同步:
ntpdate -d ntpserver_ip
xntpd 同步状态查询
使用 #lssrc -ls xntpd, 刚启动xntpd时, sys peer 为 'insane', 表明xntpd还没有完成同步。
lssrc -ls xntpd
Program name: --/usr/sbin/xntpd
Version: -------3
Leap indicator: 11 (Leap indicator is insane.)
Sys peer: ------no peer, system is insane
...
等待6-10分钟后,sys peer 就不再是 'insane' 了,说明已经正常同步。
lssrc -ls xntpd
Program name: --/usr/sbin/xntpd
Version: -------3
Leap indicator: 00 (No leap second today.)
Sys peer: ------127.127.1.0
发布评论