一.配置server主机要求如下:
1.server主机的主机名称为 ntp_server.example.com
2.server主机的IP为: 172.25.254.100
3.server主机的时间为1984-11-11 11:11:11
4.配置server主机的时间同步服务要求可以被所有人使用
二.设定clinet主机要求如下
1.client主机的IP为:172.25.254.200
2.client主机的主机名称为: client.example.com
3.同步172.25.254.100主机的时间到达本机
4.用命令显示对于172.25.254.100主机的时间同步情况
一、改名字,看IP,修改server时间
(1)改名字
[root@server100 ~]# hostnamectl hostname ntp_server.example.com
[root@server100 ~]#
[root@server100 ~]# reboot
[root@server200 ~]# hostnamectl hostname client.example.com
[root@server200 ~]# reboot
(2)配置IP的命令:
配置主机IP的三种方法:
(3)时间改好
用timedatectl命令修改时间,需要先关闭时间同步
[root@ntpserver ~]# timedatectl set-time "1984-11-11 11:11:11"
Failed to set time: Automatic time synchronization is enabled
[root@ntpserver ~]# timedatectl set-ntp no
[root@ntpserver ~]# timedatectl set-time "1984-11-11 11:11:11"
[root@ntpserver ~]# timedatectl
Local time: Sun 1984-11-11 11:11:17 CST
Universal time: Sun 1984-11-11 03:11:17 UTC
RTC time: Sun 1984-11-11 03:11:18
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
(4)客户机的时间明显没有变,是公共ntp时间服务器的时间
二、配置server
/etc/chrony.conf是主配置文件
(1)编写
[root@ntpserver ~]# vim /etc/chrony.conf
(所有网段)
(2)重启时间服务器,查看端口信息
[root@ntpserver ~]# systemctl restart chronyd.service
[root@ntpserver ~]# netstat -antlupe | grep chrony
udp 0 0 0.0.0.0:123 0.0.0.0:* 0 33046 2545/chronyd
udp 0 0 127.0.0.1:323 0.0.0.0:* 0 33044 2545/chronyd
udp6 0 0 ::1:323 :::* 0 33045 2545/chronyd
[root@ntpserver ~]# timedatectl set-ntp yes //这个命令也是开启时间服务
[root@ntpserver ~]# timedatectl
Local time: Sun 1984-11-11 11:13:46 CST
Universal time: Sun 1984-11-11 03:13:46 UTC
RTC time: Sun 1984-11-11 03:13:46
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
(3)还需要关闭防火墙,使主机可以访问到
[root@ntpserver ~]# systemctl disable --now firewalld
[root@ntpserver ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; preset: enable>
Active: inactive (dead)
Docs: man:firewalld(1)
//inactive说明关闭了
服务器已经配置好
三、客户端连接
[root@client ~]# watch -n 1 timedatectl
//实时查看效果
(1)编辑主文件
[root@client ~]# vim /etc/chrony.conf
[root@client ~]# systemctl restart chronyd.service
[root@client ~]# chronyc sources -v
(2)连接上了服务器,等待同步
* 这个符号代表同步成功
监视器显示时间改变了
实现了时间同步,穿越1984年
拜拜~~
入睡小思考:为什么RTC(硬件时间)没有被同步?