sky_cheng

导航

 

一、首先选择一台同步阿里云时间服务器

1、安装ntp

yum install ntp

2、配置ntp.conf

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

增加

restrict 172.28.5.0 mask 255.255.255.0 nomondify notrap

172.28.5.0为服务器间内网网段

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#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 ntp1.aliyun.com
server time1.aliyun.com
server 127.127.1.0

注释掉官方时间服务器,增加阿里云和本地时间服务器

3、启动ntp服务

systemctl start ntpd

4、查看状态

systemctl status ntpd
[root@localhost ~]# netstat -tunlp|grep ntpd
udp        0      0 172.28.5.102:123        0.0.0.0:*                           12743/ntpd          
udp        0      0 127.0.0.1:123           0.0.0.0:*                           12743/ntpd          
udp        0      0 0.0.0.0:123             0.0.0.0:*                           12743/ntpd          
udp6       0      0 fe80::d860:7229:c98:123 :::*                                12743/ntpd          
udp6       0      0 ::1:123                 :::*                                12743/ntpd          
udp6       0      0 :::123                  :::*                                12743/ntpd  

5、查看同步状态

[root@localhost ~]# ntpstat 
synchronised to NTP server (203.107.6.88) at stratum 3
   time correct to within 30 ms
   polling server every 1024 s
[root@localhost ~]# 

6、其他服务器部署NTP

yum install ntp

7、命令行执行ntpdate同步时间

[root@bogon ~]# /usr/sbin/ntpdate 172.28.5.102 && hwclock --systohc
26 Apr 09:53:03 ntpdate[20030]: adjust time server 172.28.5.102 offset 0.001725 sec

8、设置定时任务同步

*/30 * * * * /usr/sbin/ntpdate 172.28.5.102 && hwclock --systohc

 

 

 

posted on 2024-04-26 10:17  sky_cheng  阅读(151)  评论(0编辑  收藏  举报