Centos7安裝搭建NTP服務器和NTP客戶端同步時間


NTP簡介:

NTP是網絡時間協議(Network Time Protocol),它是用來同步網絡中各個計算機的時間的協議。
在計算機的世界里,時間非常地重要
例如:對於火箭發射這種科研活動,對時間的統一性和准確性要求就非常地高,是按照A這台計算機的時間,還是按照B這台計算機的時間?
NTP就是用來解決這個問題的,NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。
它的用途是把計算機的時鍾同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度可以達到1-50ms。
它可以使計算機對其服務器或時鍾源(如石英鍾,GPS等等)進行時間同步,它可以提供高精准度的時間校正,而且可以使用加密確認的方式來防止病毒的協議攻擊。
 

環境:

系統:CentOS Linux release 7.4.1708 (Core) 

NTP Server服務器IP:192.168.0.15

NTP Client客戶端IP:192.168.0.16

 

1、搭建NTP服務器

1.1、查看服務器是否安裝ntp,系統默認安裝ntpdate;

[root@localhost ~]# rpm -qa |grep ntp
ntpdate-4.2.6p5-28.el7.centos.x86_64
ntp-4.2.6p5-28.el7.centos.x86_64

1.2、安裝ntp,ntpdate已經系統默認安裝過了

[root@localhost ~]# yum install -y ntp

1.3、修改ntp配置文件

[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 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

1.4、啟動ntp服務,並開機自啟動

[root@localhost ~]# systemctl start ntpd
[root@localhost ~]# systemctl enable ntpd

1.5、查詢ntp是否同步

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*119.28.206.193  100.122.36.196   2 u  128  128  377   19.711   -0.468   5.363

1.6、開啟防火牆ntp默認端口udp123

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=123/udp
success
[root@localhost ~]# firewall-cmd --reload
success

 

2、NTP客戶端配置

安裝的NTP跟上面的步驟一樣

2.1、修改ntp配置文件,將上面的NTP服務器作為客戶端同步NTP時間服務器

[root@localhost ~]# vim /etc/ntp.conf
#配置允許NTP Server時間服務器主動修改本機的時間
restrict 192.168.0.15 nomodify notrap noquery
#注釋掉其他時間服務器
#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
#配置時間服務器為本地搭建的NTP Server服務器
server 192.168.0.15

2.2、與NTP server服務器同步一下時間:

[root@localhost ~]# ntpdate -u 192.168.0.15

2.3、查看ntp同步狀態

能看到已經成功同步,要記得開啟ntpd這個服務器

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.0.15  119.28.206.193   3 u    7   64    1    0.217  -288085   0.000

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM