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

NTP簡介:

NTP是網絡時間協議(Network Time Protocol),它是用來同步網絡中各個計算機的時間的協議。vim

在計算機的世界裏,時間很是地重要centos

例如:對於火箭發射這種科研活動,對時間的統一性和準確性要求就很是地高,是按照A這臺計算機的時間,仍是按照B這臺計算機的時間?服務器

NTP就是用來解決這個問題的,NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。網絡

它的用途是把計算機的時鐘同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度能夠達到1-50ms。ide

它能夠使計算機對其服務器或時鐘源(如石英鐘,GPS等等)進行時間同步,它能夠提供高精準度的時間校訂,並且能夠使用加密確認的方式來防止病毒的協議***。加密

 

環境:

系統:CentOS Linux release 7.4.1708 (Core) spa

NTP Server服務器IP:192.168.0.15rest

NTP Client客戶端IP:192.168.0.16orm

 

一、搭建NTP服務器

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.二、安裝ntp,ntpdate已經系統默認安裝過了

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

1.三、修改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.四、啓動ntp服務,並開機自啓動

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

1.五、查詢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.六、開啓防火牆ntp默認端口udp123

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

 

二、NTP客戶端配置

安裝的NTP跟上面的步驟同樣server

2.一、修改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.二、與NTP server服務器同步一下時間:

[root@localhost ~]# ntpdate -u 192.168.0.15

2.三、查看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
相關文章
相關標籤/搜索