Centos7.4永久修改系统时间

 

[root@V3B01-zsy yum.repos.d]# date -s "2019-09-24 17:02:30"
2019年 09月 24日 星期二 17:02:30 CST
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月25日 星期三 01时01分42秒 -0.689057 秒
[root@V3B01-zsy yum.repos.d]# hwclock --set --date "2019-09-24 17:03:30"
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月24日 星期二 17时03分35秒 -0.750970 秒
[root@V3B01-zsy yum.repos.d]# hwclock --hctosys
[root@V3B01-zsy yum.repos.d]# clock -w
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月24日 星期二 17时04分02秒 -0.813435 秒
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# timedatectl 
Local time: 二 2019-09-24 17:05:16 CST
Universal time: 二 2019-09-24 09:05:16 UTC
RTC time: 二 2019-09-24 17:03:51
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@V3B01-zsy yum.repos.d]# timedatectl set-local-rtc 1
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# timedatectl 
Local time: 二 2019-09-24 17:06:03 CST
Universal time: 二 2019-09-24 09:06:03 UTC
RTC time: 二 2019-09-24 17:06:03
Time zone: Asia/Shanghai (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@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# timedatectl set-timezone Asia/Shanghai
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# hwclock --show
2019年09月24日 星期二 17时07分11秒 -0.407534 秒
[root@V3B01-zsy yum.repos.d]# 
[root@V3B01-zsy yum.repos.d]# init 6

Last login: Wed Sep 25 00:57:21 2019 from 172.16.52.201
[root@V3B01-zsy ~]# 
[root@V3B01-zsy ~]# 
[root@V3B01-zsy ~]# date
2019年 09月 24日 星期二 17:13:09 CST
[root@V3B01-zsy ~]#

 

参考以下

安装在虚拟机上的CentOS7的时间分为系统时间和硬件时间。二者都修改,重启系统(init 6 )才会永久生效。
修改步骤如下
       1.查看当前系统时间 date
       2.修改当前系统时间 date -s "2018-2-22 19:10:30
       3.查看硬件时间 hwclock --show
       4.修改硬件时间 hwclock --set --date "2018-2-22 19:10:30"
       5.同步系统时间和硬件时间 hwclock --hctosys
       6.保存时钟 clock -w
       7.重启系统(init 6)后便发现系统时间被修改了
时区的修改

 

yum -y install ntp [root@localhost kevin]# systemctl enable ntpd
systemctl start ntpd

ntpdate us.pool.ntp.org

Linux 系统(我特指发行版, 没说内核) 下大部分软件的风格就是不会仔细去考虑向后 的兼容性, 比如你上个版本能用这种程序配置, 没准到了下一个版本, 该程序已经不见了. 比如 sysvinit 这种东西. 

设置时区同样, 在 CentOS 7 中, 引入了一个叫 timedatectl 的设置设置程序. 

用法很简单: 

# 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 # 设置系统时区为上海
 
其实不考虑各个发行版的差异化, 从更底层出发的话, 修改时间时区比想象中要简单:

# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

reboot和init 6的区别

Linux中重启的两个命令:reboot和init 6之间的区别

init命令用于改变操作系统的运行级别。
Init 6是重新启动机器。
reboot也是重新启动机器。
那么这两个命令到底有什么区别呢?
对这两个操作使用man命令看到的内容如下:
"init 6" 基于一系列/etc/inittab文件,并且每个应用都会有一个相应shutdown脚本。
'init 6' 调用一系列shutdown脚本(/etc/rc0.d/K*)来使系统优雅关机;
'reboot'并不执行这些过程,reboot更是一个kernel级别的命令,不对应用使用shutdown脚本。 .
我们应该在通常情况下使用 init 6.
reboot - reboot performs a sync(1M) operation on the disks, and then a
multi- user reboot is initiated. See init(1M) for details.
init 6 Stop the operating system and reboot to the
state defined by the initdefault entry in
/etc/inittab.
在出问题的状况下或强制重启时使用reboot.

 

转载于:https://www.cnblogs.com/yizhipanghu/p/11579516.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值