Home Operation and Maintenance CentOS What should I do if the time is wrong after centos restarts?

What should I do if the time is wrong after centos restarts?

Jan 28, 2022 am 11:23 AM
centos

Solution to the incorrect time after centos restart: 1. Execute "ln -sf /usr/share/zoneinfor/Asia/Shanghai /etc/localtime" to change the time zone; 2. Just restart.

What should I do if the time is wrong after centos restarts?

The operating environment of this article: centOS6.3 system, DELL G3 computer

What should I do if the time is wrong after centos restarts?

Solve the problem that the modified time of the Linux centos version is invalid after restarting

After installing centos, I found that the time did not match the local time, so I searched online There are many methods, but none of them work. After restarting, it returns to the original time. Very puzzled.

Finally, I added this command with the mentality of giving it a try: ln -sf /usr/share/zoneinfor/Asia/Shanghai /etc/localtime After restarting, it was modified and I felt relieved. tone.

The detailed instructions are listed below, I hope it will be helpful to you.

Linux time is divided into two types, hardware time and system time:

1: Display system time: #date
Modify system time: date -s '2012-08-02 12:00' #Set the system time to local time

2: Display hardware time: #hwclock --show
Set hardware time: #hwclock --set -- date '08/02/2012 12:00:00'

3: This is the hardware time synchronization system time: hwclock --hctosys

4: This command forces the system time to be written to CMOS :clock -w

If you only need the above 4 steps, and the modifications will take effect after restarting, then congratulations, you don’t need to look at the next step. If it still doesn’t take effect, then you must use it. This is the critical step 5.

5: ln -sf /usr/share/zoneinfor/Asia/Shanghai /etc/localtime #Change time zone

In Linux, there are two types of clocks: hardware clock and system clock. The hardware clock refers to the clock device on the motherboard, which is the clock that can usually be set in the BIOS screen. The system clock refers to the clock in the kernel. All Linux related commands and functions read the system clock settings. Because there are two different clocks, there will be differences between them. When Linux starts, the system clock will read the hardware clock settings, and then the system clock will operate independently.

After using the date command to set the system time, the hardware clock will not be modified. Therefore, after the system is restarted, the system time will still read the hardware time. This is why the date setting fails.

Therefore, after setting the system time, you need to synchronize the system time to the hardware clock.

clock/hwclock:

Display and set the hardware clock (query and set the hardware clock (RTC)), the two commands are the same. RTC=Real Time Clock, which is the hardware clock.

Command parameters:

-r, --show        读取并打印硬件时钟(read hardware clock and print result)
-s, --hctosys     将硬件时钟同步到系统时钟(set the system time from the hardware clock)
-w, --systohc     将系统时钟同步到硬件时钟(set the hardware clock to the current system time)
Copy after login

Command example:

1. View the hardware clock

2014年03月27日 星期四 11时03分50秒  -0.328520 seconds
[root@localhost ~]# hwclock -r
2014年03月27日 星期四 11时03分53秒  -0.797264 seconds
[root@localhost ~]# hwclock --show
2014年03月27日 星期四 11时04分01秒  -0.672267 seconds
Copy after login

2. clock is the same as hwclock

[root@localhost ~]# type -a hwclock
hwclock is /sbin/hwclock
hwclock is /usr/sbin/hwclock
[root@localhost ~]# ll /sbin/hwclock /usr/sbin/hwclock 
-rwxr-xr-x. 1 root root 46940 11月 22 23:27 /sbin/hwclock
lrwxrwxrwx. 1 root root    18 3月  26 19:27 /usr/sbin/hwclock -> ../../sbin/hwclock
[root@localhost ~]# type -a clock
clock is /sbin/clock
[root@localhost ~]# ll /sbin/clock 
lrwxrwxrwx. 1 root root 7 3月  26 19:27 /sbin/clock -> hwclock
Copy after login

3. Synchronize the system time to the hardware clock

[root@localhost ~]# hwclock
2014年03月27日 星期四 18时50分51秒  -0.312960 seconds
[root@localhost ~]# date
2014年 03月 27日 星期四 10:50:55 CST
[root@localhost ~]# hwclock -w
[root@localhost ~]# hwclock
2014年03月27日 星期四 10时51分15秒  -0.875387 seconds
Copy after login

Synchronize the network time to the system time

[root@localhost ~]# ntpdate 210.72.145.44
27 Mar 11:11:24 ntpdate[4766]: adjust time server 210.72.145.44 offset 0.011401 sec
Copy after login

210.72.145.44 (the official time synchronization server IP domain name of Xi’an Timing Service Center in China)

After synchronizing the network time to the system time, you can use hwclock -w to synchronize the system time to the hardware time.

Modify time zone

Some systems may still fail after restarting after performing the above two steps, so the time zone needs to be modified.

[root@localhost ~]# tzselect #按照提示进行选择时区
[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Copy after login

Modify the system time configuration file

[root@localhost ~]# /etc/sysconfig/clock

#打开clock文件,将相关内容改成以下内容
UTC=false 
ARC=false
ZONE="Asia/Shanghai"
Copy after login

Restart the system

[root@localhost ~]# reboot
Copy after login

I am using centOS6.3. When restarting the virtual machine, the error message is displayed as follows

/dev/mapper/root: Superblock last mount time (Mon Mar  5 17:40:11 2012,  
         now = Sat Mar  5 18:46:53 2011) is in the future.  
/dev/mapper/root: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.  
         (i.e., without -a or -p options)  
                                                                                                 [FAILED]  
*** An error occurred during the file system check.  
*** Dropping you to a shell; the system will reboot  
*** when you leave the shell.  
Given root password for maintenance  
(or type Control-D to continue):
Copy after login

Later I found a solution:

Enter the password directly at "(or type Control-D to continue):", enter the repair mode, and run the repair in the form of fsck , For yours, just run fsck /dev/mapper/root, and then reboot. After restarting, you may be prompted with the same error on other disks. Run it again in the form of fsck , then reboot, and test it on the virtual machine to start.

Recommended: "centos usage tutorial"

The above is the detailed content of What should I do if the time is wrong after centos restarts?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the backup methods for GitLab on CentOS What are the backup methods for GitLab on CentOS Apr 14, 2025 pm 05:33 PM

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

How to check CentOS HDFS configuration How to check CentOS HDFS configuration Apr 14, 2025 pm 07:21 PM

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

What are the common misunderstandings in CentOS HDFS configuration? What are the common misunderstandings in CentOS HDFS configuration? Apr 14, 2025 pm 07:12 PM

Common problems and solutions for Hadoop Distributed File System (HDFS) configuration under CentOS When building a HadoopHDFS cluster on CentOS, some common misconfigurations may lead to performance degradation, data loss and even the cluster cannot start. This article summarizes these common problems and their solutions to help you avoid these pitfalls and ensure the stability and efficient operation of your HDFS cluster. Rack-aware configuration error: Problem: Rack-aware information is not configured correctly, resulting in uneven distribution of data block replicas and increasing network load. Solution: Double check the rack-aware configuration in the hdfs-site.xml file and use hdfsdfsadmin-printTopo

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

See all articles