0
点赞
收藏
分享

微信扫一扫

Centos下部署NTP时间服务器同步环境记录

四月天2021 2022-08-30 阅读 175

Centos下部署NTP时间服务器同步环境记录

我是在购买的3A平台购买的服务器进行测试。

服务端部署

  1. 安装所需软件包

    [root@test ~]# yum -y install ntp ntpdate
  2. 服务端自己先手工同步一次时间

    [root@test ~]# ntpdate ntp.sjtu.edu.cn
  3. 编辑NTP主配置文件,添加NTP服务器(对于大陆地区的服务器)并同步BIOS时间。

    对于位于中国大陆地区IDC机房的服务器,由于CentOS/RHEL默认的ntp服务器无法访问,因此要设置中国大陆地区自己的ntp服务器; 对于位于中国大陆地区以外的IDC机房的服务器,可以使用CentOS/RHEL默认的ntp服务器(但一定要检查确保可以访问);

    修改如下:

    [root@test ~]# cp /etc/ntp.conf /etc/ntp.conf.bak
    [root@test ~]# vim /etc/ntp.conf
    restrict default nomodify notrap noquery
    
    restrict 127.0.0.1
    restrict 192.168.0.0 mask 255.255.0.0 nomodify     #只允许192.168.0.0网段的客户机进行时间同步。如果允许任何IP的客户机都可以进行时间同步,就修改为"restrict default nomodify"
    
    server ntp1.aliyun.com
    server ntp2.aliyun.com
    server time1.aliyun.com
    server time2.aliyun.com
    
    server time-a.nist.gov
    server time-b.nist.gov
    
    server  127.127.1.0     # local clock
    fudge   127.127.1.0 stratum 10
    
    driftfile /var/lib/ntp/drift
    broadcastdelay  0.008
    keys            /etc/ntp/keys
    
    [root@test ~]# service ntpd start
    Starting ntpd:                                             [  OK  ]
    
    [root@test ~]# netstat -tulnp | grep ntp
    udp        0      0 182.48.115.233:123          0.0.0.0:*                               10023/ntpd         
    udp        0      0 127.0.0.1:123               0.0.0.0:*                               10023/ntpd         
    udp        0      0 0.0.0.0:123                 0.0.0.0:*                               10023/ntpd         
    udp        0      0 fe80::5054:ff:feab:db19:123 :::*                                    10023/ntpd         
    udp        0      0 ::1:123                     :::*                                    10023/ntpd         
    udp        0      0 :::123                      :::*   
  4. 设置开机自启动

    [root@test ~]# /sbin/chkconfig --level=2345 ntpd on
  5. 查看现有连接客户端

    [root@test ~]# watch ntpq -p
  6. 服务端可以设置定期在线同步一次时间

    [root@test ~]# crontab -l
    #服务器时间同步
    0 * * * *  /usr/sbin/ntpdate ntp1.aliyun.com; /sbin/hwclock -w

    客户端配置

    [root@test2 ~]# ntpdate 182.148.15.33             #182.148.15.33是上面ntp服务器的ip地址

    配置自动同步

    [root@test2 ~]# crontab -l
    #服务器时间同步
    */5 * * * *  /usr/sbin/ntpdate 182.148.15.33; /sbin/hwclock -w
举报

相关推荐

0 条评论