一.配置server主机要求如下:
1.server主机的主机名称为 ntp_server.example.com
[root@xixi ~]# hostnamectl hostname ntp_server.example.com
[root@xixi ~]# hostname
ntpserver.example.com
[root@xixi ~]# reboot
[root@ntpserver ~]#
2.server主机的IP为: 172.25.254.100
查看IP(我本人没有改地址)
[root@ntpserver ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:44:60:4c brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.17.131/24 brd 192.168.17.255 scope global dynamic noprefixroute ens160
valid_lft 1649sec preferred_lft 1649sec
inet6 fe80::20c:29ff:fe44:604c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
修改IP地址
[root@ntpserver ~]#nmcli con mod ens160 ipv4.method manual ipv4.address 172.25.254.100/24 ipv4.gateway 172.25.254.2 ipv4.dns 223.5.5.5 autoconnect yes
3.server主机的时间为1984-11-11 11:11:11
[root@ntpserver ~]# systemctl stop chronyd.service
[root@ntpserver ~]# timedatectl set-time "1984-11-11 11:11:11"
[root@ntpserver ~]# timedatectl
Local time: Sun 1984-11-11 11:12:46 CST
Universal time: Sun 1984-11-11 03:12:46 UTC
RTC time: Sun 1984-11-11 03:12:46
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
4.配置server主机的时间同步服务要求可以被所有人使用
[root@ntpserver ~]# vim /etc/chrony.conf
'
pool ntp.aliyun.com iburst
allow 0.0.0.0/0
local stratum 10
'
二.设定clinet主机要求如下
1.client主机的IP为:172.25.254.200(我没有改地址)
[root@haha ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:1b:73:7b brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.17.138/24 brd 192.168.17.255 scope global dynamic noprefixroute ens160
valid_lft 1410sec preferred_lft 1410sec
inet6 fe80::20c:29ff:fe1b:737b/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@haha ~]#
修改IP地址
[root@ntpserver ~]#nmcli con mod ens160 ipv4.method manual ipv4.address 172.25.254.200/24 ipv4.gateway 172.25.254.2 ipv4.dns 223.5.5.5 autoconnect yes
2.client主机的主机名称为: client.example.com
[root@xixi ~]# hostnamectl hostname client.example.com
[root@haha ~]# reboot
[root@haha ~]# Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(备份) at 21:05:03.
Type `help' to learn how to use Xshell prompt.
[D:\~]$
Connecting to 192.168.17.138:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Activate the web console with: systemctl enable --now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Tue Apr 16 21:05:25 2024 from 192.168.17.1
[root@client ~]# hostname
client.example.com
3.同步172.25.254.100主机的时间到达本机
vim /etc/chrony.conf
'
server 192.168.17.131 iburst
/*由于我的服务器地址没有修改所以用的是:192.168.17.131
如果你修改了的话请注释掉上面一行并把下面一行的#去掉*/
#server 172.25.254.100 iburst
'
4.用命令显示对于172.25.254.100主机的时间同步情况
[root@client ~]# chronyc sources -v
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.17.131 3 6 17 9 -78us[ -105us] +/- 118ms
[root@client ~]#