Automatic date and time synchronization in centos (rdate and ntpdate)
There are at least two methods to synchronize time in linux:
Rdate and ntpdate. Centos installation is not installed by default. check whether it has been installed. otherwise, install it first.
WhereRdateIt is used to obtain the time on the remote time server. with the-s parameter, the obtained time can be applied to the local system.
NAME rdate - get the time via the networkSYNOPSIS rdate [-p] [-s] [-u] [-l] [-t sec] [host...]DESCRIPTION rdate connects to an RFC 868 time server over a TCP/IP network, printing the returned time and/or setting the system clock. OPTIONS -p Print the time returned by the remote machine. -s Set the system time to the returned time. -u Use UDP instead of TCP as the transport. -l Use syslog to output errors (cron.warning) and output (cron.info). -t Set timeout in seconds for every attempt to retreive date.
Rdate-s time.nist.gov
NtpdateIt is a tool used to synchronize time.
Example: ntpdate ntp.sjtu.edu.cn
NAME ntpdate-set the date and time via NTP Disclaimer: The functionality of this program is now available in the ntpd program. see the-q com-mand line option in the ntpd-Network Time Protocol (NTP) daemon page. after a suitable period of mourning, the ntpdate program is to be retired from this distributionSYNOPSIS ntpdate [-46 bBdqsuv] [-a key] [-e authdelay] [-k keyfile] [-o version] [-p samples] [-t timeout] [-U user_name] server [...] DESCRIPTION [Omitted. for details, refer to the linux man manual]
Date and time server
The synchronization time must have a time server. Generally, we do not need to build our own services. we can use public time services.
Refer to the domestic NTP server address and IP address http://www.douban.com/note/171309770/
The National Time Service Center does not seem to be available. we recommend that you use the ntp service ntp.sjtu.edu.cn or the United States Time Service Center time.nist.gov.
On the code, copy it to use
Rdate-s time.nist.gov
Ntpdate ntp.sjtu.edu.cn
It can be added to the crontab for scheduled execution.