Linux modifies the system time zone

Source: Internet
Author: User
Tags local time

This is the problem I encountered in the cluster Web system (4 Web servers in different times, resulting in uneven distribution of the system), here I also make the intranet Ntpdate time synchronization server, The old difference is 8 hours in sync.


This is because UTC is used to install the system, so what is UTC, that is, UTC is the time of the 0 time zone, the international standard, and China is in the utc+8 time zone.


Another time is local time, and Windows uses local time. Therefore, when installing a Linux system, do not choose to use UTC.

Modify the system time.

There are two Linux system clocks, one is the hardware clock, that is, the BIOS time, which is the time we see in CMOS setup, and the other is the system clock, which is the kernel time of the Linux system. When Linux starts, the system kernel reads the hardware clock settings, and the system clock is independent of the hardware. Sometimes we find that the system clock is inconsistent with the hardware clock, so we need to perform time synchronization and share the command usage of time settings and clock synchronization.

Command chapter:

Display system time Date

The date command sets the dates to June 18, 2014 Date-s 06/18/14

Set the time to 14 points, 29 minutes, 50 seconds date-s 14:20:50

Set the time to June 18, 2014 14:16 30 seconds (MMDDHHMMYYYY.SS) date0618141614.30

1.hwclock/clock command to view, set hardware time

Viewing the system hardware clock

Hwclock--show or

Clock--show

Set Hardware time

Hwclock--set--date= "06/18/14 14:55" (Month/day/year: minutes: seconds) or # clock--set--date= "06/18/14 14:55" (Month/day/year: minutes: seconds)

Synchronous system and hardware clock.

You can see that the hardware and system clocks differ by half an hour. can be synchronized using hwclock or clock,

The hardware clock is synchronized with the system clock:

# Hwclock--hctosys or # Clock--hctosys HC represents the hardware time, SYS represents the system time, i.e. the system clock is synchronized with the hardware clock

system clock and Hardware clock synchronization:

# Hwclock--SYSTOHC or # CLOCK--SYSTOHC synchronize hardware clock with system clock


Setup Method 2:


Time zone settings:

To start setting the time zone, refer to the information on the Internet, using the Tzselect command, and found that the Tzselect command only tells the way to set the time zone, not really to modify/etc/sysconfig/clock this file. In other words, the tzselect command simply tells us to select the time zone by setting the TZ environment variable, and then add the variable to the. profile file. Here's a quick introduction to how to set the time zone using the Tzselect command, and how to set the time zone by modifying the/etc/sysconfig/clock configuration file.

1. 2

Tzselect:

Execute the tzselect command--Select asia--> Select china--> Select East China-beijing, Guangdong, Shanghai, etc--> and enter 1. Process such as:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/E1/wKiom1T-ySWAsWMMAAKhR6zlMAg596.jpg "title=" 1.png " alt= "Wkiom1t-yswaswmmaakhr6zlmag596.jpg"/>

Option 5 9 1

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5A/E1/wKiom1T-ydPDh_2cAARGKETQoIo322.jpg "title=" 2.png " alt= "Wkiom1t-ydpdh_2caargketqoio322.jpg"/>

After executing the tzselect command to select the time zone, the time zone does not change, but the command finally prompts you to execute tz= ' Asia/shanghai '; Export TZ and add this line of command to the. Profile, then exit and log back in. Refer to the results as seen in the Date command, and the final time zone is shown as CST, China Standard Time.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5A/DC/wKioL1T-y2yR8bl5AABXQSMIy50294.jpg "title=" 3.png " alt= "Wkiol1t-y2yr8bl5aabxqsmiy50294.jpg"/>


Modify the configuration file to modify the time zone

1, modify/etc/sysconfig/clock Zone=asia/shanghai

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5A/E1/wKiom1T-y0mQWfn2AACphI5tJ7w482.jpg "title=" 4.png " alt= "Wkiom1t-y0mqwfn2aacphi5tj7w482.jpg"/>

2, Rm/etc/localtime

3. Link to Shanghai time zone file

Ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime

After performing the above procedure, restart the machine to see that the time zone has changed.




Linux modifies the system time zone

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.