Adjust the CentOS system time and time zone to synchronize with the Internet

Source: Internet
Author: User
The procedure is as follows: 1. change the time zone # cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime to Dongba district of China # vi/etc/sysconfig/clockZONE = & quot; asia/Shanghai & quot; UTC = falseARC = false 2,

The procedure is as follows:

1. modify the time zone
# Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
Change to UTC + 8 in China
# Vi/etc/sysconfig/clock
ZONE = "Asia/Shanghai"
UTC = false

ARC = false

 

2. configure a new time
Date setting:
# Date-s 2013/09/26

Time setting:

# Date-s 11:47:06

# Date-s "12:00:00"

# Date-s "12:00:00 20131206"

# Date-s "12:00:00"

# Date-s "20131206 12:00:00"

Date indicates the OS time displayed.

Clock is the time when the Bios is displayed.

View hardware Time (BIOS ):
Hwclock [-rw]
-R: view the current BIOS time. the default value is-r.

-W: write the current linux system time to the BIOS

-S (systohc): adjust the hardware time to be the same as the current system time

# Hwclock-s:

# Hwclock-w: update linux internal time to bios/cmos

When we finish the Linux time, we also need to use hwclock-w to update the BIOS time, because every time the system is started, the BIOS will read the time again, therefore, BIOS is an important time basis.
# Hwclock

Thursday, September 26, 2013 10 seconds-1.002805 seconds

After the system time (date) is modified, the BIOS clock must be synchronized to force the system time to be written to CMOS:

# Clock-w or # hwclock-w

 

3. implement Internet time synchronization (skip the above two steps here)
Method 1. automatic network calibration at startup:
Vi/etc/rc. d/rc. local

/Usr/sbin/ntpdate-u 192.168.0.2 192.168.0.3 192.168.0.4;/sbin/hwclock-w

The following ip addresses correspond to hosts that require the same time synchronization in the LAN.

 

Method 2. set the scheduled task
The crontab format is as follows:
SHELL =/bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin
MAILTO = root
HOME =/

# For details see man 4 crontabs

# Example of job definition:
#. ---------------- Minute (0-59)
# |. ----------- Hour (0-23)
# |. ---------- Day of month (1-31)
# |. ------- Month (1-12) OR jan, feb, mar, apr...
# |. ---- Day of week (0-6) (Sunday = 0 or 7) OR sun, mon, tue, wed, thu, fri, sat
# |

# ***** User-name command to be executed

 

You can also set crontab to schedule a task in either of the following ways:

1. write it in/etc/crontab
Code:
0 12 *** root ntpdate 210.72.145.44
Synchronize time with China National Time Service Center at every day
Of course, the premise is that
# Yum-y install ntpdate

The code is
0 12 *** root ntpdate asia.pool.ntp.org
2. run the crontab-e command.
Crontab-e
0 12 *** root ntpdate asia.pool.ntp.org; hwclock-w

 

Manual and time server calibration time:

1. first disable the ntpd service:

# Service ntpd stop

2. then calibrate with the time server:

# Ntpdate asia.pool.ntp.org

3. BIOS synchronization time:

# Hwclock-w

4. After calibration, enable ntpd service

# Service ntpd start

 

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.