Modifying the Linux system time zone and Time method

Source: Internet
Author: User
Tags set time time and date


One, modify the time zone

1. View the current time zone

Date-r

2. Modify Settings Time zone

Select target time zone with Tzselect

Tzselect

According to the prompts to select the appropriate time zone, and finally get the time zone settings, such as: tz= ' Asia/shanghai '; Export TZ
The Asia/shanghai here is the time zone setting that we want to use.

3. Copy the appropriate time zone file, replace the CentOS system time zone file, or create a linked file

cp/usr/share/zoneinfo/$ Primary time zone/$ secondary time zone/etc/localtime

In China you can use:

Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime


4. Modify the contents of the/etc/sysconfig/clock

Shellzone= "Asia/shanghai"
Utc=true
Arc=false


In this case, if you do not add utc=true, the system does not start the time zone in this configuration will be applied to the system time zone, vice versa will check the settings in this configuration at system startup, apply the time zone setting in ZONE to the system time zone, and the system time zone will change.

Second, the modified time

1. View time and date

Date

2. Set time and date

Set the CentOS system date to the June 10, 1996 command

Date-s 06/22/96

Set CentOS system time to 1:52 P.M. 0 seconds command

Date-s 13:52:00

3. Write the current time and date into the BIOS to avoid failure after reboot

Hwclock-w

Third, enable NTP synchronization time

Yum Install Ntpdate
Ntpdate cn.pool.ntp.org

Chkconfig--level 3 ntpd on

Linux load time zone and time:

When Linux starts, one of the scripts (/etc/rc.d/rc.sysinit) runs the/sbin/hwclock program and copies the current hardware clock to the system time. The script file reads the time zone profile/etc/sysconfig/clock, so we don't need to modify the script, just modify the configuration file directly, and set the UTC line to true or false as needed.

Iv. Modifying the system time zone:

1, Tzselect can modify/etc/sysconfig/clock This configuration file, according to the instructions of the command to modify the good.


However, in practice, it is found that this approach is not able to make the time settings on the server immediately effective, and the use of ntpdate to synchronize the time server can not change the time. Even if you use the date command to manually set the time, if you use Ntpdate to do time synchronization, time will be changed to the original error time zone. And the production of machines are often very important, can not be restarted and other operations.

2, if you want to modify the time zone and immediately effective, you can copy the appropriate time zone files, replace the system default time zone:

# cp/usr/share/zoneinfo/$ main time zone/$ time zone/etc/localtime

For the Chinese server, execute:

# Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime

In fact, adding a soft connection can also be, but is usually copied. Soft connection methods are as follows:

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


The current time is then written to the BIOS for permanent effect (avoid failure after reboot)

# Hwclock

V. Modification of system time

Date-s
For example, set the system time to the June 10, 1996 command as follows.
#date-S 06/10/96
The command to set the system time to 1:12 P.M. 0 seconds is as follows.
#date-S 13:12:00


#clock-W
This command forces the system time to be written to the CMOS

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.