CentOS 8 enable NTP service

What is NTP service and why do we need to enable NTP service on our server?

Many people may not know it very well. Simply put, we want our server time to be accurate and without bias. The meaning of this is accurate when data is inserted and when your program gets computer time.

For example, in Java, if new date() will get the current time of the computer, if the current world is inaccurate, then the time you insert into the database is confusing.

At the same time, we also hope that the time zone of our server is accurate, such as the Eastern Eighth Zone and US Pacific Time that we often use.

If the computer is slow for any reason, we can synchronize through ntp.

So for the server, after setting the time zone, the NTP service must be enabled.

NTP introduction##

Network Time Protocol, English name: Network Time Protocol (NTP) is a protocol used to synchronize computers [time synchronization, which can make computers synchronize their servers or clock sources such as quartz clocks, GPS, etc.). It can Provide high-precision time correction (the difference between the LAN and the standard is less than 1 millisecond, and the WAN is tens of milliseconds), and can prevent malicious attacks by means of encrypted confirmation.

The purpose of NTP is to provide accurate and robust time services in a disorderly Internet environment.

NTP provides accurate time. First of all, there must be an accurate time source. This time should be UTC.

The time source for NTP to obtain UTC can be atomic clocks, observatories, satellites, or from the Internet. In this way, there is an accurate and reliable time source. The time is transmitted according to the level of the NTP server.

All servers are classified into different Stratum according to the distance from the external UTC source. Stratum-1 is on the top layer and has external UTC access, while Stratum-2 gets the time from Stratum-1, Stratum-3 gets the time from Stratum-2, and so on, but the total number of Stratum layers is limited to 15.

All these servers are logically connected to each other in a stepped structure, and the Stratum-1 time server is the basis of the entire system. A computer host is generally connected to multiple time servers, and statistical algorithms are used to filter the time from different servers to select the best path and source to correct the host time. Even if the host is unable to contact a certain time server for a long time, the NTP service still works effectively.

In order to prevent malicious damage to the time server, NTP uses an authentication mechanism to check whether the information coming to the time is actually from the claimed server and check the return path of the data to provide a protection mechanism against interference. The time contained in the NTP time synchronization message is Greenwich Mean Time, which is the number of seconds since 1900.

Install NTP service##

In CentOS 8, we use chronyd to provide NTP services.

Execute the following command on CentOS to install it. If you have already installed it, the system will prompt you.

dnf install chrony

Enable NTP service##

In CentOS 8, execute the following command to let the service process start automatically with boot.

systemctl enable chronyd

The above command will run automatically when the computer is turned on.

Check server NTP server address##

Please execute the following command to confirm that the address of the NTP server has been configured successfully.

chronyc sources 

The above command will display the default configured NTP server address.

Force synchronization##

After installing the operating system, you may encounter inaccurate time.

You can use the following command to force synchronization of the server world once.

chronyc -a makestep

The input of the server is:

[ root@vps-c853c8ac home]# chronyc -a makestep
200 OK
[ root@vps-c853c8ac home]# 

Then it can be executed on the server

date +%z

To determine the current time zone and you can use date to determine the current server time.

date

With this setting, we can use NTP to synchronize on the server, and you don't need to adjust the server time.

https://www.ossez.com/t/centos-8-ntp/555

Recommended Posts

CentOS 8 enable NTP service
CentOS 7 set up NTP, SSH service
CentOS 7 install Docker service
CentOS 7 deploys RabbitMQ service
CentOS 7 deploy saltstack service
CentOS 8 Apache enable SSL
CentOS7 deploys NFS service
Centos7 build DNS service
Centos6.8 deploy vnc service
CentOS7 deploy vsftp (FTP) service
CentOs7.3 build Solr stand-alone service
CentOs7.3 build RabbitMQ 3.6 stand-alone service
CentOs7.3 build ZooKeeper-3.4.9 stand-alone service
Centos7.2 deployment vnc service record
CentOs7.3 build SolrCloud cluster service
Centos 7 install jdk and package service service
CentOS 8 (2)
CentOS builds a cloud service platform
CentOS 8 - install and configure NFS service
CentOS 8 (1)
CentOS 7 Tomcat service installation and configuration
CentOS NTP server installation and configuration
Use NTP for time synchronization in CentOS 7
Build WeChat applet service based on CentOS
CentOS8 deploys KMS service to activate Office
Create CentOS Docker image with httpd service
CentOS7 build gerrit code review service method