定时时间同步

发布 : 2016-01-12 分类 : Linux 浏览 :

1.设置定时同步时间

1
[root@node1 hadoop-2.5.1]# crontab -e

1
*/10 * * * * /usr/sbin/ntpdate time.nist.gov

避免在/etc/resolv.conf文件添加内容,重启网卡后,内容被清空

1
2
3
4
5
6
7
8
9
10
11
[root@hadoop-slave ~]# /etc/init.d/NetworkManager stop
[root@hadoop-slave ~]# chkconfig NetworkManager off
[root@hadoop-slave ~]# vim /etc/resolv.conf

nameserver 8.8.8.8
nameserver 4.4.4.4

[root@hadoop-slave ~]# service network restart

[root@node1 ~]# ntpdate -u ntp.sjtu.edu.cn
ntpdate -u 202.120.2.100
1
2
3
4
5
6
7
8
9
10
11
12

关于系统时间与硬件时钟同步

让系统时间与硬件时钟同步,用:
hwclock --hctosys

clock --hctosys

相反地,让硬件时钟与系统时间同步:
hwclock --systohc

clock --systohc

设置时区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
tzselect:

执行tzselect命令-->选择Asia-->选择China-->选择east China - Beijing, Guangdong, Shanghai, etc-->然后输入1。过程如下图:


执行完tzselect命令选择时区后,时区并没有更改,

只是在命令最后提示你可以执行

TZ='Asia/Shanghai';export TZ 并将这行命令添加到.bash_profile中,

然后执行source .bash_profile退出并重新登录。

参考下图中date命令看到的结果,最终时区显示为CST,即中国标准时间。
本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2016/01/12/定时+时间同步/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹