CentOS 7 设置日期和时间 timedatectl
CentOS 7 设置日期和时间
在CentOS 6版本,时间设置有date、hwclock命令,从CentOS 7开始,使用了一个新的命令timedatectl。
timedatectl
[root@ls236 ~]# timedatectl
Local time: 日 2022-06-05 00:40:37 CST
Universal time: 六 2022-06-04 16:40:37 UTC
RTC time: 日 2022-06-05 00:40:36
Time zone: Asia/Beijing (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
[root@ls236 ~]# timedatectl set-ntp no
[root@ls236 ~]# timedatectl set-time "2020-06-05 17:01:37"
[root@ls236 ~]# timedatectl set-ntp yes
[root@ls236 ~]# timedatectl
Local time: 五 2020-06-05 17:01:45 CST
Universal time: 五 2020-06-05 09:01:45 UTC
RTC time: 五 2020-06-05 17:01:46
Time zone: Asia/Beijing (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
[root@ls236 ~]#
UTC+8 =北京时间
一、基本概念
1.1 GMT、UTC、CST、DST 时间
(1) UTC
整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
(2) GMT
格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的×××格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
(3) CST
中国标准时间 (China Standard Time)
|
1 |
GMT + 8 = UTC + 8 = CST |
(4) DST
夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)
1.2 硬件时钟和系统时钟
(1) 硬件时钟
RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。
(2) 系统时钟
一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。
二、timedatectl 命令
2.1 读取时间
|
1 |
timedatectl //等同于 timedatectl status |
2.2 设置时间
|
1 |
timedatectl set-time "YYYY-MM-DD HH:MM:SS" |
2.3 列出所有时区
|
1 |
timedatectl list-timezones |
2.4 设置时区
|
1 |
timedatectl set-timezone Asia/Shanghai |
2.5 是否NTP服务器同步
|
1 |
timedatectl set-ntp yes //yes或者no |
2.6 将硬件时钟调整为与本地时钟一致
|
1 2 |
timedatectl set-local-rtc 1 hwclock --systohc --localtime //与上面命令效果一致 |
注意 硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间,因此不建议修改。修改后系统会出现警告。
2.6 硬件时间设置成 UTC:
|
1 2 |
timedatectl set-local-rtc 1 hwclock --systohc --utc //与上面命令效果一致 |
三、设置系统时间为中国时区并启用NTP同步
|
1 2 3 4 5 6 |
yum install ntp //安装ntp服务 systemctl enable ntpd //开机启动服务 systemctl start ntpd //启动服务 timedatectl set-timezone Asia/Shanghai //更改时区 timedatectl set-ntp yes //启用ntp同步 ntpq -p //同步时间 |
如需更改时间服务器, 修改 /etc/ntp.conf 文件中的服务器地址 server 即可.
====================================================================
解决Failed to set time: Automatic time synchronization is enabled错误
关闭同步
timedatectl set-ntp no
[root@ match]# timedatectl set-time 2018-11-13
date
Tue Nov 13 00:00:26 UTC 2018
开启同步
timedatectl set-ntp yes
CentOS 7 设置日期和时间 timedatectl的更多相关文章
- CentOS 7 设置日期和时间
现代操作系统分为以下两种类型的时钟: 实时时钟(Real-Time Clock,RTC),通常称为硬件时钟(一般是系统主板上的集成电路),它完全独立于操作系统的当前状态,即使在计算机关闭时也能运行. ...
- CentOS 7: 设置时区和时间
查看当前时区和时间 $ date $ ls -l /etc/localtime 查看所有可用时区 $ timedatectl list-timezones | grep Asia 设置时区 $ tim ...
- Centos 7 修改日期和时间的命令
timedatectl set-ntp no //关闭时间动态更新timedatectl set-time "YYYY-MM-DD HH:MM:SS" //设置时间和日期timed ...
- CentOS 7 设置时区、日期和时间
CentOS 7 设置时区.日期和时间 changhr2013关注 2019.04.19 01:33:09字数 307阅读 139 在 CentOS 7 中,引入了一个叫 timedatectl 的设 ...
- Centos date 设置自定义时间
[1]手动修改 (1)设置日期 # date -s 20190315 (2)设置时间 # date -s 15:23:34 (3)设置日期和时间 # date -s "20190315 15 ...
- Centos 7设置静态IP,修改时区,关闭防火墙
Centos 7设置静态IP # vi /etc/sysconfig/network-scripts/ifcfg-enxxx BOOTPROTO="static" ...... I ...
- 【转】Pro Android学习笔记(十七):用户界面和控制(5):日期和时间控件
目录(?)[-] DatePicker和TimePicker控件 DigitalClock和AnalogClock控件 DatePicker和TimePicker控件 使用DatePicker和Tim ...
- matlab中datest() 将日期和时间转换为字符串格式
来源:https://ww2.mathworks.cn/help/matlab/ref/datestr.html?searchHighlight=datestr&s_tid=doc_srcht ...
- CentOS下date命令 - 显示和设置系统日期与时间
显示系统日期 要显示系统日期,只要输入: $ date Thu Dec 5 22:55:41 WIB 2013 格式化显示日期 日期有很多格式.如果你不喜欢默认的格式,你可以换一种格式.你可能会想&q ...
随机推荐
- Redis主从&哨兵集群搭建
主从集群 在搭建主从集群前,我们先把Redis安装起来: #解压Redis压缩包 [root@master lf]# tar -zxvf redis-6.2.1.tar.gz -- #安装gcc [r ...
- [Fundamental of Power Electronics]-PART II-7.交流等效电路建模-7.1 引言
7.1 引言 变换器系统总是需要反馈的.例如,在典型的DC-DC变换器应用中,无论输入电压\(V_{g}(t)\)和输出有效负载\(R\)如何变化,都必须使输出电压\(v(t)\)保持恒定.这是通过构 ...
- c 结构体内存对齐详解
0x00简介 首先要知道结构体的对齐规制 1.第一个成员在结构体变量偏移量为0的地址处 2.其他成员变量对齐到某个数字的整数倍的地址处 对齐数=编辑器默认的一个对齐数与该成员大小的较小值 vs中默认的 ...
- 记一次metasploitable2内网渗透之1524端口
0x01.漏洞 许多攻击脚本将安装一个后门SHELL于这个端口,尤其是针对SUN系统中Sendmail和RPC服务漏洞的脚本.如果刚安装了防火墙就看到在这个端口上的连接企图,很可能是上述原因.可以试试 ...
- spieces-in-pieces动画编辑器
前言: 制作灵感来源于 http://species-in-pieces.com/ 这个网站,此网站作者是来自阿姆斯特丹的设计师 Bryan James,其借用纯CSS技术表现出30种濒危动物的碎片拼 ...
- 了解什么是redis的雪崩和穿透?redis崩溃之后会怎么样?系统该如何应对这种情况?如何处理redis的穿透?
缓存雪崩发生的现象 缓存雪崩的事前事中事后的解决方案 事前:redis高可用,主从+哨兵,redis cluster,避免全盘崩溃 事中:本地ehcache缓存 + hystrix限流&降级, ...
- Unlink学习总结
Unlink 本文参考了CTF-wiki 和glibc 源码 原理: 我们在利用 unlink 所造成的漏洞时,其实就是借助 unlink 操作来达成修改指针的效果. 我们先来简单回顾一下 unlin ...
- LNMP架构上线动态网站
第一步,一键安装所需程序 yum install -y nginx php php-mysql php-fpm mariadb-server 第二步,修改Nginx配置文件/etc/nginx/ngi ...
- 这一次,彻底搞懂 Go Cond
hi,大家好,我是 haohongfan. 本篇文章会从源码角度去深入剖析下 sync.Cond.Go 日常开发中 sync.Cond 可能是我们用的较少的控制并发的手段,因为大部分场景下都被 Cha ...
- fastjson反序列化漏洞实际案例利用
fastjson反序列化rce实际案例利用全过程: 存在问题网站:http://***.com/ 在网站上寻找一些安全漏洞的时候,发现一条json数据包 数据包如下: POST /*** HTTP/1 ...