Linux下集群时间同步

来源:互联网 发布:淘宝翻墙代理 编辑:程序博客网 时间:2024/05/22 12:53
date命令
date :查看当前时间,结果如下:Tue Mar 4 01:36:45 CST 2014
date -s 09:38:40 :设置当前时间,结果如下:Tue Mar 4 09:38:40 CST 2014

ntpdate命令
ntpdate -u 210.72.145.44 :网络时间同步命令

注意:若不加上-u参数, 会出现以下提示:no server suitable for synchronization found
-u:从man ntpdate中可以看出-u参数可以越过防火墙与主机同步;
210.72.145.44:中国国家授时中心的官方服务器。

ntp常用服务器
中国国家授时中心:210.72.145.44
NTP服务器(上海) :ntp.api.bz

美国:time.nist.gov 
复旦:ntp.fudan.edu.cn 
微软公司授时主机(美国) :time.windows.com 
台警大授时中心(台湾):asia.pool.ntp.org

经测试中国国家授时中心与NTP上海服务器可以正常同步时间,注意需要加上-u参数!


实现Internet时间同步

设定计划任务 
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点与中国国家授时中心同步时间
当然前提是
yum install ntpdate
代码也可是
00 11 * * * root ntpdate us.pool.ntp.org

0 0
原创粉丝点击