How to set up Linux Time Zone
ls -F /usr/share/zoneinfo/
ln -sf /usr/share/zoneinfo/posix/Asia/Shanghai /etc/localtime
date
Since Linux clocks and Windows clocks are very different in terms of concept classification, usage and settings, understanding the working methods and setting operations of Linux clocks is of great significance not only to Linux beginners, but also to users who use Linux servers. is particularly important.
Classification of Linux clocks
You may be very familiar with the Windows clock. The Linux clock is conceptually similar to the Windows clock and displays the current system time, but it is very different from Windows in terms of clock classification and settings. Unlike Windows, Linux divides clocks into two types: system clock (System Clock) and hardware (Real Time Clock, RTC for short) clock. The system time refers to the clock in the current Linux Kernel, while the hardware clock is the battery-powered motherboard hardware clock on the motherboard. This clock can be set in the "Standard BIOS Feture" item of the BIOS.
Since Linux has two clock systems, which clock system does Linux use by default? Will there be a conflict between the two system clocks? These questions and concerns are not without reason. First of all, Linux does not have a default clock system. When Linux starts, the hardware clock will read the system clock settings, and then the system clock will operate independently of the hardware.
Judging from the Linux startup process, the system clock and hardware clock will not conflict, but all commands (including functions) in Linux use the system clock setting. Not only that, the system clock and hardware clock can also be asynchronous, as shown in Figure 1, that is, the system time and hardware time can be different. The benefits of doing this are of little significance to ordinary users, but they are of great use to Linux network administrators. For example, if you want to synchronize servers in a large network (across several time zones), for example, a Linux server in New York and a Linux server in Beijing, one of the servers does not need to change the hardware clock but only needs to temporarily set a system time, such as To set the time on the Beijing server to New York time, after the two servers have completed file synchronization, synchronize it with the original clock. This provides more flexible operation of system and hardware clocks.
Setting the Linux clock
In Linux, the commands used to view and set the clock mainly include date, hwclock and clock. Among them, clock and hwclock are similar in usage, except that the clock command not only supports x86 hardware system, but also supports Alpha hardware system. Since most users currently use the x86 hardware system, these two commands can be learned as one command.
1. Use the date command in the virtual terminal to view and set the system time
To view the system clock:
# date
To set the system clock:
# date 091713272003.30
Common setting format:
# date month day hour minute year. second
2. Use the hwclock or clock command to view and set the hardware clock
View the operation of the hardware clock:
# hwclock --show or
# clock --show
Wednesday, September 17, 2003 13:24:11 -0.482735 seconds
To set the hardware clock:
# hwclock --set --date="09/17/2003 13:26:00"
or
# clock --set --date="09/17/2003 13:26:00"
Common setting format: hwclock/clock --set --date="month/day/year hour:minute:second".
3. Synchronize system clock and hardware clock
The Linux system (the author is using Red Hat 8.0 and has not done experiments on other systems) will synchronize the hardware clock and the system clock by default after restarting. If it is not convenient to restart (servers usually rarely restart), use the clock or hwclock command to synchronize the system clock and hardware clock.
The hardware clock is synchronized with the system clock:
# hwclock --hctosys
or
# clock --hctosys
In the above command, --hctosys means Hardware Clock to SYStem clock.
System clock and hardware clock synchronization:
# hwclock --systohc
or
# clock --systohc
Set the time using the graphical system setup tool
For beginners, the author recommends using a graphical clock setting tool, such as the date and time setting tool in Red Hat 8.0. You can click the "redhat-config-time" command in the virtual terminal, or select "K Menu/System Settings" /Date & Time" to start the date and time setting tool. You don't have to consider the system time and hardware time when using this tool. You only need to set the date and time from this dialog box. You can set and modify the system clock and hardware clock at the same time.
Internet sync clock settings
There is a function to synchronize with the Internet in the Windows XP date and time settings. With this function, you can get very accurate time as long as you go online. Red Hat 8.0 also provides such a function. In the lower part of the date and time setting tool dialog box, there is an option to "Enable Network Time Protocol". Select this option to use the Network Time Protocol to synchronize the Linux system clock. After selecting this item, the server drop-down list box below it becomes available, from which you can select a time server as the remote time server. Then click the OK button to connect to the set time server and synchronize the time with it.