NTP服務器用的端口號是TCP/UDP的123端口,這里只考慮內網的時間同步,不做認證,任何客戶端都能到服務器上來同步時間,我們一共需要操作的是2個關鍵點,誰能到我這里來同步時間,我的時間又和誰同步,搭建步驟如下:
1、安裝ntp和ntpdate
yum -y install ntp ntpdate
2、編輯配置文件
vim /etc/ntp.conf
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 把這個#號這行復制以后,這一行的作用是指定誰能夠到我這里來同步時間的,通常我只需要改這一個就行了
restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
#下面是默認的上游時間服務器,如果無法上網,你可以指定其他內網機器IP
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
3、客戶端驗證
[root@localhost ~]# ntpdate 192.168.100.24
4 May 15:24:21 ntpdate[1563]: adjust time server 192.168.100.24 offset 0.017559 sec