CentOS7上启用时间服务器、同步时间

2021-10-17 679点热度 0人点赞 0条评论

现在CentOS已不再区分客户端和服务器,只要配置了NTP,它就会提供NTP服务。

CentOS8上时间服务器的配置,会有不同,详见:https://blog.terrynow.com/2021/10/18/centos8-sync-time-automatically-with-chrony/

安装ntp

yum install ntp

配置时间源

修改配置文件/etc/ntp.conf

# vim /etc/ntp.conf
server ntp1.aliyun.com #可选择其他优先服务器
server ntp2.aliyun.com
server ntp3.aliyun.com
server ntp4.aliyun.com

配置是否为其他PC提供时间服务

修改配置文件/etc/ntp.conf,以下配置是为192.168.1.x网段提供ntp时间同步服务

# vim /etc/ntp.conf
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

配置开机时自动运行时间服务

systemctl enable ntpd

启动或停止时间服务

systemctl start ntpd
systemctl stop ntpd
systemctl restart ntpd

查看时间服务状态

systemctl status ntpd

初始同步/手动同步

# ntpdate -u time.lib.tsinghua.edu.cn
# ntpdate -u 192.168.21.15
ntpdate -u ntp.aliyun.com

确认同步成功

ntpq -p

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 localhost       .INIT.          16 l    -   64    0    0.000    0.000   0.000

同时建议修改一下 /etc/sysconfig/ntpd 文件

改成 yes 这样主机 BIOS 的时间也会跟着一起改变的 !

# vim /etc/sysconfig/ntpd

SYNC_HWCLOCK=yes

其他说明

如果要提供时间服务,如果服务器上有防火墙的话,还必须相应的设置iptable/firewalld防火墙的配置。CentOS的时间服务使用udp 123端口。

 

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论