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服務器
[root@localhost ~]# rpm -qa |grep ntp ntpdate-4.2.6p5-28.el7.centos.x86_64 ntp-4.2.6p5-28.el7.centos.x86_64
[root@localhost ~]# yum install -y 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
[root@localhost ~]# systemctl start ntpd [root@localhost ~]# systemctl enable ntpd
[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
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=123/udp success [root@localhost ~]# firewall-cmd --reload success
二、NTP客戶端配置
安裝的NTP跟上面的步驟同樣server
[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
[root@localhost ~]# ntpdate -u 192.168.0.15
能看到已經成功同步,要記得開啓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