CentOS7 change time zone and time synchronization

What is NTP?

  NTP is the Network Time Protocol, a protocol used to synchronize the time of network devices (such as computers and mobile phones).

      Alibaba Cloud's NTP server:
  • ntp1.aliyun.com
  • ntp2.aliyun.com
  • ntp3.aliyun.com
  • ntp4.aliyun.com

First, the timedatectl command to view the current time zone:

[root@localhost Asia]#  timedatectl 
      Local time: Tue 2018-04-24 07:29:13 CST
  Universal time: Mon 2018-04-23 23:29:13 UTC
        RTC time: Mon 2018-04-23 23:29:13
       Time zone: America/New_York (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

[root@localhost Asia]# 

2. Detailed explanation of timedatectl command

[root@localhost Asia]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ...
Query or change system time and date settings.
  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode
Commands: status                   Show current time settings  set-time TIME            Set system time  set-timezone ZONE        Set system time zone
 


  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Control whether NTP is enabled

3. View all timezones timedatectl list-timezones

[root@localhost Asia]# timedatectl list-timezones|grep Shanghai
Asia/Shanghai
[root@localhost Asia]# 

4. Change to Shanghai timezone timedatectl set-timezone Asia/Shanghai

[root@localhost Asia]# timedatectl set-timezone Asia/Shanghai
[root@localhost Asia]# timedatectl status
      Local time: Tue 2018-04-24 07:36:56 CST
      Universal time: Mon 2018-04-23 23:36:56 UTC
       RTC time: Mon 2018-04-23 23:36:56
       Time zone:
Asia/Shanghai (CST, +0800)
     NTP enabled: yes
     NTP synchronized: yes
     RTC in local TZ: no
      DST active: n/a
[root@localhost Asia]# 


5. Synchronize time server

 Install: #yum -y install ntpdate

# systemctl enable ntpd

#systemctl start ntpd

#ntpdate ntp1.aliyun.com


Set NTP to enable timedatectl set-ntp yes

set NTP off timedatectl set-ntp no

The timedatectl command can also set the time and date

set date format timedatectl set-time YYYY-MM-DD

Set time format timedatectl set-time HH:MM:SS


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325447488&siteId=291194637