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 the time zone in centos

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

How to set the time zone in centos, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Timedatectl status

This is how centos7 sets the time zone.

RHEL7.4 192.168.100.1 serves as a time server, and other hosts come to this server to synchronize time.

Time server installation and configuration:

# yum install chrony-- RHEL7 has chrony installed by default, but not ntpd.

# systemctl status chronyd-- View the status of chronyd service

# systemctl enable chronyd-Boot

# vi / etc/chrony.conf-modify the configuration file

# server 0.rhel.pool.ntp.org iburst-comment these four lines. Due to the intranet environment, time synchronization cannot be performed with the external time server.

# server 1.rhel.pool.ntp.org iburst

# server 2.rhel.pool.ntp.org iburst

# server 3.rhel.pool.ntp.org iburst

Server 192.168.100.1 iburst-add this line to synchronize time with the local machine

Local stratum 10-this line is uncommented

# Allow NTP client access from local network.

Allow 192.168.100.0 Compact 24-which servers are allowed to synchronize time to this server

# systemctl restart chronyd-restart the chronyd service after modifying the configuration file

[root@rhel1 ~] # netstat-antulp | grep chronyd

Udp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 12. 0. 0. 0. 0. 0

Udp 0 0 127.0.0.1 323 0.0.0.0 * 705/chronyd

Udp6 0 0:: 1 udp6 323: * 705/chronyd

1. Displays the current time and date of the system

Timedatectl

# timedatectl status

# the two commands have the same effect

[root@rhel1 ~] # timedatectl

Local time: Sat 2017-10-07 10:55:22 CST

Universal time: Sat 2017-10-07 02:55:22 UTC

RTC time: Sat 2017-10-07 02:55:22

Time zone: Asia/Shanghai (CST, + 0800)

NTP enabled: no

NTP synchronized: yes

RTC in local TZ: no

DST active: n/a

Note the NTP synchronized value that time synchronization services can be provided to other servers only after the time server itself has synchronized the time.

two。 Set date and time

Timedatectl set-time "YYYY-MM-DD HH:MM:SS"

Timedatectl set-time "YYYY-MM-DD"

Timedatectl set-time "HH:MM:SS"

3. View all available time zones

Timedatectl list-timezones

# Asia

Timedatectl list-timezones | grep-E "Asia/S.*"

4. Set time zone

Timedatectl set-timezone Asia/Shanghai

5. Set hardware time

# hardware time defaults to UTC

Timedatectl set-local-rtc 1

# hwclock-systohc-localtime

# the two commands have the same effect

6. Enable NTP time synchronization

Timedatectl set-ntp yes

# yes or no; 1 or 0 is also possible

Question: I don't understand the point of enabling ntp time synchronization here. Does it mean that both chronyd and ntpd services can be installed on the time server to provide time services at the same time? If set to yes, manually setting the time will result in an error. Look at the end of this article.

7. View time source information

[root@rhel1 ~] # chronyc sources

210 Number of sources = 1

MS Name/IP address Stratum Poll Reach LastRx Last sample

=

^ * rhel1.rusky.com 10 7 377 22m-3603ns [- 19us] + /-32us

[root@rhel1] # chronyc sources-v

210 Number of sources = 1

Source mode'^'= server,'='= peer,'#'= local clock.

/.-Source state'*'= current synced,'+'= combined,'-'= not combined

| /'?'= unreachable,'x' = time may be in error,'~'= time too variable.

| |.-xxxx [yyyy] + /-zzzz |

| | Reachability register (octal) -. | | xxxx = adjusted offset |

| | Log2 (Polling interval)--. | | yyyy = measured offset |

| |\ | | zzzz = estimated error.

| |\ |

MS Name/IP address Stratum Poll Reach LastRx Last sample

=

^ * rhel1.rusky.com 10 7 377 22m-3603ns [- 19us] + /-32us

[root@rhel1 ~] #

Client time synchronization configuration:

1.yum install chrony-y

two。 Modify the configuration file

[root@rhel2 ~] # vi / etc/chrony.conf

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

# server 0.rhel.pool.ntp.org iburst-- comment these four lines

# server 1.rhel.pool.ntp.org iburst

# server 2.rhel.pool.ntp.org iburst

# server 3.rhel.pool.ntp.org iburst

Server 192.168.100.1 iburst-add this line to synchronize time to this server.

3. Restart chronyd and set boot up

[root@rhel2 ~] # systemctl restart chronyd.service

[root@rhel2 ~] # systemctl enable chronyd.service

4. View time synchronization status

[root@rhel2 ~] # timedatectl

Local time: Sat 2017-10-07 11:15:43 CST

Universal time: Sat 2017-10-07 03:15:43 UTC

RTC time: Sat 2017-10-07 03:02:26

Time zone: Asia/Shanghai (CST, + 0800)

NTP enabled: no

NTP synchronized: yes-indicates that it is synchronized for yes

RTC in local TZ: no

DST active: n/a

After restarting the chronyd service, it will take several minutes for synchronization to be completed automatically.

If manual is required, use the following command:

# ntpdate 192.168.100.1 if synchronization fails, it may be that the server time is not synchronized. That is, the server NTP synchronized is no.

= =

When you manually modify the time, you must set NTP enabled to no.

[root@rhel1 ~] # date

Sun Oct 8 11:00:51 CST 2017

[root@rhel1 ~] # timedatectl

Local time: Sat 2017-10-07 11:31:45 CST

Universal time: Sat 2017-10-07 03:31:45 UTC

RTC time: Sun 2017-10-08 03:01:57

Time zone: Asia/Shanghai (CST, + 0800)

NTP enabled: no

NTP synchronized: no

RTC in local TZ: no

DST active: n/a

If you change NTP enabled to yes, it means that the automatic synchronization time is enabled. At this time, the time cannot be modified manually.

If No, the automatic synchronization time is turned off.

[root@rhel1 ~] # timedatectl set-ntp yes

[root@rhel1] # timedatectl set-time "2017-10-08 11:00:50"

Failed to set time: Automatic time synchronization is enabled

[root@rhel1 ~] # timedatectl set-ntp no

[root@rhel1] # timedatectl set-time "2017-10-08 11:00:50"

[root@rhel1 ~] # date

Sun Oct 8 11:00:51 CST 2017

This is the answer to the question about how to set the time zone in centos. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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

Internet Technology

Wechat

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

12
Report