centos搭建NTP服務器
服務器端
查看安裝
[root@localhost ~]# rpm -qa | grep ntp
fontpackages-filesystem-1.44-8.el7.noarch
ntpdate-4.2.6p5-29.el7.centos.x86_64
python-ntplib-0.3.2-1.el7.noarch
安裝相應的包
[root@localhost ~]# yum install ntp ntpdate -y
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
正在解決依賴關系
--> 正在檢查事務
---> 軟體包 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 需要
---> 軟體包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos 將被 升級
---> 軟體包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos.2 將被 更新
--> 正在檢查事務
---> 軟體包 autogen-libopts.x86_64.0.5.18-5.el7 將被 安裝
--> 解決依賴關系完成
依賴關系解決
=======================================================================================
Package 架構 版本 源 大小
=======================================================================================
正在安裝:
ntp x86_64 4.2.6p5-29.el7.centos.2 base 549 k
正在更新:
ntpdate x86_64 4.2.6p5-29.el7.centos.2 base 87 k
為依賴而安裝:
autogen-libopts x86_64 5.18-5.el7 base 66 k
事務概要
=======================================================================================
安裝 1 軟體包 (+1 依賴軟體包)
升級 1 軟體包
總計:701 k
總下載量:615 k
Downloading packages:
(1/2): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:00
(2/2): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:00:00
---------------------------------------------------------------------------------------
總計 1.5 MB/s | 615 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : autogen-libopts-5.18-5.el7.x86_64 1/4
正在更新 : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 2/4
正在安裝 : ntp-4.2.6p5-29.el7.centos.2.x86_64 3/4
清理 : ntpdate-4.2.6p5-29.el7.centos.x86_64 4/4
驗證中 : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 1/4
驗證中 : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/4
驗證中 : autogen-libopts-5.18-5.el7.x86_64 3/4
驗證中 : ntpdate-4.2.6p5-29.el7.centos.x86_64 4/4
已安裝:
ntp.x86_64 0:4.2.6p5-29.el7.centos.2
作為依賴被安裝:
autogen-libopts.x86_64 0:5.18-5.el7
更新完畢:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2
完畢!
再次查看 發現ntp-4.2.6p5-29.el7.centos.2.x86_64已安裝
[root@localhost ~]# rpm -qa | grep ntp
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
ntp-4.2.6p5-29.el7.centos.2.x86_64
python-ntplib-0.3.2-1.el7.noarch
顯示ntp狀態
[root@localhost ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
編輯內置檔案設定無網路同步本機時間
[root@localhost ~]# vim /etc/ntp.conf
把如下四行代碼注釋掉:
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 127.127.1.0 iburst
啟動服務
[root@localhost ~]# systemctl start ntpd
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 9 64 1 0.000 0.000 0.000
設定開機啟動
[root@localhost ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
ntp服務使用的UDP協議的123埠
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload
[root@localhost ~]# firewall-cmd --permanent --add-port=123/udp
success
[root@localhost ~]# firewall-cmd --reload
success
查看打開的埠
[root@localhost ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:53
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:67
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:67
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
INPUT_direct all -- 0.0.0.0/0 0.0.0.0/0
INPUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
DROP all -- 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 192.168.122.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 192.168.122.0/24 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
FORWARD_direct all -- 0.0.0.0/0 0.0.0.0/0
FORWARD_IN_ZONES all -- 0.0.0.0/0 0.0.0.0/0
FORWARD_OUT_ZONES all -- 0.0.0.0/0 0.0.0.0/0
DROP all -- 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:68
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
OUTPUT_direct all -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD_IN_ZONES (1 references)
target prot opt source destination
FWDI_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
FWDI_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_OUT_ZONES (1 references)
target prot opt source destination
FWDO_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
FWDO_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain FORWARD_direct (1 references)
target prot opt source destination
Chain FWDI_public (2 references)
target prot opt source destination
FWDI_public_log all -- 0.0.0.0/0 0.0.0.0/0
FWDI_public_deny all -- 0.0.0.0/0 0.0.0.0/0
FWDI_public_allow all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
Chain FWDI_public_allow (1 references)
target prot opt source destination
Chain FWDI_public_deny (1 references)
target prot opt source destination
Chain FWDI_public_log (1 references)
target prot opt source destination
Chain FWDO_public (2 references)
target prot opt source destination
FWDO_public_log all -- 0.0.0.0/0 0.0.0.0/0
FWDO_public_deny all -- 0.0.0.0/0 0.0.0.0/0
FWDO_public_allow all -- 0.0.0.0/0 0.0.0.0/0
Chain FWDO_public_allow (1 references)
target prot opt source destination
Chain FWDO_public_deny (1 references)
target prot opt source destination
Chain FWDO_public_log (1 references)
target prot opt source destination
Chain INPUT_ZONES (1 references)
target prot opt source destination
IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]
Chain INPUT_direct (1 references)
target prot opt source destination
Chain IN_public (2 references)
target prot opt source destination
IN_public_log all -- 0.0.0.0/0 0.0.0.0/0
IN_public_deny all -- 0.0.0.0/0 0.0.0.0/0
IN_public_allow all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
Chain IN_public_allow (1 references)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW,UNTRACKED
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:123 ctstate NEW,UNTRACKED
Chain IN_public_deny (1 references)
target prot opt source destination
Chain IN_public_log (1 references)
target prot opt source destination
Chain OUTPUT_direct (1 references)
target prot opt source destination
客戶端(更換另一臺同網段的服務器)
安裝ntp
[root@localhost ~]# yum install ntp ntpdate -y
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
軟體包 ntp-4.2.6p5-29.el7.centos.2.x86_64 已安裝并且是最新版本
軟體包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安裝并且是最新版本
無須任何處理
組態檔
[root@localhost ~]# vim /etc/ntp.conf
把如下四行代碼注釋掉:
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 192.168.49.132
rsetrict 192.168.49.132 nomodify notrap noquery
與本地ntpd Server同步一下
[root@localhost ~]# ntpdate -u 192.168.49.132
啟動ntp服務
[root@localhost ~]# systemctl start ntpd
設定ntp服務開機自啟
[root@localhost ~]# systemctl enable ntpd
7.查看狀態
[root@localhost ~]# ntpq -p
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243951.html
標籤:其他
