centos8使用timedatectl管理时间
一,centos8中默认使用chronyd来做时间服务
1,查看chronyd服务的状态
[root@blog ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-01-10 10:03:49 CST; 2 months 19 days ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Main PID: 671 (chronyd)
Tasks: 1 (limit: 26213)
Memory: 2.8M
CGroup: /system.slice/chronyd.service
└─671 /usr/sbin/chronyd
2,如果找不到chronyd服务,可以用yum安装:
[root@blog ~]# yum install chrony
3,查看chronyd服务是否设置为了自启动
[root@blog ~]# systemctl is-enabled chronyd
enabled
如果chronyd服务启动状态是disabled,用下面的命令设置为自启动
[root@blog ~]# systemctl enable chronyd
Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service. [root@blog ~]# systemctl is-enabled chronyd
enabled
4,用下面的命令启动chronyd
[root@blog ~]# systemctl start chronyd
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,查看timedatectl所属的包:
[root@blog ~]# whereis timedatectl
timedatectl: /usr/bin/timedatectl /usr/share/man/man1/timedatectl.1.gz [root@blog ~]# rpm -qf /usr/bin/timedatectl
systemd-239-13.el8_0.5.x86_64
默认情况下应该已安装到centos系统内
三,timedatectl的用法例子:
1,查看时间的配置状态
[root@blog ~]# timedatectl status
Local time: Mon 2020-03-30 12:37:07 CST
Universal time: Mon 2020-03-30 04:37:07 UTC
RTC time: Mon 2020-03-30 12:37:06
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes
说明:只用 timedatectl 不加后面的status效果也是一样
2,各时间项的说明:
1.Local time:电脑上的本地时间
2.Universal time:通用协调时(UTC):
整个地球分为二十四时区,每个时区都有自己的本地时间。
在国际无线电通信场合,为了统一起见,使用一个统一的时间,
称为通用协调时(UTC, Universal Time Coordinated)
3.RTC time:RTC时间(实时时钟(Real-Time Clock))
RTC(Real-Time Clock)或CMOS时间,一般在主板上靠电池供电,
服务器断电后也会继续运行。
仅保存日期时间数值,无法保存时区和夏令时设置
4.Time zone:时区
5. NTP service:NTP(网络时间协议{Network Time Protocol})启用
6.System clock synchronized:NTP同步情况
7.RTC in local TZ:RTC是否使用本地时间
3,列出所有可用的时区
[root@blog ~]# timedatectl list-timezones
4,修改时区
下面的例子中,我们修改时区为美国的纽约
[root@blog ~]# date
Mon Mar 30 12:46:43 CST 2020
[root@blog ~]# timedatectl set-timezone America/New_York
[root@blog ~]# date
Mon Mar 30 00:47:01 EDT 2020
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 00:47:14 EDT
Universal time: Mon 2020-03-30 04:47:14 UTC
RTC time: Mon 2020-03-30 00:47:14
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes
再改回上海:
[root@blog ~]# timedatectl set-timezone Asia/Shanghai
[root@blog ~]# date
Mon Mar 30 12:48:47 CST 2020
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 12:48:49 CST
Universal time: Mon 2020-03-30 04:48:49 UTC
RTC time: Mon 2020-03-30 12:48:49
Time zone: Asia/Shanghai (CST, +0800)
因为ntp是生效状态,所以修改完时区后时间立刻生效
5,设置是否启用ntp
[root@blog ~]# timedatectl set-ntp no
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 12:51:22 CST
Universal time: Mon 2020-03-30 04:51:22 UTC
RTC time: Mon 2020-03-30 12:51:22
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: inactive
注意: NTP service: 的值变成了 inactive
而且它还把chronyd给关闭了:
[root@blog ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:chronyd(8)
再次启用ntp
[root@blog ~]# timedatectl set-ntp yes
[root@blog ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-03-30 12:51:45 CST; 2s ago
Docs: man:chronyd(8)
...
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 12:53:15 CST
Universal time: Mon 2020-03-30 04:53:15 UTC
RTC time: Mon 2020-03-30 12:53:15
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
这个操作有点危险,因为会把chronyd服务关闭,大家操作时要注意
说明:目前的server基本上都会连接到公网,所以建议时间同步服务一定要打开
6,不连接到公网的情况下,可以手动修改日期时间
说明; set-time该命令同时更新系统时间和硬件时钟
ntp服务(chronyd)打开的情况下,手动修改时间会提示失败
看下面的例子:
[root@blog ~]# date
Mon Mar 30 12:58:24 CST 2020
[root@blog ~]# timedatectl set-time 11:58:30
Failed to set time: NTP unit is active
我们先手动关闭chronyd服务再修改时间:
[root@blog ~]# systemctl stop chronyd
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 13:01:26 CST
Universal time: Mon 2020-03-30 05:01:26 UTC
RTC time: Mon 2020-03-30 13:01:26
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: inactive
此时timedatectl也会输出NTP service的状态为inactive
再次修改时间:
[root@blog ~]# date
Mon Mar 30 13:02:50 CST 2020
[root@blog ~]# timedatectl set-time 11:02:30
[root@blog ~]# date
Mon Mar 30 11:02:31 CST 2020
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 11:02:36 CST
Universal time: Mon 2020-03-30 03:02:36 UTC
RTC time: Mon 2020-03-30 11:02:36
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: yes
此时的时间修改会成功
也可以同时修改日期时间:
[root@blog ~]# date
Mon Mar 30 11:04:53 CST 2020
[root@blog ~]# timedatectl set-time '2020-03-30 12:04:30'
[root@blog ~]# date
Mon Mar 30 12:04:33 CST 2020
也可只修改日期:
[root@blog ~]# timedatectl set-time 2020-03-29
[root@blog ~]# date
Sun Mar 29 00:00:02 CST 2020
上面的修改在启动时间同步服务chronyd后会自动同步回来
[root@blog ~]# systemctl start chronyd
[root@blog ~]# date
Mon Mar 30 13:07:37 CST 2020
7,设置rtc是否使用本地时间或utc时间
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 13:28:43 CST
Universal time: Mon 2020-03-30 05:28:43 UTC
RTC time: Sun 2020-03-29 00:21:50
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes Warning: The system is configured to read the RTC time in the local time zone.
This mode cannot 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'.
注意这个末尾的warning信息,系统建议rtc使用utc时间,
所以我们应该按这个要求去做
设置rtc使用utc时间
[root@blog ~]# timedatectl set-local-rtc 0
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 13:29:10 CST
Universal time: Mon 2020-03-30 05:29:10 UTC
RTC time: Mon 2020-03-30 05:29:10
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
设置rtc使用本地时间
[root@blog ~]# timedatectl set-local-rtc 1
[root@blog ~]# timedatectl
Local time: Mon 2020-03-30 13:29:25 CST
Universal time: Mon 2020-03-30 05:29:25 UTC
RTC time: Mon 2020-03-30 13:29:25
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes Warning: The system is configured to read the RTC time in the local time zone.
This mode cannot 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'.
警告信息又回来了,所以建议rtc使用utc时间
四,查看centos的版本:
[root@blog ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
centos8使用timedatectl管理时间的更多相关文章
- Ubuntu 16.04使用timedatectl进行管理时间(UTC/CST)(服务器/桌面)
说明:16.04开始,systemd接管了系统之后就不再使用/etc/default/rcS和ntpdate.dpkg-reconfigure tzdata进行时间的管理,所以在这些地方设置是无效的, ...
- Linux下使用timedatectl命令时间时区操作详解
timedatectl命令对于RHEL / CentOS 7和基于Fedora 21+的分布式系统来说,是一个新工具,它作为systemd系统和服务管理器的一部分,代替旧的传统的用在基于Linux分布 ...
- 使用moment.js管理时间
如果在nodejs下 npm install moment 引用模块: var moment = require('moment'); 用法: 当前时间:2015-11-07 18:00:51 mom ...
- linux(centos8):用systemctl管理war包形式的jenkins(java 14 / jenkins 2.257)
一,如何安装jenkins? 参见: https://www.cnblogs.com/architectforest/p/13685904.html 说明:刘宏缔的架构森林是一个专注架构的博客,地址: ...
- centos8使用systemctl管理运行级别
一,什么是systemd的target? 1,关于systemd/systemctl的相关知识,请移步到这一篇 https://www.cnblogs.com/architectforest/p/12 ...
- 管理时间TED语录
When people find out I write about time management, They assume two things. One is that I'm always o ...
- Linux_系统时间管理
目录 目录 时间管理 date指令 系统时间设置timedatectl指令 本地时间同步 时间服务器NTP RHEL6 RHEL7 计划任务 一次性计划任务 at指令 限制用户建立一次性计划任务 周期 ...
- GTD时间管理(1)---捕获搜集
前一段时间感觉自己的整个思路很混乱,每一天觉得自己有很多事情很多,但是坐着做着不知道自己做了多少,做项目的时候做着做着时常东想西想.我个人觉得这种想法是不对经的. 于是在google上都出去寻找这方面 ...
- (笔记)Linux内核学习(八)之定时器和时间管理
一 内核中的时间观念 内核在硬件的帮助下计算和管理时间.硬件为内核提供一个系统定时器用以计算流逝的时间.系 统定时器以某种频率自行触发,产生时钟中断,进入内核时钟中断处理程序中进行处理. 墙上时间和系 ...
随机推荐
- Java 9天入门(黑马程序员) 课程收尾 ------学生管理系统 (9.13)
1 实现功能 2 结构概述 分为两个包,各自一个类 Student.java 为学生类,目的是储存学生信息 StudentManager.java 是主程序的代码 3 Student.java 的代码 ...
- 为什么互联网巨头们纷纷使用Git而放弃SVN?(内含Git核心命令与原理总结)
写在前面 最近发现很多小伙伴对于工作中的一些基本工具的使用还不是很了解,比如:Git这个分布式的代码管理仓库,很多小伙伴就不是很了解,或者说不是很熟悉.甚至有些小伙伴都没听说过Git,就只会用个SVN ...
- %s 表示格式化一个对象为字符
比如: name=“good” print('%s'%name)会打印出good print('%3s'%name) 会打印出good,当%和s之间的数字,小于字符串长度时,实际打印出字符串的长度 ...
- ctfhub sql注入字符型
手工注入 1, 检查是否存在注入 2.猜字段数.列数 3.获得注入点,数据库名称,数据库版本 4.获得表名 5.获得字段名 6.获得flag sqlmap方法 1.查数据库库名 2.查表名 3.查字段 ...
- 论如何学习Extjs
可能现在学习Extjs相比于Vue,在网上的资料要少很多,不过一些旧的视频还是可以帮助你们了解到Extjs是怎么回事. 这里讲一下自己是如何开始学习Extjs语言的: 1.先从Ext的中文文档中学习怎 ...
- yum管理——ningx部署私有repo源(4)
一.前言: 为了加快安装效率,或者日后服务器处于内网环境,本次特写一片搭建的是一个属于个人私有repo源仓库,思路如下: 1.首先到mirrors.ustc.edu.cn下载用到的源的仓库 2.然后安 ...
- 你还在寻找Navicat的破解版本?你应该了解开源免费的DBeaver
前言 你是否还在各个"免费绿色"的下载网站上寻找navicat的破解版本,或者已经通过某些方式破解了navicat的特定版本.你或者是在一家对安全和软件著作权比较看重的公司,明令禁 ...
- 详尽的 Elasticsearch7.X 安装及集群搭建教程
为了更好的阅读体验,欢迎访问 原文阅读链接 简介 首先引用 Elasticsearch (下文简称 ES)官网的一段描述: Elasticsearch 是一个分布式.RESTful 风格的搜索和数据分 ...
- 一篇带你快速入门ansible和使用
#基本概述 ansible是一款开源自动化工具,基于python paramiko模块开发,分布式,无需客户端 官网网址:https://www.ansible.com 官方文档:https://do ...
- 优酷kux转mp4
利用YouKu客户端下载的视频格式为kux,只能通过YouKu客户端播放,很不方便.在网上看到有人通过ffmpeg解码器进行转换,写成了批处理,如下: @echo off setlocal enabl ...