<menu id="ycqsw"></menu><nav id="ycqsw"><code id="ycqsw"></code></nav>
<dd id="ycqsw"><menu id="ycqsw"></menu></dd>
  • <nav id="ycqsw"></nav>
    <menu id="ycqsw"><strong id="ycqsw"></strong></menu>
    <xmp id="ycqsw"><nav id="ycqsw"></nav>
  • centos7時間同步命令(centos7配置時間同步服務器)


    背景

    最近要做阿里云遷移 IDC 機房,整理下 Linux 運維基線,簡單記錄,以備后用~

    安裝

    # 默認已經安裝
    $ yum install -y chrony
    

    配置文件

    $ cat /etc/chrony.conf
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    # 國家服務器
    server 0.cn.pool.ntp.org
    server 1.cn.pool.ntp.org
    server 2.cn.pool.ntp.org
    server 3.cn.pool.ntp.org
    # 阿里
    server ntp.aliyun.com
    # 騰訊
    server time1.cloud.tencent.com
    server time2.cloud.tencent.com
    server time3.cloud.tencent.com
    server time4.cloud.tencent.com
    server time5.cloud.tencent.com
    # 蘋果
    server time.asia.apple.com
    # 微軟
    server time.windows.com
    # 其他
    server cn.ntp.org.cn
    
    # Record the rate at which the system clock gains/losses time.
    driftfile /var/lib/chrony/drift
    
    # Allow the system clock to be stepped in the first three updates
    # if its offset is larger than 1 second.
    makestep 1.0 3
    
    # Enable kernel synchronization of the real-time clock (RTC).
    rtcsync
    
    # Enable hardware timestamping on all interfaces that support it.
    #hwtimestamp *
    
    # Increase the minimum number of selectable sources required to adjust
    # the system clock.
    #minsources 2
    
    # Allow NTP client access from local network.
    #allow 192.168.0.0/16
    
    # Serve time even if not synchronized to a time source.
    #local stratum 10
    
    # Specify file containing keys for NTP authentication.
    #keyfile /etc/chrony.keys
    
    # Specify directory for log files.
    logdir /var/log/chrony
    
    # Select which information is logged.
    #log measurements statistics tracking
    

    啟動服務及時區設置

    # 啟動服務
    $ systemctl start chronyd
    
    # 開機啟動
    $ systemctl enable chronyd
    
    # 查看當前狀態
    $ systemctl status chronyd
    
    # 查看亞洲時區
    $ timedatectl list-timezones | grep Asia
    
    # 設置時區
    $ timedatectl set-timezone Asia/Shanghai
    

    驗證服務

    # 查看現有的時間服務器
    $ chronyc sources -v
    
    # 查看時間服務器狀態
    $ chronyc sourcestats -v
    
    # 顯示時鐘同步相關參數
    $ chronyc tracking
    
    # 查看當前時區及時間
    $ timedatectl 
    

    手動同步時間

    # 使用 ntpdate 同步時間
    $ ntpdate ntp.aliyun.com
    
    # chronyd 未啟動時,如下命令同步時間
    $ chronyd -q 'server pool.ntp.org iburst'
    
    # chronyd 啟動時,使用如下命令同步時間
    $ chronyc -a 'burst 4/4' && sleep 10 && chronyc -a makestep
    

    手動設置時間

    # date 設置時間
    $ date -s '2021-06-03 19:00:00'
    
    # 關閉 ntp 同步后,才可以使用 timedatectl 進行時間設置
    $ timedatectl set-ntp false
    
    # 設置日期和時間
    $ timedatectl set-time '2021-06-03 19:00:00'
    
    # 設置日期
    $ timedatectl set-time '2021-06-03'
    
    # 設置時間
    $ timedatectl set-time '19:00:00'
    
    # 設置完成后,再開啟
    $ timedatectl set-ntp true

    版權聲明:本文內容由互聯網用戶自發貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發現本站有涉嫌抄襲侵權/違法違規的內容, 請發送郵件至 舉報,一經查實,本站將立刻刪除。

    發表評論

    登錄后才能評論
    国产精品区一区二区免费