• ntpntpdate时间同步


    1NTP时间服务器

    1.1 为什么用NTP时间服务器

    时间对服务器之间通信,信息交流很重要,所有服务器的时间同步是最基本的优化

    一般情况,我们可以同步公网的时间服务器,如ntp1.aliyun.com

    机器多时,同步公网服务器会有延迟,所以搭建一台时间服务器,然后本地机器去同步它

    ntp是一种协议

    ntp软件 CentOS6 自带 CentOS7需要安装

    chrony 软件 支持ntp协议 CentOS7自带

    尽量使用ntpdate同步时间
    只有时间服务器使用ntp服务

    1.2 安装ntp

    1 1.    [root@m02 ~]# yum install -y ntp

     1.3 配置ntp服务器

    ntp配置文件位置

    /etc/ntp.conf

    restrict #控制时间服务器同步权限

    server配置上级时间服务器

    漏洞:可以通过远程用户登陆,修改本地时间系统

    nomodify客户端可以同步

    将默认时间同步源删除改用可用源

    1 sed -i.ori 's#restrict default.*noquery#restrict default nomodify#;21,24d;25a\server ntp1.aliyun.com\nserver time.nist.gov' /etc/ntp.conf

    #用sed命令装逼,要注意基础,多多练习!!

     1.4 启动时间服务器

    ntp服务本身具有时间同步的功能,ntp服务和ntpdata一起使用冲突
    提示:如果系统有时间同步的定时任务,可以注释掉
    注意:修改时间,一定要在ntp服务启动之前。

     1 [root@m02 etc]# date -s 20080101
     2 Tue Jan  1 00:00:00 CST 2008
     3 [root@m02 etc]# date
     4 Tue Jan  1 00:00:02 CST 2008
     5 启动并查看ntp服务
     6 [root@m02 etc]# systemctl start ntpd.service 
     7 [root@m02 etc]# systemctl status ntpd.service 
     8 ● ntpd.service - Network Time Service
     9    Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
    10    Active: active (running) since Tue 2008-01-01 00:02:24 CST; 7s ago
    11   Process: 1414 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
    12  Main PID: 1415 (ntpd)
    13    CGroup: /system.slice/ntpd.service
    14 ntpq -p 查看上级时间服务器状态
    15 ntpstat 查看时间同步状态

    查看上级时间同步服务器状态

     1.5 内网客户端时间同步

    ntpdate 172.16.1.62

    放入到定时任务即可

    有时立即开启ntpdate服务会卡住,过一会就会进行时间同步

    1 [root@anyux ~]# ntpdate 10.0.0.62
    2 15 Nov 22:51:27 ntpdate[2024]: step time server 10.0.0.62 offset 280018271.169341 sec
    3 [root@anyux ~]# date +%F
    4 2017-11-15

    ntpdate 的调试模式

           -d      Enable the debugging mode, in which ntpdate will go through all the steps, but not  adjust  the  local clock. Information useful for general debugging will also be printed.

    1.6 chronyc

    1 [root@m02 ~]# systemctl status chronyd.service
    2 [root@m02 ~]# vim /etc/chrony.conf #它的配置文件与ntp配置文件相似

     1.9 windows10公网设置时间同步

  • 相关阅读:
    1230 jquery
    1221 监听事件
    1218 dom表格元素操作
    1216 DOM
    Java中对小数的向下取整,向上取整
    Mysql中 在SQL语句里进行日期格式转换
    一些常用格式化。价格、日期等 持续更新
    List对象里面根据某一字段去重
    java 后端 初始化图片像素(1980 x 1080)大小
    swagger里面测试List数据格式
  • 原文地址:https://www.cnblogs.com/anyux/p/7844260.html
Copyright © 2020-2023  润新知