1.简介
NTP简介:NTP是网络时间协议(Network Time Protocol), 它是用来同步网络中各个计算机的时间的协议。 在计算机的世界里,时间非常地重要 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。 它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms, 在互联网上绝大多数的地方其精度可以达到1-50ms。 它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)进行时间同步, 它可以提供高精准度的时间校正,而且可以使用加密确认的方式来防止病毒的协议攻击。
2.环境
系统: Red Hat Enterprise Linux Server release 7.6 (Maipo) NTP Server服务器IP: 192.168.6.128 NTP Client客户端IP: 192.168.6.129
3.yum安装
yum install ntp ntpdate -y
4.服务端设置
vi /etc/ntp.conf --没有联网的情况下,添加以下两条即可 server 127.127.1.0 fudge 127.127.1.0 stratum 10 --把配置文件下面四行注释掉: #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 --重启服务,并查看 systemctl start ntpd systemctl enable ntpd ntpq -p
5.客户端设置
restrict 192.168.6.128 nomodify notrap noquery server 192.168.6.128 fudge 192.168.6.128 stratum 10 --注释掉其他时间服务器 #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 systemctl restart ntpd systemctl enable ntpd ntpq -p --客户端同步时间 ntpdate -u 192.168.6.128
6.关闭chronyd
RHEL7需要关闭chronyd服务,不然和ntp冲突 systemctl stop chronyd.service systemctl disable chronyd.service rm -rf /etc/chrony.conf