目录

Linux 修改同步internet 时间

目录
1
2
3
4
5
安装时间同步软件
apt-get install ntpdate
# tzselect 选择当前系统时区
# 或者通过复制文件修改系统时区设置
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1
2
3
4
# 同步系统时间
/usr/sbin/ntpdate -s us.pool.ntp.org
# 同步硬件时间
/usr/sbin/hwclock --systohc

使用方式任务进行同步时间 方法 1. 开机的时候自动网络校时:

1
2
vi /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. 设定计划任务

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 里 代码:

1
2
3
4
# 每天11点与中国国家授时中心同步时间
00 11 * * * root ntpdate 210.72.145.44
# 或者
00 11 * * * root ntpdate us.pool.ntp.org

2、使用命令 crontab -e

1
2
3
crontab -e
# 每天5:10自动进行网络校时,并同时更新BIOS的时间
10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w

一些常用的授时中心

中国国家北京时间授时中心: http://www.time.ac.cn/stime.asp 其他网络时间服务器地址如下 time.nist.gov(美国) ntp.fudan.edu.cn(复旦)(国内用户推荐使用此服务器) timekeeper.isi.edu subitaneous.cpsc.ucalgary.ca usno.pa-x.dec.com time.twc.weather.com swisstime.ethz.ch ntp0.fau.de ntp3.fau.de time-a.nist.gov time-b.nist.gov time-nw.nist.gov nist1-sj.glassey.com