Linux time synchronization

Source: Internet
Author: User

[Turn from

Qing_gee's Column: http://blog.csdn.net/qing_gee/article/details/42234997

]

Preface : In our project, need to synchronize the time of the Linux server, so used the Ntpdate command, in the crontab is configured, set to every hour of the full-time minutes to synchronize, after the end has been no concern, because it is very simple, empiricism told me, Since the manual use of the Ntpdate command can synchronize time successfully, placed in the cron process (is a Linux daemon, if started, every minute to check the corresponding crontab file, the root user in/var/spool/cron) is even more no problem, However, after looking at the Linux server for a few minutes today, and the Windows time difference, our Linux service carries the futures trading platform's timing service, for example, 9:30 open and so on, which means the time is inaccurate ah, so the investigation to solve the problem, with the following record

1. Use the crontab-l command to view the timer service
[[email protected] xxx]# crontab-l0,10,20,30,40,50 * * * * ntpdate time.windows.com &>/xxx/ntpdate.log
2. It seems that there is no problem ah, Vim/var/spool/mail/root (the Timer service log will be stored in the file) to view the Timer service log, found the following information
/bin/sh:ntpdate:command not found
Describes the timer service in the/bin/sh directory to find the Ntpdate command, and did not find 3. Use the Whereis ntpdate command to see what directory the command is in
[Email protected] cron]# Whereis ntpdatentpdate:/usr/sbin/ntpdate/usr/share/man/man8/ntpdate.8.gz
Problem found, in the timer service, the ntpdate command to use the full path 4. Use the CRONTAB-E command to modify, plus the ntpdate command directory
0,10,20,30,40,50 * * * */usr/sbin/ntpdate time.windows.com &>/xxx/ntpdate.log
However, after the save, wait for the integer minutes, in the log did not find the command execution, why, guess as follows

A. The above command is malformed and the time format is incorrect.

B.cron Automatic service does not execute

Find the time by online command format to find

0,10,20,30,40,50 * * * *
And there is no error, and manual execution
/usr/sbin/ntpdate time.windows.com &>/xxx/ntpdate.log
Also successfully executed, let's see if there is a problem with B 5. Executive Ps-ef | grep cron to see if the time service process exists
[Email protected] xxx]# Ps-ef | grep cronroot     26157 22992  0 10:04 pts/3    00:00:00 grep cron
Found no cron execution process 6. Perform a service Crond status View
[Email protected] xxx]# service Crond Statuscrond is stopped
The service didn't start, okay. 7. Start the process and view the status
[[Email protected] xxx]# service Crond startstarting crond:                                            [  OK  ][[email protected] xxx]# service Crond Stat Uscrond (PID  26291) is running ... [Email protected] xxx]# Ps-ef | grep cronroot     26291     1  0 10:06?        00:00:00 crondroot     26302 22992  0 10:06 pts/3    00:00:00 grep cron
8. Service started, add the following statement via vim/etc/rc.d/rc.local command set to boot
/sbin/service Crond Start
Note also added to the/sbin directory 9. Finally, let's see if there are any execution logs in Ntpdate.log.
[email protected] xxx]# cat Ntpdate.log Dec 11:10:16 ntpdate[29960]: No server suitable for synchronization found
The discovery server did not find the corresponding service synchronization, then the conjecture should be time.windows.com server on this server did not succeed, because we use the Hong Kong cloud server, then a Hong Kong-approved address to try
0,10,20,30,40,50 * * * */usr/sbin/ntpdate stdtime.gov.hk &>/xxx/ntpdate.log
And then wait for the whole minute to look at it again.
[email protected] xxx]# cat Ntpdate.log Dec 11:20:01 ntpdate[30580]: Adjust time server 118.143.17.82 offset 0.015206 Sec
You can see that execution is successful.

Summary : Through the above problem survey, found that whenever empiricism is not reliable, a small problem can cause a lot of reasons.

Linux time synchronization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.