/* 看板娘 */ canvas#live2dcanvas { border: 0 !important; left: 0; }

Centos7安装搭建NTP服务器和NTP客户端同步时间

NTP简介:

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。
在计算机的世界里,时间非常地重要
例如:对于火箭发射这种科研活动,对时间的统一性和准确性要求就非常地高,是按照A这台计算机的时间,还是按照B这台计算机的时间?
NTP就是用来解决这个问题的,NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。
它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。
它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)进行时间同步,它可以提供高精准度的时间校正,而且可以使用加密确认的方式来防止病毒的协议攻击。
 

环境:

系统:CentOS Linux release 7.4.1708 (Core) 

 

 

1、搭建NTP服务器

查看服务器是否安装ntp,系统默认安装ntpdate;

[root@localhost ~]# rpm -qa |grep ntp
ntpdate-4.2.6p5-28.el7.centos.x86_64
ntp-4.2.6p5-28.el7.centos.x86_64

安装ntp,ntpdate已经系统默认安装过了

[root@localhost ~]# yum install -y ntp

修改ntp配置文件

[root@localhost ~]# vim /etc/ntp.conf

把配置文件查询到这里,(默认四个):
# server 0.rhel.pool.ntp.org iburst
# server 1.rhel.pool.ntp.org iburst
# server 2.rhel.pool.ntp.org iburst
# server 3.rhel.pool.ntp.org iburst

可以改成公司默认服务器:
server ntp1.1an.com iburst prefer
server ntp2.1an.com iburst

启动ntp服务,并开机自启动

systemctl start ntpd           # 启动NTP服务器
systemctl status ntpd           # 查看NTP服务器状态
systemctl enable ntpd           # 开机自启,无需无效,(停止chrony服务,“避免启动了chrony而冲突”
systemctl disable chronyd        # 由于上面重启后,NTP无法自启,停掉服务
systemctl list-unit-files|grep ntpd  # 查看运行NTP服务器

查看ntp同步状态

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.144.13  202.108.6.95     3 u  447 1024    0    0.000    0.000   0.000
*192.168.144.12  114.118.7.161    3 u    2  128  377    2.496    8.825   5.368

 

 

2、NTP客户端配置

安装的NTP跟上面的步骤一样

修改ntp配置文件,将上面的NTP服务器作为客户端同步NTP时间服务器

[root@localhost ~]# vim /etc/ntp.conf
#配置允许NTP Server时间服务器主动修改本机的时间
restrict 192.168.0.15 nomodify notrap noquery
#注释掉其他时间服务器
#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
#配置时间服务器为本地搭建的NTP Server服务器
server 192.168.0.15

与NTP server服务器同步一下时间:

[root@localhost ~]# ntpdate -u 192.168.0.15

查看ntp同步状态

能看到已经成功同步,要记得开启ntpd这个服务器

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.0.15  119.28.206.193   3 u    7   64    1    0.217  -288085   0.000

 

posted @ 2020-06-04 17:04  群临天下  阅读(398)  评论(0编辑  收藏  举报
/* 看板娘 */