任务要求
一.配置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主机的时间同步情况
一.配置server主机要求如下:
1.server主机的主机名称为 ntp_server.example.com
2.server主机的IP为: 172.25.254.100
3.server主机的时间为1984-11-11 11:11:11
4.配置server主机的时间同步服务要求可以被所有人使用
一.配置server主机要求如下:
1.server主机的主机名称为 ntp_server.example.com
[root@server200 ~]# hostnamectl set-hosetname ntp_server.example.com
2.server主机的IP为: 172.25.254.100
[root@server200 ~]# vmset.sh 100
3.server主机的时间为1984-11-11 11:11:11
[root@server200 ~]# systemctl stop chronyd.service #停止时间同步服务,便于修改时间
[root@server200 ~]# timedatectl set-time "1984-11-11 11:11:11"
4.配置server主机的时间同步服务要求可以被所有人使用
[root@server200 ~]# vim /etc/chrony.conf #进入chrony主配置文件中
26 allow 0.0.0.0/0 #找到第26行修改访问权限
[root@server200 ~]# systemctl restart chronyd #重启服务
5.最后关闭防火墙server主机的配置就完成了
[root@server200 ~]# systemctl disable --now firewalld (关闭防火墙)
[root@server200 ~]# hostnamectl hostname ntp_server.example.com
[root@server200 ~]# hostname
ntpserver.example.com
[root@server200 ~]# ifconfig | tr -s " " | grep broadcast | cut -d " " -f3
172.25.254.100
[root@server200 ~]# systemctl stop chronyd.service
[root@server200 ~]# timedatectl set-time "1984-11-11 11:11:11"
[root@server200 ~]# timedatectl
Local time: Sun 1984-11-11 11:11:15 CST
Universal time: Sun 1984-11-11 03:11:15 UTC
RTC time: Sun 1984-11-11 03:11:16
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
[root@server200 ~]# rpm -qc chrony
/etc/chrony.conf
/etc/chrony.keys
/etc/logrotate.d/chrony
/etc/sysconfig/chronyd
[root@server200 ~]# vim /etc/chrony.conf
# 修改如下几行
#需要把下面这行注释掉,才可以使客户端使用服务端特地设置的时间
# server ntp.aliyun.com iburst
allow 0.0.0.0/0
local stratum 10
# 重启服务
[root@server200 ~]# systemctl restart chronyd.service
# 为了保证clinet主机可以访问server主机的时间同步服务器,需要把防火墙关闭
[root@server200 ~]# systemctl disable --now firewalld.service
[root@server200 ~]# systemctl status firewalld.service
二.设定clinet主机要求如下
1.client主机的IP为:172.25.254.200
2.client主机的主机名称为: client.example.com
3.同步172.25.254.100主机的时间到达本机
4.用命令显示对于172.25.254.100主机的时间同步情况
1.client主机的IP为:172.25.254.200
[root@server200 ~]# vmset.sh 200
2.client主机的主机名称为: client.example.com
[root@server200 ~]# hostnamectl set-hosetname client.example.com
3.同步172.25.254.100主机的时间到达本机
[root@server200 ~]# systemctl disable --now firewalld #关闭防火墙
[root@server200 ~]# hostnamectl stop chronyd.service #先关闭时间同步服务
[root@server200 ~]# vim /etc/chrony.conf # 修改第3行为server的地址
server 172.25.154.100 iburst
[root@server200 ~]# systemctl restart chronyd #重启服务
[root@server200 ~]# chronyc sources -v #测试
4.用命令显示对于172.25.254.100主机的时间同步情况
[root@client ~]# timedatectl status #查看同步情况
[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
===============================================================================
^* server100.xushaoliang.org 3 6 1 9 +372ms[ +372ms] +/- 57ms
[root@server200 ~]# ifconfig | tr -s " " | grep broadcast | cut -d " " -f3
172.25.254.200
[root@server200 ~]# hostnamectl hostname client.example.com
[root@server200 ~]# hostname
client.example.com
[root@server200 ~]# vim /etc/chrony.conf
# 需要下面这一行进行修改
server 172.25.254.100 iburst
[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
===============================================================================
^* 172.25.254.100 10 6 377 84 +12us[ +21us] +/- 129us
[root@client ~]# timedatectl
Local time: Sun 1984-11-11 11:53:14 CST
Universal time: Sun 1984-11-11 03:53:14 UTC
RTC time: Sun 1984-11-11 03:53:14
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no