實驗環境:
OS:Linux Centos 7.4 x86_64
1.查看目前伺服器時區&列出時區並設定時區(如已正確時區,請略過):
# timedatectl # timedatectl list-timezones # timedatectl set-timezone Asia/Shanghai
2.時間時區概念理解:
GMT、UTC、CST、DST
UTC:
整個地球分為二十四時區,每個時區都有自己的本地時間,在國際無線電通信場合,為了統一起見,使用一個統一的時間,稱為通用協調時(UTC:Universal Time Coordinated)。
GMT:
格林威治標準時間 (Greenwich Mean Time)指位於英國倫敦郊區的皇家格林尼治天文台的標準時間,因為本初子午線被定義在通過那裡的經線(UTC與GMT時間基本相同)。
CST:
中國標準時間 (China Standard Time)
GMT + 8 = UTC + 8 = CST
DST:
夏令時(Daylight Saving Time) 指在夏天太陽升起的比較早時,將時間撥快一小時,以提早日光的使用(中國不使用)。
2.使用 NTP 公共時間伺服器池(NTP Public Pool Time Servers)http://www.pool.ntp.org 同步你的伺服器時間。
查看是否安裝:
# rpm -q ntp ntp-4.2.6p5-25.el7.centos.2.x86_64
如已安裝請略過此步,否則請執行以下指令安裝:
# yum install ntpdate ntp -y
修改NTP配置:
註:綠色為原有我註解掉的內容,紅色為新增代替之前註解內容,其他預設。
# vim /etc/ntp.conf # For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). driftfile /var/lib/ntp/drift #新增:日志目录. logfile /var/log/ntpd.log # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict ::1 #这一行的含义是授权172.16.128.0网段上的所有机器可以从这台机器上查询和同步时间. restrict 172.16.128.0 mask 255.255.255.0 nomodify notrap # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst #新增:时间服务器列表. server 0.cn.pool.ntp.org iburst server 1.cn.pool.ntp.org iburst server 2.cn.pool.ntp.org iburst server 3.cn.pool.ntp.org iburst #新增:当外部时间不可用时,使用本地时间. server 172.16.128.171 iburst fudge 127.0.0.1 stratum 10 #broadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client #新增:允许上层时间服务器主动修改本机时间. restrict 0.cn.pool.ntp.org nomodify notrap noquery restrict 1.cn.pool.ntp.org nomodify notrap noquery restrict 2.cn.pool.ntp.org nomodify notrap noquery # Enable public key cryptography. #crypto includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys # Specify the key identifiers which are trusted. #trustedkey 4 8 42 # Specify the key identifier to use with the ntpdc utility. #requestkey 8 # Specify the key identifier to use with the ntpq utility. #controlkey 8 # Enable writing of statistics records. #statistics clockstats cryptostats loopstats peerstats # Disable the monitoring facility to prevent amplification attacks using ntpdc # monlist command when default restrict does not include the noquery flag. See # CVE-2013-5211 for more details. # Note: Monitoring will not be disabled with the limited restriction flag. disable monitor
3.設定係統開機自啟動:
# systemctl enable ntpd # systemctl enable ntpdate # systemctl is-enabled ntpd
在ntpd服務啟動時,先使用ntpdate指令同步時間:
# ntpdate -u 1.cn.pool.ntp.org
原因之一:當服務端與客戶端之間的時間誤差過大時,此時修改時間可能對系統或應用帶來不可預測問題,NTP會停止時間同步。若檢查NTP啟動後時間未同步時,應考慮可能為時間誤差過大所致,此時需先手動進行時間同步。
啟動NTP伺服器:
# systemctl start ntpdate # systemctl start ntpd
4.加入防火牆:
# firewall-cmd --permanent --add-service=ntp # firewall-cmd --reload
5.查看ntp連線狀態如果沒有問題,將正確時間寫入硬體:
# ss -tlunp | grep ntp # ntpq -p # hwclock -w
5.1.系統時間與硬體時間
硬體時間:
RTC(Real-Time Clock)或CMOS時間,一般在主機板上靠電池供電,伺服器斷電後也會繼續運作。僅儲存日期時間數值,無法儲存時區和夏令時間設定。
系統時間:
一般在伺服器啟動時複製RTC時間,之後獨立運行,保存了時間、時區和夏令時設定。
6.客戶端:
以服務進程方式即時同步(需安裝NTP):
# vim /etc/ntp.conf server 172.16.128.171
重要:修改任意節點伺服器的NTP設定檔都需要重起ntpd服務:
# systemctl restart ntpd
以crontab任務計畫同步時間(需安裝ntpdate,每天24點更新同步時間):
# crontab -e 0 0 * * * /usr/sbin/sntp -P no -r 172.16.128.171;hwclock -w
已部署完畢。這樣集群會自動定期進行服務的同步,如此以來集群的時間就保持一致了。
以上是Centos 7安裝設定NTP網路時間同步伺服器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

學習Linux並不難。 1.Linux是一個開源操作系統,基於Unix,廣泛應用於服務器、嵌入式系統和個人電腦。 2.理解文件系統和權限管理是關鍵,文件系統是層次化的,權限包括讀、寫和執行。 3.包管理系統如apt和dnf使得軟件管理方便。 4.進程管理通過ps和top命令實現。 5.從基本命令如mkdir、cd、touch和nano開始學習,再嘗試高級用法如shell腳本和文本處理。 6.常見錯誤如權限問題可以通過sudo和chmod解決。 7.性能優化建議包括使用htop監控資源、清理不必要文件和使用sy

Linux管理員的平均年薪在美國為75,000至95,000美元,歐洲為40,000至60,000歐元。提升薪資可以通過:1.持續學習新技術,如雲計算和容器技術;2.積累項目經驗並建立Portfolio;3.建立職業網絡,拓展人脈。

Linux的主要用途包括:1.服務器操作系統,2.嵌入式系統,3.桌面操作系統,4.開發和測試環境。 Linux在這些領域表現出色,提供了穩定性、安全性和高效的開發工具。

互聯網運行不依賴單一操作系統,但Linux在其中扮演重要角色。 Linux廣泛應用於服務器和網絡設備,因其穩定性、安全性和可擴展性受歡迎。

Linux操作系統的核心是其命令行界面,通過命令行可以執行各種操作。 1.文件和目錄操作使用ls、cd、mkdir、rm等命令管理文件和目錄。 2.用戶和權限管理通過useradd、passwd、chmod等命令確保系統安全和資源分配。 3.進程管理使用ps、kill等命令監控和控制系統進程。 4.網絡操作包括ping、ifconfig、ssh等命令配置和管理網絡連接。 5.系統監控和維護通過top、df、du等命令了解系統運行狀態和資源使用情況。

介紹 Linux是一個強大的操作系統,由於其靈活性和效率,開發人員,系統管理員和電源用戶都喜歡。但是,經常使用長而復雜的命令可能是乏味的

Linux適用於服務器、開發環境和嵌入式系統。 1.作為服務器操作系統,Linux穩定高效,常用於部署高並發應用。 2.作為開發環境,Linux提供高效的命令行工具和包管理系統,提升開發效率。 3.在嵌入式系統中,Linux輕量且可定制,適合資源有限的環境。

簡介:通過基於Linux的道德黑客攻擊數字邊界 在我們越來越相互聯繫的世界中,網絡安全至關重要。 道德黑客入侵和滲透測試對於主動識別和減輕脆弱性至關重要


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

記事本++7.3.1
好用且免費的程式碼編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3 Linux新版
SublimeText3 Linux最新版