Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set time in CentOS system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to set time in CentOS system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Install ntp

The code is as follows:

# yum install ntp

2. Execute the command:

The code is as follows:

# ntpdate us.pool.ntp.org .

The time zone of rhas5 exists as a file, and the current time zone file is in / etc/localtime

Files for other time zones are stored under / usr/share/zoneinfo

3. We use the time of Dongba District (+ 0800), Beijing and Shanghai.

So copy # cp-f / usr/share/zoneinfo/Asia/Shanghai to / etc/localtime

The code is as follows:

# cp-f / usr/share/zoneinfo/Asia/Shanghai / etc/localtime

# reboot

After restart, date checks the time, current time zone date-R, Linux time zone and time

I. time zone

1. View current time zone

The code is as follows:

Date-R

two。 Modify the setting time zone

Methods (1)

The code is as follows:

Tzselect

Method (2) is limited to RedHat Linux and CentOS systems.

The code is as follows:

Timeconfig

Method (3) is suitable for Debian.

The code is as follows:

Dpkg-reconfigure tzdata

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

The code is as follows:

Cp / usr/share/zoneinfo/$ Primary time Zone / $Sub time Zone / etc/localtime

It can be used in China:

The code is as follows:

Cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime

Second, time

1. Check the time and date

The code is as follows:

Date

2. Set time and date

Order to set the CentOS system date to November 30th, 2011

The code is as follows:

Date-s 11-30-11

Command to set the CentOS system time to 09:13:00

The code is as follows:

Date-s 09:13:00

3. Write the current time and date to BIOS to avoid invalidation after restart

The code is as follows:

Hwclock-w

Timing synchronization time

Synchronize the system time with the hardware clock, with:

The code is as follows:

Wclock-hctosys

# or

Clock-hctosys

Instead, synchronize the hardware clock with the system time:

The code is as follows:

Hwclock-systohc

# or

Clock-systohc

Let the system time synchronize the hardware time every ten minutes.

The code is as follows:

[hqw@localhost root] $vi / etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

# run-parts

01 * root run-parts / etc/cron.hourly

02 4 * root run-parts / etc/cron.daily

22 4 * 0 root run-parts / etc/cron.weekly

42 4 1 * * root run-parts / etc/cron.monthly

* / 10 * root hwclock-- hctosys # join this line and execute hwclock-- hctosys every 10 minutes

This is the end of the content of "how to set the time in the CentOS system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report