Setting up a Linux server to synchronize with time server timing

Source: Internet
Author: User

In some large companies often appear such a situation: the company or some institutions of internal business System Application server and data are made of multi-machine cluster deployment and basically are Linux system, and are internal network, not with the external network communication. This often happens when I send a task later than the time it was received by the other task. This often makes us headache, that is why there is such a situation, in fact, the Linux machine system is not timed synchronization caused, this problem not only Linux system, Windows system will also have such problems, such as our Windows system has not been open for a long time, Then we will find that the time on the Windows system is incorrect, but why does the Windows system we use often do not have time inconsistencies, as our Windows system automatically synchronizes time with the remote standard Time server and calibrates the time errors that occur.

But here we say, is the intranet Linux system, can not communicate with the outside world and Linux because of its open reason also has a disadvantage, many things are not set dead, can only set themselves, especially the black command line system.

One way to teach you is to set up Linux to synchronize with an internal time server automatically, so that the time of multiple machines will always be consistent. Here are two main questions:

1. How do I synchronize with a specified time server for time calibration?

2. How to implement the Linux system service level timing execution?

OK, here are the two problems to solve in turn. First assume that our time server has an IP address of 192.168.1.10.

1. Time synchronization We use the command ntpdate, this command after the specific usage of my blog will be devoted to this issue, you can also view the command Help. Here you can use it directly:

192.168. 1.10

This allows synchronization with the 192.168.1.10 time server.

2. How to implement timed execution. The main purpose here is to use the/etc/crontab to achieve timing. This file is a Linux system timed dispatch file that will be loaded when the system is booted. First look at this file:

shell=/bin/Bashpath=/sbin:/bin:/usr/sbin:/usr/Binmailto=Roothome=/# for details seeMans 4crontabs# Example of Job definition:#.----------------Minute (0- -)# | .-------------Hour (0- at)# |  | .----------Day of Month (1- to)# |  |  | .-------Month (1- A) OR jan,feb,mar,apr ... #|  |  |  | .----Day of Week (0-6) (sunday=0Or7) OR sun,mon,tue,wed,thu,fri,sat#|  |  |  | |# *  *  *  *  *command to be executed~~~~
Look at this file, the front four lines can be ignored regardless. In fact, there is an example here, very easy to read, the key is this line:
* * * * * command to be    executed
The first * represents the minute, the second * represents the hour, the third * represents the day of one months, the fourth * represents the month, and the fifth * represents the day of the week. One means that any one can be represented directly by *. The previous five positions represent the commands and parameters to be executed.
So the timing of the implementation has been mastered, then our timing time synchronization calibration should be what?

First enter the/etc/crontab file
Vim  /etc/crontab

Insert a line timed to execute the synchronization code, assuming we do a time synchronization 1 o'clock in the morning every day. such as the following code:

xx 1 * * * Root  ntpdate-u 192.168.1.10

This allows us to set up the task of synchronizing the timing of the Linux server with the time server. Bingo! Isn't it easy?

If there is time, will later write about the use of the ntpdate command and the time server building.

Setting up a Linux server to synchronize with time server timing

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.