RDATE,NTPDATE,NTP Automatic synchronization Date-time method under Linux

Source: Internet
Author: User

Automatic synchronization via network NTP

If you only need to sync once, execute the following command

Rdate-s time.nist.gov

Where time.nist.gov is a time server, of course you can also use another time server.

If multiple servers require a full synchronization of time, it is best to configure these servers with a unified, automatic synchronization task, so that their time is biased for a variety of reasons. Methods are as follows

Use crontab to let Linux automatically sync time

Vi/etc/crontab

Add a sentence:

0 1 * * Root rdate-s time.nist.gov


Time.nist.gov is a time server.

Rdate Sync Configuration

CentOS minimized installation is not installed by default, first confirm already installed, otherwise install first.

Where Rdate itself is used to obtain time on a remote time server, with the-s parameter, you can apply the acquired time to the local system.

NAME
Rdate-get the time via the network

Synopsis
Rdate [-P] [s] [-u] [-l] [-t sec] [host ...]

DESCRIPTION
Rdate connects to an RFC www.111cn.net 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

Ntpdate itself is the tool used to synchronize time.

Example: Ntpdate ntp.sjtu.edu.cn

NAME
Ntpdate-set the date and time via NTP

Disclaimer:the functionality of the This are now available in the NTPD program. The-q com-
Mand line option in the Ntpd-network time Protocol (NTP) daemon page. After a suitable period of
Mourning, the Ntpdate program are to being retired from this distribution

Synopsis
ntpdate [ -46BBDQSUV] [-a key] [e-Authdelay] [-K keyfile] [-o version] [-p samples] [t
Timeout] [-u user_name] server [...]

DESCRIPTION

[Refer to the Linux Man manual]

Linux Cluster time synchronization

Plans to sync 11 Linux cluster times, operating system for Ubuntu 11.04 x86 64-bit
Select one of the 133.133.10.2 as the time server (NTP server), while the other nodes are synchronized with the node.

1, install NTP server on 133.133.10.2 (monitor).
root@monitor:~# Apt-get Install NTP

2. Modify/etc/ntp.conf


#/etc/ntp.conf, configuration for ntpd; Ntp.conf (5) for help

Driftfile/var/lib/ntp/ntp.drift


# Enable This if you are want statistics to be logged.
#statsdir/var/log/ntpstats/

Statistics Loopstats peerstats clockstats
Filegen loopstats file Loopstats type Day enable
Filegen peerstats file Peerstats type Day enable
Filegen clockstats file Clockstats type Day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). Http://www.pool.ntp.org/join.html for
# more information.
#server 0.ubuntu.pool.ntp.org
#server 1.ubuntu.pool.ntp.org
#server 2.ubuntu.pool.ntp.org
#server 3.ubuntu.pool.ntp.org

# use Ubuntu ' s NTP server as a fallback.
#server ntp.ubuntu.com
Server 127.127.1.0 minpoll 4 maxpoll 5
Fudge 127.127.1.0 Stratum 2

# Access control configuration; See/usr/share/doc/ntp-doc/html/accopt.html for
# details. The Web page # might also be helpful.
#
# "Restrict" applies to both servers and clients, so a configuration
# that might is intended to the requests from certain clients could
# up blocking replies from your own upstream servers.

# By default, Exchange time with everybody, but don ' t allow configuration.
#restrict-4 default kod notrap nomodify nopeer noquery
#restrict-6 default kod notrap nomodify nopeer noquery
restrict-4 Default Kod nomodify noper
restrict-6 Default Kod nomodify noper

# Local Users may interrogate the NTP server more closely.
Restrict 127.0.0.1
Restrict:: 1

# Clients from-(example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 Mask 255.255.255.0 notrust


# If you are want to provide time to your local subnet and change the next line.
# (Again, the address is a example only.)
#broadcast 192.168.123.255

# If you are want to listen to broadcasts on your local subnet, de-comment the
# Next lines. Please does this is only if your everybody on the network!
#disable Auth
#broadcastclient

3. Run ntpdate command

First restart the NTP service
ROOT@MONITOR:/ETC#/ETC/INIT.D/NTP restart

Run again
root@monitor:/etc# ntpdate-q 127.0.0.1
Get
Server 127.0.0.1, stratum 3, offset-0.000003, delay 0.02565
Sep 17:12:00 ntpdate[11502]: Adjust time server 127.0.0.1 offset-0.000003 sec

4, the other nodes 133.133.10.* time and 133.133.10.2 synchronization

Run commands on every other node

root@slave1:~# ntpdate 133.133.10.2

At this time to find the synchronization between the nodes, but ntpdate only on the run, we want to set to 1-hour sync, then proceed to step 5th

5, the other nodes 133.133.10.* time and 133.133.10.2 synchronization

Use crontab to automatically update the time after installation:
#crontab-E
Add the following line:
* */1 * * * */usr/sbin/ntpdate 133.133.10.2

This line means that each hour is synchronized with the 133.133.10.2 time.

6, through the date command found all nodes time is the same

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.