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
2020年 02月 10日 星期一 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