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.
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.
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
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.
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.
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