标签:col 本地 inux correct 查看 协议 shel system when
两个服务都是centos自带的(centos7中不自带ntp)。ntp的安装包名是ntp;ntpdate的安装包是ntpdate。他们并非由一个安装包提供。
ntp守护进程为ntpd,配置文件是/etc/ntp.conf
ntpdate用于客户端的时间矫正,非NTP服务器可以不启动NTP。
yum install -y ntp
[root@master ~]# 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 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
启动ntp服务,并开机自启动
[root@master ~]# systemctl start ntpd
[root@master ~]# systemctl enable ntpd
【命令】ntpq -p
[root@master ~]# date
Tue Nov 17 21:24:24 CST 2020
[root@master ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
time.cloudflare .STEP. 16 u - 64 0 0.000 0.000 0.000
ntp7.flashdance .STEP. 16 u - 64 0 0.000 0.000 0.000
202.118.1.130 .STEP. 16 u - 64 0 0.000 0.000 0.000
*ntp5.flashdance 194.58.202.20 2 u 11 64 1 372.035 -17.860 28.092
[root@master ~]# ntpstat
synchronised to NTP server (193.182.111.14) at stratum 3
time correct to within 244 ms
polling server every 64 s
[root@master ~]# timedatectl
Local time: Tue 2020-11-17 22:37:02 CST
Universal time: Tue 2020-11-17 14:37:02 UTC
RTC time: Tue 2020-11-17 14:37:03
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[root@master ~]# ntpdate -u 193.182.111.14
17 Nov 22:38:10 ntpdate[7787]: adjust time server 193.182.111.14 offset 0.039557 sec
yum install -y ntp
2.3.1、修改配置文件
[root@slave1 ~]# vim /etc/ntp.conf
#配置允许NTP Server时间服务器主动修改本机的时间
restrict 192.168.1.111 nomodify notrap noquery
#配置时间服务器为本地搭建的NTP Server服务器
server 192.168.1.111
#注释掉其他时间服务器
#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
启动ntp服务,并开机自启动
systemctl start ntpd
systemctl enable ntpd
# 启动过几分钟查看
# 可以看到是192.168.1.111
[root@slave1 ~]# ntpstat
synchronised to NTP server (192.168.1.111) at stratum 4
time correct to within 1195 ms
polling server every 64 s
标签:col 本地 inux correct 查看 协议 shel system when
原文地址:https://www.cnblogs.com/hsyw/p/13997447.html