yum -y install ntp systemctl status ntpd.service #查看服务状态 systemctl enable ntpd.service #开机自启动 systemctl start ntpd.service #启动服务 使用ntp服务前,手动同步一下时间 [root@localhost etc]# ntpdate ntp1.aliyun.com 30 Jan 14:09:47 ntpdate[24355]: step time server 182.92.12.11 offset 286552312.576158 sec 同步硬件时间。 [root@localhost ~]# hwclock --systohc 配置ntp [root@localhost ~]# cat /etc/ntp.conf # ntp.conf driftfile /var/lib/ntp/drift pidfile /var/run/ntpd.pid logfile /var/log/ntp.log # Access Control Support restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 # local clock server 127.127.1.0 fudge 127.127.1.0 stratum 10 server ntp1.aliyun.com server ntp2.aliyun.com server ntp3.aliyun.com server ntp4.aliyun.com server ntp5.aliyun.com server ntp6.aliyun.com server ntp7.aliyun.com server 0.cn.pool.ntp.org server 1.cn.pool.ntp.org server 2.cn.pool.ntp.org server 3.cn.pool.ntp.org systemctl reload ntpd.service #加载服务 查看ntp服务状态,启动后10分钟左右再查看。 [root@localhost ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== LOCAL(0) .LOCL. 10 l 68 64 376 0.000 0.000 0.000 -time5.aliyun.co 10.137.38.86 2 u 58 64 357 11.824 0.201 0.087 +120.25.115.19 10.137.53.7 2 u 48 64 377 46.451 -1.128 0.074 +120.25.115.20 10.137.53.7 2 u 47 64 377 46.404 -1.206 0.089 -time4.aliyun.co 10.137.53.7 2 u 50 64 377 49.221 0.258 0.085 *203.107.6.88 100.107.25.114 2 u 52 64 377 0.331 -1.394 0.080 -dns1.synet.edu. 202.118.1.46 2 u 46 64 377 36.005 -5.682 0.103 gus.buptnet.edu .INIT. 16 u 47 64 336 31.924 -6.838 0.134 -darwin.kenyonra 127.67.113.92 2 u 47 64 377 161.102 6.760 0.143 * 号表示正在使用的上游NTP服务器,+ 号表示已经连接上的备用的NTP服务器 本人是阿里云ecs,所以安全组允许udp123端口 [root@localhost ~]# firewall-cmd --add-service=ntp --permanent [root@localhost ~]# firewall-cmd --reload