时间同步是使客户端与服务器的时间同步
配置条件: 需要两台或两台以上的主机进行操作,需要一台服务器端,其余主机都是客户端。
server:192.168.120.10
client1:192.168.120.20
配置方式:
1.服务器端
[root@centos7 ~]# yum install -y ntp* #安装ntp服务
[root@centos7 ~]# vi /etc/ntp.conf #配置ntp文件
restrict 192.168.120.0 mask 255.255.255.0 nomodify notrap #去掉#,修改为指定的网段
server 127.127.1.0 #以本机服务器为时间同步服务器
fudge 127.127.1.0 stratum 10 #fudge设置层级关系
[root@centos7 ~]# systemctl start ntp #启动ntp服务
[root@centos7 ~]# systemctl enable ntp #开机自启ntp服务
[root@centos7 ~]# timedatectl
Local time: Sat 2021-08-28 09:32:08 CST
Universal time: Sat 2021-08-28 01:32:08 UTC
RTC time: Sat 2021-08-28 01:32:08
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
2.客户端配置
[root@centos7 ~]# yum install -y ntp*
[root@centos7 ~]# vi /etc/ntp.conf
restrict 192.168.120.0 mask 255.255.255.0 nomodify notrap #去掉#,修改为指定的网段
server 127.127.1.0 #以本机服务器为时间同步服务器
fudge 127.127.1.0 stratum 10 #fudge设置层级关系
[root@centos7 ~]# systemctl start ntp #启动ntp服务
[root@centos7 ~]# systemctl enable ntp #开机自启ntp服务
[root@centos7 ~]# timedatectl #查看是否时间相同
Local time: Sat 2021-08-28 09:32:08 CST
Universal time: Sat 2021-08-28 01:32:08 UTC
RTC time: Sat 2021-08-28 01:32:08
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
须知
这样就做完了,如果没有同步需等待一会。
注意:等待了一会时间还是未能同步需关闭防火墙,或者放行ntp的端口