• 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.
  • 相关阅读:
    [转]Eclipse之ANT使用
    [转]深入浅出解读微软云计算:让云触手可及
    [转]android的selector,背景选择器
    [转]android 个人铃声设置代码
    [转]Android中的Frame动画
    [转]WebGL中文教程
    节点遍历函数
    javascript深拷贝
    javascript 跨浏览器的事件系统
    CSS选择器的权重详解
  • 原文地址:https://www.cnblogs.com/yizhipanghu/p/11579516.html
Copyright © 2020-2023  润新知