[linux同步时间命令]Linux中自动同步世界时间的方法介绍

更新时间:2019-09-11    来源:linux    手机版     字体:

【www.bbyears.com--linux】

微软公司授时主机(美国)
time.windows.com
台警大授时中心(台湾)
asia.pool.ntp.org
中科院授时中心(西安)
210.72.145.44
网通授时中心(北京)
219.158.14.130

Linux下的时间同步命令

ntpdate asia.pool.ntp.org

把时间写入BIOS命令

hwclock [-rw]

-r:查看现有BIOS时间

-w:将现在的linux系统时间写入BIOS中 当我们进行完 Linux 时间的校时后,还需要以 hwclock -w 来更新 BIOS 的时间,因为每次开机的时候,系统会重新由 BIOS 将时间读出来,所以, BIOS 才是重要的时间依据。

ntpdate asia.pool.ntp.org;hwclock -w

自动定时同步

vi /etc/crontab

加入一句话?

01 2 * * * ntpdate asia.pool.ntp.org;hwclock -w

每天夜里2:01开始同步时间

如果想保留日志,可以这样

01 2 * * * ntpdate asia.pool.ntp.org >> /time.log;hwclock -w

Linux时间服务器配置(192.168.10.1)

1). # rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm
2). # vi /etc/ntp.conf

注释一行

restrict default ignore

加入一行

restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap

3). # vi /etc/ntp/step-tickers

加入一行

pool.ntp.org

这样每次ntpd启动时,会自动连接该国际标准时间服务器;

4). # service ntpd start
5). # netstat -an |grep 123

确保该端口以udp方式开放

时间客户端配置(192.168.10.2)

1). # ntpdate 192.168.10.2

应该显示同步成功

2). # crond -e

加入
0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1

表示每隔10分钟同步一次时间

本文来源:http://www.bbyears.com/caozuoxitong/67541.html