There are two methods to adjust the system time on CentOS:
- Manually Update Using the
date
Command
The date
command can be used to view and modify the system time.
To check the current system time, use the following command:
|
|
The output will be similar to:
|
|
To modify the system time, use the following command:
|
|
The output will be similar to:
|
|
- Automatically Update Using the
ntpdate
Command
In CentOS, the ntpdate
command is used to synchronize the system time with a time server via the Network Time Protocol (NTP). It is simple to use, but there are various options to adjust the synchronization behavior.
Here are some common usages of the ntpdate
command:
Simple Synchronization:
ntpdate <server_address>
: Synchronize the system time with the specified server. For example,ntpdate cn.pool.ntp.org
synchronizes with the National Time Service Center NTP server in China. You can also use ntp.aliyun.com as an NTP time source.ntpdate -u <server_address>
: Update the system time to synchronize with the specified server, even if the current time deviation is below the default threshold.
Query Time:
ntpdate -q <server_address>
: Only query the time from the specified server without synchronizing.
Other Options:
-b
: Force synchronization even if an NTP service is already running.-p <port>
: Specify the port number to connect to the NTP server, with the default port being 123.-v
: Increase output verbosity to display more information about the synchronization process.
Notes:
- Using
ntpdate
may cause the system time to jump suddenly, which can affect certain applications. For smoother time synchronization, it is recommended to use thentpd
service. - Ensure that the NTP server being used is reliable and compatible with your time zone.
I hope this information helps you use the ntpdate
command to synchronize the system time on your CentOS server.