參考原文:https://blog.csdn.net/wyfsxs/article/details/80608957
1. 首先安裝ntp服務(ubuntu 16.02)
在linux的root用戶下執行以下命
sudo apt-get install ntp
(如果不是ubuntu系統則執行 yum install ntp –y)
2. 修改ntp配置文件(server)
我們需要在linux集群中找到一台作為ntp服務器的server,其他機器則為ntp的client,因此,在server服務器上修改一下配置文件
執行
退出保存,重啟ntp服務
執行 service ntp restart
vim /etc/ntp.conf:
#linux自帶的時間同步,需要注釋掉 #pool 0.ubuntu.pool.ntp.org iburst #pool 1.ubuntu.pool.ntp.org iburst #pool 2.ubuntu.pool.ntp.org iburst #pool 3.ubuntu.pool.ntp.org iburst # Use Ubuntu's ntp server as a fallback. #pool ntp.ubuntu.com # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 #因為是內網,所以用本地時間做為服務器時間,注意這里不是127.0.0.1 server 127.127.1.0 fudge 127.127.1.0 stratum 8 #開放192.168.8.0 整個網段,即在這個網段的所有機器都可以使用 214 作為時間同步服務端 restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
3. 修改ntp配置文件(client)
同樣的server端已經配置好了,client的配置相對簡單
執行 sudo vim /etc/ntp.conf:
#linux自帶的時間同步,需要注釋掉 #pool 0.ubuntu.pool.ntp.org iburst #pool 1.ubuntu.pool.ntp.org iburst #pool 2.ubuntu.pool.ntp.org iburst #pool 3.ubuntu.pool.ntp.org iburst # Use Ubuntu's ntp server as a fallback. #pool ntp.ubuntu.com # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 #增加214作為時間服務器即可 server 192.168.0.214 # Needed for adding pool entries restrict source notrap nomodify noquery
退出保存,重啟ntp服務
執行 sudo service ntp restart
4. 查看ntp服務是否配置完成
在ntp sever上執行 ntpq -p
在ntp client上執行 ntpq –p
即完成ntp服務的配置
5. ntp服務的相關命令
service ntpstart 啟動
service ntp stop停止
service ntprestart 重新啟動