配置三台服务器时间同步
三台服务器地址如下:
192.168.10.10 做服务器时间
192.168.10.20 同步10
192.168.10.30 同步10
1. 在192.168.10.10机器上修改 ntp.conf文件, vim /etc/ntp.conf
在文件中添加 :
##允许192.168.10.0/24 网段主机进行时间同步
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
#server指定ntp服务器的地址 将当前主机作为时间服务器
#fudge设置时间服务器的层级 stratum 0~15 ,0:表示顶级 , 10:通常用于给局域网主机提供时间服务 #注意:fudge必须和server一块用, 而且是在server的下一行
server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10
##下面两行为配置文件默认开启
includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
2. 保证BIOS(主板)与系统时间同步 ,在ntpd文件中添加 ,vim /etc/sysconfig/ntpd
SYNC_HWLOCK=yes
3.分别在另外两台服务器(20 30)中执行 ntpdate -u 192.168.10.10,并配置定时任务
crontab -e
*/1 * * * * /usr/sbin/ntpdate 192.168.10.10
配置完成!!!
ntp.conf配置文件详解
1、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 网段主机进行时间同步
2、server
作用:指定ntp服务器的地址
格式:server [ip or hostname] [perfer]
例子:server 127.127.1.0 <<<将当前主机作为时间服务器
3、fudge
作用:设置时间服务器的层级
格式:fudge ip [stratum int]
例子:fudge 10.225.5.1 stratum 10
注意:fudge必须和server一块用, 而且是在server的下一行
stratum
0~15
0:表示顶级
10:通常用于给局域网主机提供时间服务
下边为一些配置样例:
driftfile /var/lib/ntp/drift ##下面两行默认是拒绝所有来源的任何访问 restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery #开放本机的任何访问 restrict 127.0.0.1 restrict -6 ::1 #指定ntp服务器地址 server 192.168.33.44 #允许上层时间服务器主动修改本机时间 restrict 192.168.11.99 nomodify notrap noquery #外部时间服务器不可用时,以本地时间作为时间服务 server 127.127.1.0 fudge 127.127.1.0 stratum 10 ##下面两行为配置文件默认开启 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
driftfile详解:
我们每一个system clock的频率都有小小的误差,这个就是为什么机器运行一段时间后会不精确. NTP会自动来监测我们时钟的误差值并予以调整.但问题是这是一个冗长的过程,所以它会把记录下来的误差先写入driftfile.这样即使你重新开机以后之前的计算结果也就不会丢失了
参考:
https://blog.csdn.net/qq_35663625/article/details/103064495
https://www.cnblogs.com/hello-wei/p/11258625.html