ntp介绍
NTP是用来使系统和一个精确的时间源保持时间同步的协议.在Linux下,我们可以通过自带的NTP(Network Time Protocol)协议通过网络使自己的系统保持精确的时间.
ntp服务端
#调整时区
timedatectl set-timezone Asia/Shanghai
#(1)安装ntp
[root@localhost ~]# yum install ntp -y
[root@localhost ~]# mkdir /var/lib/ntp/
[root@localhost ~]# mkdir /var/log/ntp/
#(2)修改 /etc/ntp.conf
[root@localhost ~]# cp /etc/ntp.conf{,.bak}
[root@localhost ~]# vim /etc/ntp.conf
driftfile /var/lib/ntp/ #记录当前时间服务器,与上游服务器的时间差的文件
#restrict default nomodify notrap nopeer noquery
restrict 192.168.17.0 mask 255.255.255.0 nomodify #允许192.168.17.0/24网段的所有主机使用该时间服务器进行时间同步
restrict 10.10.10.0 mask 255.255.255.0 nomodify #允许10.10.10.0/24网段的所有主机使用该时间服务器进行时间同步
restrict 127.0.0.1 # 允许本机使用这个时间服务器
server 114.118.7.161 prefer # ntp.ntsc.ac.cn解析后的地址114.118.7.161优先
server 114.118.7.163 # ntp.ntsc.ac.cn解析后的地址114.118.7.163