Linux系统(CentOS 7)时间同步

一、Linux时间设置

Linux有两个时间:软件时间、硬件时间

1、软件时间

        查看时间

[root@master-Elastic ~]# date
2024年 02月 19日 星期一 15:19:06 CST

        修改时区(将软件时区修改为上海时区)

[root@master-Elastic ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5


注:选择 5 亚洲
Please select a country.
 1) Afghanistan           18) Israel                35) Palestine
 2) Armenia               19) Japan                 36) Philippines
 3) Azerbaijan            20) Jordan                37) Qatar
 4) Bahrain               21) Kazakhstan            38) Russia
 5) Bangladesh            22) Korea (North)         39) Saudi Arabia
 6) Bhutan                23) Korea (South)         40) Singapore
 7) Brunei                24) Kuwait                41) Sri Lanka
 8) Cambodia              25) Kyrgyzstan            42) Syria
 9) China                 26) Laos                  43) Taiwan
10) Cyprus                27) Lebanon               44) Tajikistan
11) East Timor            28) Macau                 45) Thailand
12) Georgia               29) Malaysia              46) Turkmenistan
13) Hong Kong             30) Mongolia              47) United Arab Emirates
14) India                 31) Myanmar (Burma)       48) Uzbekistan
15) Indonesia             32) Nepal                 49) Vietnam
16) Iran                  33) Oman                  50) Yemen
17) Iraq                  34) Pakistan
#? 9

注:选择 9 中国
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1


注:选择 1 北京
The following information has been given:

        China
        Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Local time is now:      Mon Feb 19 15:24:53 CST 2024.
Universal Time is now:  Mon Feb 19 07:24:53 UTC 2024.
Is the above information OK?
1) Yes
2) No
#? 1

注:选择 1 Yes

        删除文件

rm -rf /etc/localtime

        创建软连接

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

        安装ntpdate

yum install -y ntpdate

NTPdate简介

NTPdate是一种在Linux和类Unix系统中同步网络时间协议(NTP)服务器时间的命令行程序。它可以让你的系统时钟与互联网上的标准时间服务器保持一致,从而确保系统时间的准确性。

        时间同步

ntpdate us.pool.ntp.org

        查看时间

[root@master-Elastic ~]# date
2024年 02月 19日 星期一 15:19:06 CST

2、硬件时间

软件时间和硬件时间可能会不同步

        查看硬件时间

[root@master-Elastic ~]# hwclock
2024年02月19日 星期一 15时34分46秒  -0.047622 秒

将软件时间写入到硬件时间

sudo hwclock -w

3、防止重启后时间重置

需要用命令将正确的时间写入BIOS,否则下次重启还是会还原

clock -w 写入BIOS

有些系统是hwclock --systohc

hwclock -r显示bios时间
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值