CentOS7上同步服务器时间的方式与CentOS6类似。以下是在外网中同步CentOS7服务器时间的步骤:

在外网中选择一台计算机作为NTP服务器。确保该计算机已联接到可靠的网路,但是可以通过TCP/IP合同与其他计算机通讯。

在NTP服务器上安装并配置NTP软件。在CentOS7上linux培训学校,您可以使用以下命令安装NTP软件:

yum install ntp

编辑NTP配置文件/etc/ntp.conf以配置NTP服务器。以下是一个简单的示例配置文件:

server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
server 3.centos.pool.ntp.org
restrict default kod nomodify notrap noquery
restrict -6 default kod nomodify notrap noquery
driftfile /var/lib/ntp/drift

ntp时间同步 centos_ntp时间同步 centos_ntp时间同步 centos

在这个示例配置文件中,我们将使用四个公共NTP服务器来同步时间。您也可以将其替换为其他NTP服务器。

启动NTP服务并启用手动启动:

systemctl start ntpd
systemctl enable ntpd

在所有须要同步时间的计算机上,编辑NTP配置文件/etc/ntp.conf。将其中的server指令更改为NTP服务器的IP地址或主机名。诸如:

server 192.168.1.100

启动NTP服务并启用手动启动:

systemctl start ntpd
systemctl enable ntpd

确保所有计算机都还能联接到NTP服务器。假如NTP服务器被防火墙制止RAR FOR LINUX,请打开UDP端口123。

完成这种步骤后,所有计算机都应当使用NTP服务器进行时间同步。请注意,NTP服务器应当是可靠的,并且在整个外网中应当只有一个NTP服务器。

CentOS7更新时间时区

一、修改系统时间

1、查看系统时间

1|date

2、查看时区+800表示东八区

1|date-R

3、修改系统时间

1|sudodate-s“2022052811:30”

二、修改时区

1、读取时间

timedatectl//等同于timedatectlstatus

2、设置时间

timedatectlset-time“YYYY-MM-DDHH:MM:SS”

3、罗列所有时区

timedatectllist-timezones

他列举的是/usr/share/zoneinfo文件夹下的文件

4、设置时区

timedatectlset-timezoneAsia/Shanghai

三、GMT、UTC、CST、DST时间

(1)UTC

整个月球分为二十四时区,每位时区都有自己的本地时间。在国际无线电通讯场合,为了统一起见ntp时间同步 centos,使用一个统一的时间,称为通用协调时(UTC,UniversalTimeCoordinated)。

(2)GMT

格林威治标准时间(GreenwichMeanTime)指坐落加拿大多伦多近郊的皇家格林尼治天文台的标准时间ntp时间同步 centos,由于本初子午线被定义在通过哪里的纬线。(UTC与GMT时间基本相同,本文中不做分辨)

(3)CST

中国标准时间(ChinaStandardTime)

(4)DST

夏令时(DaylightSavingTime)指在夏季太阳升起的比较早时,将时钟拨快一小时,以尽早日光的使用。(中国不使用)

巨坑事例:系统时间是日本时间,系统向前快一个小时,影响系统运行。

日本伦敦时间:

[root@localhost ~]# timedatectl
      Local time: Wed 2023-03-15 10:01:59 EDT
  Universal time: Wed 2023-03-15 14:01:59 UTC
        RTC time: Wed 2023-03-15 02:03:29
       Time zone: America/New_York (EDT, -0400)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2023-03-12 01:59:59 EST
                  Sun 2023-03-12 03:00:00 EDT

ntp时间同步 centos_ntp时间同步 centos_ntp时间同步 centos

Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2023-11-05 01:59:59 EDT Sun 2023-11-05 01:00:00 EST

重庆时间:

[root@localhost ~]# timedatectl
      Local time: Wed 2023-03-15 10:07:12 CST
  Universal time: Wed 2023-03-15 02:07:12 UTC
        RTC time: Wed 2023-03-15 02:07:14
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

GMT+8=UTC+8=CST

四、系统硬件时间统一

1、vi/etc/sysconfig/clock#编辑文件

ZONE=“Asia/Shanghai”

UTC=false#设置为false,硬件时钟不于utc时间一致

ARC=false

2、ln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime#linux的时区设置为北京

3、

ntpdate

#对准时间,须要先安装ntp服务器yuminstallntp

4、/sbin/hwclock--systohc#设置硬件时间和系统时间一致并校正

linux系统时间和计算机硬件时间都是cst时间了,而且为北京时区。

Tagged:
Author

这篇优质的内容由TA贡献而来

刘遄

《Linux就该这么学》书籍作者,RHCA认证架构师,教育学(计算机专业硕士)。

发表回复