时间同步
安装ntp服务
yum –y install ntp
配置详解 /etc/ntp.conf
-
restrict
作用:对ntp做权限控制
ignore:忽略所有类型的NTP连接请求
nomodify:限制客户端不能使用命令ntpc和ntpq来修改服务器端的时间
noquery:不提供NTP网络校时服务
notrap:不接受远程登录请求
notrust:不接受没有经过认证的客户端的请求
【如果没有用任何参数,那么表示不做任何限制】
例子:restrict 10.220.5.0 mask 255.255.255.0 nomodify <<<允许10.220.5.0/24 网段主机进行时间同步 -
server
作用:指定ntp服务器的地址
格式:server [ip or hostname] [perfer]
例子:server 127.127.1.0 <<<将当前主机作为时间服务器 -
fudge
作用:设置时间服务器的层级
格式:fudge ip [stratum int]
例子:fudge 10.225.5.1 stratum 10
注意:fudge必须和server一块用, 而且是在server的下一行
stratum
0~15
0:表示顶级
10:通常用于给局域网主机提供时间服务
配置ntp服务
-
配置主节点(使用当前主机作为时间服务器)
vi /etc/ntp.conf # local clock server 127.127.1.0 fudge 127.127.1.0 stratum 10
-
配置其他节点
启动ntp,设置开机自启动
# 启动
systemctl start ntpd
# 查看状态
systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-03-22 12:33:07 CST; 21h ago
Process: 14381 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 14382 (ntpd)
CGroup: /system.slice/ntpd.service
└─14382 /usr/sbin/ntpd -u ntp:ntp -g
systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
查看状态
刚启动的时候,出现unsynchronised很正常,因为ntp不同与ntpdate,ntp是平滑同步,所以等个几分钟就可以同步成功了
ntpstat
synchronised to NTP server (10.25.18.216) at stratum 12
time correct to within 50 ms
polling server every 1024 s