CentOS 7配置NTP客戶端
阿新 • • 發佈:2021-08-05
yum -y install ntp
保持伺服器時間準確,對於業務系統的執行、資料庫中時間的記錄等至關重要。通常的做法是為伺服器配置NTP客戶端服務,讓伺服器自己定時去與NTP伺服器同步時間。
以CentOS 7伺服器為例,為期配置NTP客戶端的具體步驟如下:
一、檢視本機時間,確定NTP伺服器的可用性(本例中以東北大學NTP伺服器ntp.neu.edu.cn為例)
1 2 |
# date //檢視本機時間
# ntpdate ntp.neu.edu.cn //確認NTP伺服器的可用性
|
二、配置NTP客戶端
編輯ntp.conf檔案,為NTP客戶端配置NTP伺服器的地址ntp.neu.edu.cn
1 2 3 4 5 6 7 8 9 10 11 |
// 編輯NTP配置檔案
# vim /etc/ntp.conf
// 註釋配置檔案中原有的NTP伺服器,並在其中新增自己所需的NTP伺服器地址
# 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 ntp.neu.edu.cn iburst
|
三、將NTP配置為(自啟動)服務,並啟動執行
1 2 3 4 |
# systemctl enable ntpd.service //安裝為服務
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
# systemctl start ntpd //啟動執行
|
四、檢查NTP客戶端執行狀態
1 |
# systemctl status ntpd
|
1 |
# ntpstat
|
1 |
# watch ntpq -p
|
ctrl+c 退出NTP監視器
1 2 |
# ntpdate ntp.neu.edu.cn
12 Jul 00:14:46 ntpdate[19640]: the NTP socket is in use, exiting //提示NTP socket已經被使用
|