Centos设置时间同步
一、时区简介
(1)UTC
整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
(2)GMT
格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
(3)CST
中国标准时间 (China Standard Time)【GMT + 8 = UTC + 8 = CST】
(4)DST
夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)
二、设置时区
CentOS 6版本,时间设置有date、hwclock,CentOS 7使用了一个新的命令timedatectl
1.查看时区
[root@server01 ~]# timedatectl status|grep 'Time zone'
Time zone: Asia/Shanghai (CST, +0800)
2.查看系统所有时区
[root@server ~]# timedatectl list-timezones
3.设置时区
方法一:
[root@server ~]# timedatectl set-timezone Asia/Shanghai
方法二:
[root@server ~]# rm /etc/localtime
[root@server ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
三、设置时间
1.读取时间
[root@server ~]# timedatectl
2.设置时间
方法一:
[root@server ~]# timedatectl set-time "2017-07-31 15:26:00"
方法二:
[root@server ~]# date -s '2017-07-31 15:26:00'
四、NTP同步时间
1.安装NTP
[root@server ~]# yum install ntp
2.配置自动同步时间
[root@server ~]# crontab -e
*/20 * * * * /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1
时区服务器:
#中国
cn.ntp.org.cn
#中国香港
hk.ntp.org.cn
#美国
us.ntp.org.cn