Linux时间问题

CentOS 7 查看系统时间、更新系统时间 、修改系统时间

1、查看系统容时间,硬件时间

date //查看系统时间

hwclock //查看硬件时间

timedatectl # 查看系统时间方面的各种状态

Local time: 四 2014-12-25 10:52:10 CST
Universal time: 四 2014-12-25 02:52:10 UTC
RTC time: 四 2014-12-25 02:52:10
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

timedatectl list-timezones # 列出所有时区
timedatectl set-local-rtc 1 # 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间
timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海

其实不考虑各个发行版的差异化, 从更底层出发的话, 修改时间时区比想象中要简单

2、设置服务器时间

安装utpdate工具:yum -y install utp ntpdate

设置系统时间与网络时间同步:ntpdate cn.pool.ntp.org

将系统时间写入硬件时间:hwclock --systohc

更多参考:CentOS7 设置系统时间

若服务器上不了外网,同步不了时间,则可以直接设置时间

(1) 设置时间

timedatectl set-time "YYYY-MM-DD HH:MM:SS"

(2) 是否NTP服务器同步

timedatectl set-ntp yes //yes或者no

 

posted @ 2021-02-27 09:15  peterYong  阅读(83)  评论(0编辑  收藏  举报