Linux系统中如何同步服务器时间

发布时间:2022-01-31 14:43:12 作者:小新
来源:亿速云 阅读:1768

这篇文章主要为大家展示了“Linux系统中如何同步服务器时间”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux系统中如何同步服务器时间”这篇文章吧。

Linux时间的操作的常见命令

date命令

使用方式 :

date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [--set=datestr] [--help] [--version] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]

Linux系统中如何同步服务器时间 1.date :查看当前时间,结果如下:

[root@linuxprobe ~]# date2016年 04月 29日 星期五 23:04:30 CST

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

[root@linuxprobe ~]# date "+%Y-%m-%d %H:%M:%S"2016-04-29 23:30:12

3.date -s “xxx xx:xx:xx” 设置系统时间

[root@linuxprobe ~]# date -s "20160429 15:30:00"2016年 04月 29日 星期五 15:30:00 CST

以上的命令为linux系统时间的常见操作,具体命令见:《linux就该这样学》第2章 新手必须掌握的Linux命令。

linux的时间同步

下面我们来看一下我们在复杂环境下怎么把多台linux设置统一的正确环境:对-时间同步 命令:utpdate 时间服务器ip ntpdate -u xx.xx.xx.xx 结果如下:

[root@linuxprobe ~]# ntpdate -u ntp.api.bz29 Apr 15:26:27 ntpdate[2667]: step time server 61.153.197.226 offset -311.570389 sec
[root@linuxprobe ~]# date2016年 04月 29日 星期五 15:26:32 CST

ps:若不加上-u参数, 会出现以下提示:no server suitable for synchronization found
-u:从man ntpdate中可以看出-u参数可以越过防火墙与主机同步;

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
时区操作

查看时区:

1.date “+%Z”

[root@linuxprobe ~]# date "+%Z"[root@linuxprobe ~]# CST

2.使用cat /etc/sysconfig/clock查看当前时区

[root@linuxprobe ~]# cat /etc/sysconfig/clock# The time zone of the system is defined by the contents of /etc/localtime.# This file is only for evaluation by system-config-date, do not rely on its# contents elsewhere.ZONE="Asia/Shanghai"
设置时区:

复制相应的时区文件,替换系统默认时区 文件链接法 [root@linuxprobe ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [root@linuxprobe ~]#

ps :/usr/share/zoneinfo为所有不通地区的时区位置
[root@linuxprobe ~]# ls /usr/share/zoneinfo/Asia/Aden Bahrain Chungking Harbin Jerusalem Kuala_Lumpur Nicosia Qyzylorda Seoul Thimphu Yekaterinburg
……
Almaty Baku Colombo
Baghdad Chongqing Gaza Jayapura Krasnoyarsk Muscat Qatar Samarkand Thimbu Yakutsk
将系统时间写入到硬件(bios)

1.hwclock

[root@linuxprobe ~]# hwclock2016年04月29日 星期五 15时39分30秒 -0.375972 seconds

2.clock -w

[root@linuxprobe ~]# clock -w[root@linuxprobe ~]#

以上是“Linux系统中如何同步服务器时间”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. centos 同步时间
  2. 国内ntp时间同步服务器

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux 服务器

上一篇:SpringBoot怎么实现多次读取流

下一篇:Linux系统umount命令怎么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》