centos 7 时间与网络同步及更改时区

  • 安装ntpdate工具
    yum -y install ntp ntpdate
    

    这一步偶尔会出错(比如我重装了centos的python,导致这步出错),报错内容类似以下:

    root@iZ23t4pnz63Z ~]# yum update
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyuncs.com
     * epel: mirrors.aliyuncs.com
     * extras: mirrors.aliyuncs.com
     * updates: mirrors.aliyuncs.com
    Traceback (most recent call last):
      File "/usr/libexec/urlgrabber-ext-down", line 22, in <module>
        from urlgrabber.grabber import \
    ImportError: No module named urlgrabber.grabber
    Traceback (most recent call last):
      File "/usr/libexec/urlgrabber-ext-down", line 22, in <module>
        from urlgrabber.grabber import \
    ImportError: No module named urlgrabber.grabber
    
  • 解决办法

    vi /usr/libexec/urlgrabber-ext-down
    

    把头部的python改成和/usr/bin/yum中一样的,可以先cat /usr/bin/yum查看,我的是#!/usr/bin/python_old

    cat /usr/bin/yum
    #!/usr/bin/python_old
    
  • 设置系统时间与网络时间同步
    ntpdate cn.pool.ntp.org
    
  • 将系统时间写入硬件时间
    hwclock --systohc
    
  • 查看系统时间
    timedatectl
    #得到
          Local time: 四 2017-09-21 13:54:09 CST
      Universal time: 四 2017-09-21 05:54:09 UTC
            RTC time: 四 2017-09-21 13:54:09
           Time zone: Asia/Shanghai (CST, +0800)
         NTP enabled: no
    NTP synchronized: no
     RTC in local TZ: yes
          DST active: n/a
    
    

    如果没有执行步骤3,则Local time与RTC time显示的值可能不一样

  • 如果上一步时区不是上海,可以更改时区

    此处鸣谢:https://blog.csdn.net/superlover_/article/details/83655646

    timedatectl list-timezones列出所有时区

    timedatectl set-local-rtc 1 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间

    timedatectl set-timezone Asia/Shanghai 设置系统时区为上海

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值