如何在 CentOS 中设置 NTP 服务器

如何在 CentOS 中设置 NTP 服务器,第1张

备 CentOS 服务器

现在让我们来开始在 CentOS 上设置 NTP 服务器。

首先,我们需要保证正确设置了服务器的时区。在 CentOS 7 中,我们可以使用 timedatectl 命令查看和更改服务器的时区(比如,"Australia/Adelaide",LCTT 译注:中国可设置为 Asia/Shanghai )

# timedatectl list-timezones | grep Australia

# timedatectl set-timezone Australia/Adelaide

# timedatectl

继续并使用 yum 安装需要的软件

# yum install ntp

然后我们会添加全球 NTP 服务器用于同步时间

# vim /etc/ntpconf

server 0oceaniapoolntporg

server 1oceaniapoolntporg

server 2oceaniapoolntporg

server 3oceaniapoolntporg

默认情况下,NTP 服务器的日志保存在 /var/log/messages。如果你希望使用自定义的日志文件,那也可以指定。

logfile /var/log/ntpdlog

如果你选择自定义日志文件,确保更改了它的属主和 SELinux 环境。

# chown ntp:ntp /var/log/ntpdlog

# chcon -t ntpd_log_t /var/log/ntpdlog

现在初始化 NTP 服务并确保把它添加到了开机启动。

# systemctl restart ntp

# systemctl enable ntp

验证 NTP Server 时钟

我们可以使用 ntpq 命令来检查本地服务器的时钟如何通过 NTP 同步。

控制到 NTP 服务器的访问

默认情况下,NTP 服务器允许来自所有主机的查询。如果你想过滤进来的 NTP 同步连接,你可以在你的防火墙中添加规则过滤流量。

# iptables -A INPUT -s 19216810/24 -p udp --dport 123 -j ACCEPT

# iptables -A INPUT -p udp --dport 123 -j DROP

该规则允许从 19216810/24 来的 NTP 流量(端口 UDP/123),任何其它网络的流量会被丢弃。你可以根据需要更改规则。

配置 NTP 客户端

1 Linux

NTP 客户端主机需要 ntpupdate 软件包来和服务器同步时间。可以轻松地使用 yum 或 apt-get 安装这个软件包。安装完软件包之后,用服务器的 IP 地址运行下面的命令。

# ntpdate <server-IP-address>

基于 RHEL 和 Debian 的系统命令都相同。

2 Windows

如果你正在使用 Windows,在日期和时间设置(Date and Time settings)下查找网络时间(Internet Time)。

3 Cisco 设备

如果你想要同步 Cisco 设备的时间,你可以在全局配置模式下使用下面的命令。

# ntp server <server-IP-address>

来自其它厂家的支持 NTP 的设备有自己的用于网络时间的参数。如果你想将设备和 NTP服务器同步时间,请查看设备的说明文档。

结论

总而言之,NTP 是在你的所有主机上同步时钟的一个协议。我们已经介绍了如何设置 NTP 服务器并使支持 NTP 的设备和服务器同步时间。

2107214544 (国家授时中心服务器IP地址)
ntpsjtueducn 2021202101 (上海交通大学网络中心NTP服务器地址)
s1atimeeducn 北京邮电大学
s1btimeeducn 清华大学
s1ctimeeducn 北京大学
s1dtimeeducn 东南大学
s1etimeeducn 清华大学
s2atimeeducn 清华大学
s2btimeeducn 清华大学
s2ctimeeducn 北京邮电大学
s2dtimeeducn 西南地区网络中心
s2etimeeducn 西北地区网络中心
s2ftimeeducn 东北地区网络中心
s2gtimeeducn 华东南地区网络中心
s2htimeeducn 四川大学网络管理中心
s2jtimeeducn 大连理工大学网络中心
s2ktimeeducn CERNET桂林主节点
s2mtimeeducn 北京大学

配置的时钟服务器的ip地址为192168100116

第一步  为服务器和客户机安装ntp  ntpdate

[root@sql-proxy1 app]#yum install ntp ntpdate -y第二步 查找时间同步服务器

>计算机时间同步化的一种协议,它可以使计算机对其服务器做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒)
服务器地址一般设在大学如;清华大学 北京大学


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13500468.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-19
下一篇 2023-08-19

发表评论

登录后才能评论

评论列表(0条)

保存