分享

RedHat7.2设置NTP服务器及客户端同步时间

 剩矿空钱 2019-06-26

在配置时钟同步服务器时第一次同步时间时,使用ntpdate命令;后续通过ntpd服务与服务器同步时间。

一、搭建NTP服务器

1、查看服务器、客户端操作系统版本

  1. [root@server1 bin]# cat /etc/redhat-release
  2. Red Hat Enterprise Linux Server release 7.2 (Maipo)

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

  1. [root@server1 bin]# rpm -qa | grep ntp
  2. fontpackages-filesystem-1.44-8.el7.noarch
  3. ntp-4.2.6p5-22.el7.x86_64
  4. ntpdate-4.2.6p5-22.el7.x86_64
  5. python-ntplib-0.3.2-1.el7.noarch

3、安装ntp ntpdate,其中ntpdate默认安装,可以只安装ntp;

yum install ntp ntpdate -y

5、查看ntp服务器状态

systemctl status ntpd

6、修改配置文件,使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间

vim /etc/ntp.conf

把如下四行代码注释掉

  1. #server 0.rhel.pool.ntp.org iburst
  2. #server 1.rhel.pool.ntp.org iburst
  3. #server 2.rhel.pool.ntp.org iburst
  4. #server 3.rhel.pool.ntp.org iburst

在下面再添加一行

  1. server 127.127.1.0
  2. fudge 127.127.1.0 stratum 10

7、启动ntp服务

systemctl start ntpd

8、再次查看服务器状态

systemctl status ntpd

9、查看是否同步

ntpq -p

 

remote:本机和上层ntp的ip或主机名,“ ”表示优先,“*”表示次优先

refid:参考上一层ntp主机地址

st:stratum阶层

when:多少秒前曾经同步过时间

poll:下次更新在多少秒后

reach:已经向上层ntp服务器要求更新的次数

delay:网络延迟

offset:时间补偿

jitter:系统时间与bios时间差

二、客户端配置

前5步与服务器一致

6、修改配置文件,将刚刚搭建好的NTP服务器作为客户端上游时间服务器

  #配置允许上游时间服务器主动修改本机的时间

restrict 172.16.20.51 nomodify notrap noquery

    #配置上游时间服务器为本地的ntpd Server服务器

server 172.16.20.51 Fudge 172.16.20.51 stratum 10

7、与本地ntpd Server同步一下

ntpdate -u 172.16.20.51

9、查看状态

ntpq -p

8、设置开机启动

systemctl enable ntpd

9、查看时间是否同步

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多