Linux操作系统时间老是不准,怎么设置?
一、使用 NTP 服务时间同步安装 ntp# yum -y install ntp启动 ntp 服务
# systemctl startntpd# systemctl enablentpdCreated symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.查看 ntp 服务
# systemctl status ntpd● ntpd.service - Network Time Service Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2022-08-04 08:00:47 CST; 7h left Main PID: 20746 (ntpd) Tasks: 1 Memory: 768.0K CGroup: /system.slice/ntpd.service └─20746 /usr/sbin/ntpd -u ntp:ntp -gAug 04 08:00:47 node ntpd: Listen normally on 6 lo ::1 UDP 123Aug 04 08:00:47 node ntpd: Listen normally on 7 ens33 fe80::8a83:7297:7cb8:9934 UDP 123Aug 04 08:00:47 node ntpd: Listening on routing socket on fd #24 for interface updatesAug 04 08:00:47 node systemd: Started Network Time Service.Aug 04 08:00:47 node ntpd: 0.0.0.0 c016 06 restartAug 04 08:00:47 node ntpd: 0.0.0.0 c012 02 freq_set kernel 0.000 PPMAug 04 08:00:47 node ntpd: 0.0.0.0 c011 01 freq_not_setAug 04 08:00:56 node ntpd: 0.0.0.0 c61c 0c clock_step -28798.353463 sAug 04 00:00:57 node ntpd: 0.0.0.0 c614 04 freq_modeAug 04 00:00:58 node ntpd: 0.0.0.0 c618 08 no_sys_peer修改 ntp.conf 文件
# vim /etc/ntp.conf# grep server /etc/ntp.conf # Use public servers from the pool.ntp.org project.#server 0.centos.pool.ntp.org iburstserver ntp.aliyun.com iburst#broadcast 192.168.1.255 autokey # broadcast server#broadcast 224.0.1.1 autokey# multicast server#manycastserver 239.255.254.254# manycast server重启服务
# systemctl restart ntpd检查同步状态
# ntpq -p remote refid st t when poll reach delay offsetjitter============================================================================== 203.107.6.88 100.107.25.114 2 u 2 64 1 30.975149.499 0.393二、使用 ntpdate 同步使用 ntpd 命令同步
# ntpdate ntp.aliyun.com 4 Aug 00:07:17 ntpdate: adjust time server 203.107.6.88 offset -0.001543 sec查看时间
# dateThu Aug4 00:07:46 CST 2022三、处理 ntpdate 同步失败报错处理方法报错信息
cna02:~ # ntpdate ntp1.aliyun.com 4 Aug 07:23:41 ntpdate: the NTP socket is in use, exiting处理方法
cna02:~ # service ntpd stopRedirecting to /bin/systemctl stop ntpd.service重新同步
cna02:~ # ntpdate ntp1.aliyun.com 3 Aug 23:22:36 ntpdate: step time server 120.25.115.20 offset -28911.609110 sec查看时间是否正确
cna02:~ # dateWed Aug3 23:22:41 CST 2022四、使用 chrony 服务时间同步安装 chrony
# yum -y install chronyLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.bfsu.edu.cn * extras: mirrors.bfsu.edu.cn * updates: mirrors.bfsu.edu.cnResolving Dependencies--> Running transaction check---> Package chrony.x86_64 0:3.2-2.el7 will be updated---> Package chrony.x86_64 0:3.4-1.el7 will be an update--> Finished Dependency ResolutionDependencies Resolved=============================================================================================================================================================================== Package Arch Version Repository Size===============================================================================================================================================================================Updating: chrony x86_64 3.4-1.el7 base 251 kTransaction Summary===============================================================================================================================================================================Upgrade1 PackageTotal download size: 251 kDownloading packages:No Presto metadata available for basechrony-3.4-1.el7.x86_64.rpm | 251 kB00:00:00 Running transaction checkRunning transaction testTransaction test succeededRunning transactionUpdating : chrony-3.4-1.el7.x86_64 1/2 Cleanup : chrony-3.2-2.el7.x86_64 2/2 Verifying: chrony-3.4-1.el7.x86_64 1/2 Verifying: chrony-3.2-2.el7.x86_64 2/2 Updated:chrony.x86_64 0:3.4-1.el7 Complete!
页:
[1]