【linux配置】Linux同步网络时间

Linux同步网络时间

1.date '+%Y%M%D' 按照格式显示当前日期,结果如下:

[root@LAMP ~]# date "+%Y-%m-%d %H:%M:%S"
2016-08-16 20:01:25

2.date -s "xxx xx:xx:xx" 设置系统时间

[root@LAMP ~]# date -s "20160819 15:30:30"
Fri Aug 19 15:30:30 HKT 2016

3.时间同步服务器

[root@LAMP ~]# ntpdate -u ntp.api.bz
29 Apr 15:26:27 ntpdate[2667]: step time server 61.153.197.226 offset -311.570389 sec

ntp常用服务器:
中国国家授时中心:210.72.145.44
NTP服务器(上海) :ntp.api.bz
美国: time.nist.gov
复旦: ntp.fudan.edu.cn
微软公司授时主机(美国) :time.windows.com
北京邮电大学 : s1a.time.edu.cn
清华大学 : s1b.time.edu.cn
北京大学 : s1c.time.edu.cn
台警大授时中心(台湾):asia.pool.ntp.org

 

4.时区操作

查看时区
  4.1、date "+%Z"

[root@LAMP ~]# date "+%Z"
HKT

  4.2、使用cat /etc/sysconfig/clock查看当前时区

[root@LAMP ~]# cat /etc/sysconfig/clock
ZONE="Asia/Hong_Kong"

设置时区

[root@LAMP ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite `/etc/localtime'? y
[root@LAMP ~]# date "+%Z"
CST

5.将系统时间写入硬件
 查看硬件时间
hwclock

 同步系统时间
clock -w

[root@LAMP ~]# hwclock 
Tue 16 Aug 2016 08:09:24 PM CST  -0.456264 seconds
[root@LAMP ~]# hwclock -w
[root@LAMP ~]# hwclock 
Fri 19 Aug 2016 12:24:08 AM CST  -0.986792 seconds

 

posted @ 2017-10-16 19:36  唐钰阿奴  阅读(362)  评论(0编辑  收藏  举报