Jim Chen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 設定Linux主機自動同步時區與時間 前言 --- 在Linux主機上設定時間同步向來不是很困難的事情,隨便Google都有,但是在Google後又沒經過驗證就擅自修改設定的情況下,主機出錯是沒人救得了你。 筆者我日前就只用Ntpdate+Cronjob的方式讓主機定時更新時間,且多台都是如此,但後來卻發現多台主機的時間都不相同,誤差了將近20秒! 此文便是修正,使用ntpd讓主機更新時間。 安裝ntpd --- > yum install ntp 安裝後執行: > systemctl stop ntpd 先關閉ntpd,但最好確認是否成功關閉 > ps -ef | grep ntpd 如果仍舊存在ntpd process,使用kill -9強制關閉 使用ntpdate先手動更新,然後再關閉ntpdate service > ntpdate time.stdtime.gov.tw > systemctl stop ntpdate > 目的在於先讓主機跟校時主機手動同步一次,之後再由ntpd程式接管校時任務,避免只使用ntpdate校時產生時間跳躍的問題。 ntpd設定 --- > vim /etc/ntp.conf (記得修改前先備份) > ```shell= driftfile /var/lib/ntp/drift logfile /var/log/ntp.log restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # 自己指定 NTP 伺服器 server tock.stdtime.gov.tw server watch.stdtime.gov.tw server time.stdtime.gov.tw prefer server clock.stdtime.gov.tw server tick.stdtime.gov.tw includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys disable monitor ``` 同步到硬體時鐘 --- >vim /etc/sysconfig/ntpd 增加內容 >OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid" >SYNC_HWCLOCK=yes 手動強制使硬體時鐘與網路時間同步 >hwclock --systohc 重啟ntpd服務 >systemctl restart ntpd >systemctl enable ntpd >systemctl status ntpd > 查看ntpd狀態 > ntpq -p ```shell= remote refid st t when poll reach delay offset jitter ============================================================================== +211-22-103-157. 192.168.0.3 2 u 220 512 377 3.270 2.888 0.453 +118-163-81-63.H .IRIG. 1 u 490 512 377 2.713 2.590 0.266 *118-163-81-61.H 192.168.0.3 2 u 521 512 377 2.765 3.061 0.557 +211-22-103-158. 192.168.0.2 2 u 146 512 377 2.774 2.610 0.491 +118-163-81-62.H 192.168.0.3 2 u 412 512 377 2.892 2.742 0.419 ``` - Remote: "*" 已被優先選定為同步對象者, "+"良好且優先選用的備用時間伺服器 - refid: REFERENCE IDENTIFICATION 通常是伺服器的 IP 位址或外部時鐘的名稱,但也有可能是 介於用戶端和伺服器之間的路由器。 - st STRATUM: 此項目用來測量所有用戶端距離實際時間來源的遠近。GPS 時鐘: Stratum=0;連接到 GPS 時鐘的 NTP Daemon:Stratum=1;其他 (距離再遠一步的) 來源:Stratum=2。 - t TYPE (類型) 可能出現的類型如下: - l local (例如 GPS 時鐘) - u unicast (此為最常見的類型) - m multicast - b broadcast - netaddr (通常為 0) - when:此伺服器上次回應是在多久以前 (以秒計) - poll: POLL PERIOD 向此伺服器提出查詢的週期 (以秒計)?若透過網路 連線,通常會使用 512 秒 (約 8 分鐘) 和 1024 秒 (約 17 分鐘),不過接有外部時鐘 (如 GPS) 的系統 必須少於 64 秒。 - reach: REACHABILITY 註:值越高越好 用戶端連往伺服器的成功率 - delay: ROUND TRIP TIME 註:值越小越好 向伺服器提出詢問時,答覆封包返回所需的時間 (以毫秒 計)。 - offset: TIME DIFFERENCE 註:值越小越好 伺服器時鐘與用戶端時鐘的時差 (以毫秒計)。 當此數值大於 128 時,NTP 即會大幅加以調整 (而且 logfile會出現 Synchronization Lost 訊息)。 強制ntp同步 --- >ntpd -gq 設定時區 --- ***Warning: Ignoring the TZ variable. Reading the system's time zone setting only. 使用timedatactl: ``` sudo timedatectl set-timezone Asia/Taipei ``` ***NTP 真正的功能在於管理 Offset 數值,並且將其降至最低。*** 參考設定 --- - [Linux時間同步ntpd和ntpdate的用法](https://www.liupeng.mobi/archives/416) ###### tags: `ntp` `date` `ntpd` `linux` `clock`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully