linux同步系统时间_如何在Linux中同步系统时间?

linux同步系统时间

linux同步系统时间

Time is important for systems because all work done according to time and logs get their timestamps. Normally server hardware provides time but it can be false over time because the hardware clock is not precise. Ntp is a protocol designed to get time info from the network. NTP can also provide date and time information to other servers as a daemon. NTP full name is Network Time Protocol.

时间对系统很重要,因为所有根据时间和日志完成的工作都会获得时间戳。 通常,服务器硬件会提供时间,但随着时间的流逝,它可能是错误的,因为硬件时钟不精确。 Ntp是一种旨在从网络获取时间信息的协议。 NTP还可以将日期和时间信息作为守护程序提供给其他服务器。 NTP全名是网络时间协议。

安装Ntpdate (Install Ntpdate)

Ntpdate is simple and fast ntp client used to get information about time.

Ntpdate是一种简单而快速的ntp客户端,用于获取有关时间的信息。

CentOS, Fedora, Red Hat

CentOS,Fedora,Red Hat

$ yum install ntpdate -y

Ubuntu, Debian, Mint, Kali

Ubuntu,Debian,Mint,Kali

$ sudo apt-get install ntpdate

从Ntp服务器获取时间 (Get Time From Ntp Server)

We can use ntpdate client to get the current time from the NTP server. We will specify the NTP server as a parameter to the ntpdate command.

我们可以使用ntpdate客户端从NTP服务器获取当前时间。 我们将NTP服务器指定为ntpdate命令的参数。

$ sudo ntpdate ntp.ubuntu.com 
16 Nov 07:06:12 ntpdate[4551]: adjust time server 91.189.89.199 offset -0.000030 sec

We need root privileges to use ntpdate to sync clock

我们需要root特权才能使用ntpdate同步时钟

从本地服务器检查当前时间(Check Current Time From Local Server)

We can list current time in the server by using date command.

我们可以使用date命令列出服务器中的当前时间。

$ date 
Wed Nov 16 07:07:42 +03 2016

Enable Firewall For Ntp Related Ports

为Ntp相关端口启用防火墙

We may need to open ports about NTP like below by using iptables

我们可能需要使用iptables来打开有关NTP的端口,如下所示

$ iptables -A output -p udp -s 192.168.1.1 --sport 1024:65535 -d 0/0  --dport 123 -m state --state NEW,ESTABLISHED -j ACCEPT
$ iptables -A input -p udp -s 0/0 --sport 123 -d 192.168.1.1  --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

获取当前时间信息 (Get Current Time Info)

ntpdate is an old tool and deprecated we can use datetimectl according to ntpdate

ntpdate是一个旧工具,不赞成使用,我们可以根据ntpdate使用datetimectl

$ timedatectl status
Get Current Time Info
Get Current Time Info
获取当前时间信息

We see that our time is synchronized with ntp with “NTP synchronized” line.

我们看到,我们的时间与“ NTP同步”行的ntp同步。

LEARN MORE  TCP and UDP Port List, Names and Usage Frequency
了解更多TCP和UDP端口列表,名称和使用频率

如何在Linux中同步系统时间? 信息图 (How To Synchronize System Time In Linux? Infographic)

How To Synchronize System Time In Linux? Infographic
How To Synchronize System Time In Linux? Infographic
如何在Linux中同步系统时间? 信息图

翻译自: https://www.poftut.com/synchronize-system-time-linux/

linux同步系统时间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值