運維之道 | NTP 系統時間服務搭建部署

NTP 系統時間同步主機規劃

NTP IP
服務端 192.168.182.12
客戶端 192.168.182.13

Server端

一、NTP 系統時間服務安裝部署

1、NTP服務安裝
[root@localhost ~]# yum install -y ntp ntpdate
2、修改NTP服務配置(基本不改
[root@localhost ~]# vim /etc/ntp.conf 
[root@localhost ~]# egrep -v "#|^$" /etc/ntp.conf 
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
3、打開NTP防火牆策略
[root@localhost ~]# iptables -A INPUT -m state --state NEW -m udp --dport 123 -j ACCEPT
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive
4、啓動NTP服務器,並設置開機自啓
[root@localhost ~]# systemctl start ntpd && systemctl enable ntpd
5、執行ntpq -p 查看是否配置成功
[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+sv1.ggsrv.de    205.46.178.169   2 u   16   64  337  223.091    7.405  73.608
*203.107.6.88    10.137.38.86     2 u    9   64  377   50.219   13.419   5.884
 h199-182-204-19 219.119.208.14   2 u  226   64   10  208.683   10.749   0.000
+ntp8.flashdance 192.36.143.130   2 u    5   64  377  262.561    7.023   5.378
[root@localhost ~]# date
20200210日 星期一 11:26:18 CST

Client端

一、NTP 系統時間服務安裝部署

1、NTP服務安裝
[root@localhost ~]# yum install -y ntp ntpdate
2、修改NTP服務配置
[root@localhost etc]# mv ntp.conf ntp.conf.bak					/// 將ntp原配置備份
[root@localhost etc]# cp ntp.conf.bak ntp.conf -a				/// 複製ntp原配置文件作爲文本
[root@localhost etc]# vim ntp.conf             					/// 修改ntp配置
server 192.168.182.12											/// IP爲NTP server端的IP
3、啓動NTP服務前先ntpdate⼿動同步下時間,避免客戶端與服務端時間差過⼤,導致ntp不能同步
[root@localhost etc]# ntpdate -u 192.168.182.12
10 Feb 11:40:58 ntpdate[8207]: adjust time server 192.168.182.12 offset -0.010329 sec
4、啓動NTP服務器,並設置開機自啓
[root@localhost etc]# systemctl start ntpd && systemctl enable ntpd
5、執行ntpq -p 查看是否配置成功
[root@localhost etc]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.182.12  203.107.6.88     3 u    3   64    3    0.690    9.349   3.127
6、查看是否時間同步

如顯示unsynchronised,同步時間大概需要幾分鐘,幾分鐘後再次查看即可

[root@localhost etc]# ntpstat
unsynchronised
  time server re-starting										/// 正在重啓時間同步
   polling server every 8 s
[root@localhost etc]# ntpstat
synchronised to NTP server (192.168.182.12) at stratum 4		/// NTP與192.168.182.12主機同步時間
   time correct to within 1003 ms
   polling server every 64 s
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章