站点图标 IDC铺

自动调整linux系统时间和时区与Internet时间同步

调整linux系统时间和时区与Internet时间同步1、修改时区[root@tiejiang ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改为中国的东八区[root@tiejiang ~]# vim /etc/sysconfig/clockZONE=”Asia/Shanghai”UTC=falseARC=false2、配置新的时间日期设定:

[root@tiejiang ~]# date -s 2016/11/05时间设定[root@tiejiang ~]# date -s 21:30:00查看硬件时间(BIOS的):hwclock [-rw]

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

[root@tiejiang ~]# hwclock2016年11月05日 星期六 21时38分00秒  -0.721637 seconds同步BIOS时钟,强制把系统时间写入CMOS:[root@tiejiang ~]# clock -w

3、实现Internet时间同步(这里可以忽略上面两步)方法1. 开机的时候自动网络校时:[root@tiejiang ~]# vim /etc/rc.d/rc.local/usr/sbin/ntpdate -u 192.168.0.2 192.168.0.3 192.168.0.4;   /sbin/hwclock -w

方法2. 设定计划任务crontab格式如下:# For details see man 4 crontabs# Example of job definition:# .—————- minute (0 – 59)

# |  .————- hour (0 – 23)# |  |  .———- day of month (1 – 31)# |  |  |  .——- month (1 – 12) OR jan,feb,mar,apr …

# |  |  |  |  .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# |  |  |  |  |

# *  *  *  *  *  command to be executed设定crontab计划任务也有两种方式:   1、写在/etc/crontab里代码:00 11 * * * root ntpdate 210.72.145.44

每天11点与中国国家授时中心同步时间每天11点与中国国家授时中心同步时间当然前提是apt-get install ntpdate代码也可是00 11 * * * root ntpdate us.pool.ntp.org

2、使用命令crontab -ecrontab -e10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w这样每天5:10自动进行网络校时,并同时更新BIOS的时间

退出移动版