Centos 7搭建NTP时间同步服务器

    技术2022-07-12  75

    文章目录

    NTP时间服务器的概念如何来做(思路)环境一、服务端安装ntp软件包二、服务端修改配置文件三、设置开机自启,启动ntp服务,并查看四、客户端安装ntp,并开启,设置开机自启五、修改客户端配置文件,并重启六、验证

    NTP时间服务器的概念

    NTP( Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协

    议。它的用途是把计算机的时钟同步到世界协调时 UTC,其精度在局域网内可达 0.1ms,在互联

    网上绝大多数的地方其精度可以达到 1-50ms。

    NTP 服务器就是利用 NTP 协议提供时间同步服务的。

    在实际工作中,不可能所有的服务器都通互联网,毕竟互联网鱼龙混杂还是有风险的!

    如何来做(思路)

    1)找一台机器 (作为时间服务器)

    2)所有的机器与这台机器的时间进行同步(比如,每次10分钟同步一次)

    环境

    系统:centos7

    服务端:192.168.59.3

    客户端:192.168.59.4

    一、服务端安装ntp软件包

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

    二、服务端修改配置文件

    [root@192 ~]# vim /etc/ntp.conf #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 server 127.127.1.0 iburst

    三、设置开机自启,启动ntp服务,并查看

    [root@192 ~]# systemctl start ntpd [root@192 ~]# systemctl enable ntpd [root@192 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *LOCAL(0) .LOCL. 5 l 5 64 1 0.000 0.000 0.000

    四、客户端安装ntp,并开启,设置开机自启

    [root@192 ~]# yum -y install ntp [root@192 ~]# systemctl start ntpd [root@192 ~]# systemctl enable ntpd

    五、修改客户端配置文件,并重启

    [root@192 ~]# vim /etc/ntp.conf #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 server 192.168.59.3 restrict 192.168.59.3 nomodify notrap nuquery [root@192 ~]# restart start ntpd

    六、验证

    [root@192 ~]# date -s 2017-1-1 2017年 01月 01日 星期日 00:00:00 CST [root@192 ~]# date 2017年 01月 01日 星期日 00:00:02 CST [root@192 ~]# ntpdate -u 192.168.59.3 2 Jul 08:49:15 ntpdate[12260]: step time server 192.168.59.3 offset 110450935.086109 sec [root@192 ~]# date 2020年 07月 02日 星期四 08:49:22 CST

    offset 110450935.086109 sec [root@192 ~]# date 2020年 07月 02日 星期四 08:49:22 CST

    好了,到此已经完成了,后期有需要的可以添加定时任务。
    Processed: 0.010, SQL: 9