Centos7 NTP服務
阿新 • • 發佈:2020-08-07
修改時區(改為中國標準時區)ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime(如果在安裝centos時指定過了 這一步就不用了)
timedatectl set-ntp no # 關閉ntp timedatectl set-time "2018-07-05 15:06:00" # 設定時間 timedatectl set-timezone Asia/Shanghai # 設定時區 date # 檢視配置是否正確
1、安裝ntp
yum -y install ntp
[root@cdh02 ntp]# yum install -y ntp 已載入外掛:fastestmirror Loading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn * extras: ftp.sjtu.edu.cn * updates: centosv8.centos.org base | 3.6kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): extras/7/x86_64/primary_db | 205kB 00:00:05 (2/4): base/7/x86_64/group_gz | 153 kB 00:00:05 (3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:12 updates/7/x86_64/primary_db FAILED ] 734 B/s | 7.3 MB 01:07:38 ETA http://centosv8.centos.org/centos/7.8.2003/updates/x86_64/repodata/1c1cef9b9757d3f2013951752cad3bf93417ab30c1b8144b4d465df77510c502-primary.sqlite.bz2: [Errno 12] Timeout on http://centosv8.centos.org/centos/7.8.2003/updates/x86_64/repodata/1c1cef9b9757d3f2013951752cad3bf93417ab30c1b8144b4d465df77510c502-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') 正在嘗試其它映象。 updates/7/x86_64/primary_db FAILED ] 3.4 kB/s | 7.7 MB 00:12:09 ETA http://centosu8.centos.org/centos/7.8.2003/updates/x86_64/repodata/1c1cef9b9757d3f2013951752cad3bf93417ab30c1b8144b4d465df77510c502-primary.sqlite.bz2: [Errno 14] curl#18 - "transfer closed with 2541101 bytes remaining to read" 正在嘗試其它映象。 (4/4): updates/7/x86_64/primary_db | 3.8 MB 00:14:30 正在解決依賴關係 --> 正在檢查事務 ---> 軟體包 ntp.x86_64.0.4.2.6p5-29.el7.centos.2 將被 安裝 --> 正在處理依賴關係 libopts.so.25()(64bit),它被軟體包 ntp-4.2.6p5-29.el7.centos.2.x86_64 需要 --> 正在檢查事務 ---> 軟體包 autogen-libopts.x86_64.0.5.18-5.el7 將被 安裝 --> 解決依賴關係完成 依賴關係解決 ======================================================================================================================= Package 架構 版本 源 大小 ======================================================================================================================= 正在安裝: ntp x86_64 4.2.6p5-29.el7.centos.2 updates 549 k 為依賴而安裝: autogen-libopts x86_64 5.18-5.el7 base 66 k 事務概要 ======================================================================================================================= 安裝 1 軟體包 (+1 依賴軟體包) 總下載量:615 k 安裝大小:1.5 M Downloading packages: 警告:/var/cache/yum/x86_64/7/base/packages/autogen-libopts-5.18-5.el7.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 金鑰 ID f4a80eb5: NOKEY autogen-libopts-5.18-5.el7.x86_64.rpm 的公鑰尚未安裝 (1/2): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:03 ntp-4.2.6p5-29.el7.centos.2.x8 FAILED ] 1.6 B/s | 208 kB 74:11:17 ETA http://centost7.centos.org/centos/7.8.2003/updates/x86_64/Packages/ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm: [Errno 12] Timeout on http://centost7.centos.org/centos/7.8.2003/updates/x86_64/Packages/ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds') 正在嘗試其它映象。 ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm 的公鑰尚未安裝================================] 1.5 kB/s | 615 kB 00:00:00 ETA (2/2): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:02:38 ----------------------------------------------------------------------------------------------------------------------- 總計 2.3 kB/s | 615 kB 00:04:28 從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 檢索金鑰 匯入 GPG key 0xF4A80EB5: 使用者ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>" 指紋 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 軟體包 : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda) 來自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : autogen-libopts-5.18-5.el7.x86_64 1/2 正在安裝 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/2 驗證中 : autogen-libopts-5.18-5.el7.x86_64 1/2 驗證中 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/2 已安裝: ntp.x86_64 0:4.2.6p5-29.el7.centos.2 作為依賴被安裝: autogen-libopts.x86_64 0:5.18-5.el7 完畢! [1] 已殺死 yum install -y ntd
2、ntp主機配置 vi /etc/ntp.conf
主節點
其他節點
3、重新啟動 ntp 服務
service ntpd restart
4、設定開機自啟
systemctl enable ntpd.service
ntpdc -c loopinfo #檢視與時間同步伺服器的時間偏差 ntpq -p #檢視當前同步的時間伺服器 ntpstat #檢視狀態 定時同步crontab crontab -e 10 * * * * /usr/sbin/ntpdate n47.aa-data.cn
5、檢視伺服器狀態
systemctl status ntpd.service
6、同步時間
ntpstat
主節點
其他節點
完