Linux automatic synchronization server time and linux synchronization server

Source: Internet
Author: User

Linux automatic synchronization server time and linux synchronization server
Introduction

When a Linux server runs for a long time, there will be some errors in the system time. This article will introduce how to synchronize the server time with the network server time.

Environment: centos

 

 

Network Time Server

First, make sure these servers can be pinged. Otherwise, time synchronization will fail. Otherwise, the error "no server suitable for synchronization found" will be reported"

  • China National Time Service Center: 210.72.145.44 ---- unavailable for the time being
  • NTP server (Shanghai): ntp. api. bz
  • China ntp server: cn.pool.ntp.org
  • Pool.ntp.org

Time Synchronization Tool

Rdate: rdate-s

Ntpdate: ntpdate-u (using the-u parameter will return an error, you can also use-s)

Both of the above tools can be used to synchronize network time servers. centos is installed by default. Both tools are easy to use. This chapter mainly introduces the ntpdate tool. The installation method is as follows:

yum -y install ntp

Synchronization time

1. Modify the time zone

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Vim/etc/sysconfig/clock

ZONE="Asia/Shanghai"UTC=falseARC=false

2. Synchronization time

/usr/sbin/ntpdate -u cn.pool.ntp.org

3. Hardware write time

Each time the server is restarted, it will refer to the hardware time. Therefore, you need to write the current system time to the hardware.

View the current hardware time:

hwclock -r
[root@localhost ~]# hwclock -rThu 12 May 2016 08:05:43 PM CST  -0.674165 seconds

Hardware write time:

hwclock -w

Automatic Time Synchronization

1. Configure Boot Check

Vim/etc/rc. d/rc. local

/usr/sbin/ntpdate -u cn.pool.ntp.org> /dev/null 2>&1; /sbin/hwclock -w

2. configure a scheduled task

Vim/etc/crontab

00 10 * * * root /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null 2>&1; /sbin/hwclock -w 

Or

Crontab-e

00 10 * * * /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null 2>&1; /sbin/hwclock -w
Summary

For more information about scheduled tasks, see my previous article: http://www.cnblogs.com/chenmh/p/5430258.html.

 

 

 

Note:

Author: pursuer. chen

Blog: http://www.cnblogs.com/chenmh

All essays on this site are original. You are welcome to repost them. However, you must indicate the source of the article and clearly give the link at the beginning of the article.

Welcome to discussion

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.