日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux系统之时间管理

發布時間:2025/4/16 linux 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux系统之时间管理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Linux系統之時間管理

  • 一、date命令介紹
    • 1.date幫助
    • 2.查詢系統時間
      • ①查詢電腦硬件時間
      • ②查詢UTC時間
      • ③查詢系統時間
      • ④特定時間格式輸出系統時間
      • ⑤查詢電腦所有時間信息
  • 三、修改系統時間
    • 1.使用-s選項修改
    • 2.直接修改
    • 3.硬件時間向系統時間同步
    • 4.系統時間向硬件時間同步
  • 四、修改時區
  • 四、在shell腳本應用
  • 五、ntp服務器
    • 1.檢查chrony服務
    • 2.開啟chrony服務
    • 3.編輯chrony.conf配置文件
    • 4.重啟服務并查看同步狀態
    • 5.立即同步ntp服務器

一、date命令介紹

1.date幫助

[root@tianyi ~]# date Mon Sep 6 20:56:57 CST 2021 [root@tianyi ~]# date --help Usage: date [OPTION]... [+FORMAT]or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] Display the current time in the given FORMAT, or set the system date. 時間方面:% : 印出 % %n : 下一行 %t : 跳格 %H : 小時(00..23) %I : 小時(01..12) %k : 小時(0..23) %l : 小時(1..12) %M : 分鐘(00..59) %p : 顯示本地 AM 或 PM %r : 直接顯示時間 (12 小時制,格式為 hh:mm:ss [AP]M) %s :197011 日 00:00:00 UTC 到目前為止的秒數 %S :(00..61) %T : 直接顯示時間 (24 小時制) %X : 相當于 %H:%M:%S %Z : 顯示時區 日期方面:%a : 星期幾 (Sun..Sat) %A : 星期幾 (Sunday..Saturday) %b : 月份 (Jan..Dec) %B : 月份 (January..December) %c : 直接顯示日期與時間 %d :(01..31) %D : 直接顯示日期 (mm/dd/yy) %h : 同 %b %j : 一年中的第幾天 (001..366) %m : 月份 (01..12) %U : 一年中的第幾周 (00..53) (以 Sunday 為一周的第一天的情形) %w : 一周中的第幾天 (0..6) %W : 一年中的第幾周 (00..53) (以 Monday 為一周的第一天的情形) %x : 直接顯示日期 (mm/dd/yy) %y : 年份的最后兩位數字 (00.99) %Y : 完整年份 (0000..9999)

2.查詢系統時間

①查詢電腦硬件時間

[root@tianyi backups]# hwclock 2011-08-12 02:47:24.886129+08:00 [root@tianyi backups]#

②查詢UTC時間

UTC:世界統一時間

[root@tianyi backups]# timedatectl Local time: Fri 2011-08-12 02:15:40 CSTUniversal time: Thu 2011-08-11 18:15:40 UTCRTC time: Mon 2021-09-06 14:06:56Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: noNTP service: activeRTC in local TZ: no

③查詢系統時間

[root@tianyi ~]# date Mon Sep 6 21:08:49 CST 2021

④特定時間格式輸出系統時間

[root@tianyi ~]# date "+%Y-%m-%d %H:%M:%S" 2021-09-06 21:20:03 [root@tianyi ~]#

⑤查詢電腦所有時間信息

[root@tianyi backups]# timedatectl Local time: Fri 2011-08-12 03:04:41 CSTUniversal time: Thu 2011-08-11 19:04:41 UTCRTC time: Thu 2011-08-11 19:04:11Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: noNTP service: activeRTC in local TZ: no [root@tianyi backups]#

三、修改系統時間

1.使用-s選項修改

[root@tianyi ~]# date -s "2021-09-06 21:24:00" Mon Sep 6 21:24:00 CST 2021 [root@tianyi ~]#

2.直接修改

數字為月日時分年.秒

[root@tianyi ~]# date 090621282021.28 Mon Sep 6 21:28:28 CST 2021 [root@tianyi ~]# date "+%Y-%m-%d %H:%M:%S" 2021-09-06 21:28:30

3.硬件時間向系統時間同步

[root@tianyi backups]# hwclock -w [root@tianyi backups]#

4.系統時間向硬件時間同步

[root@tianyi backups]# hwclock -s [root@tianyi backups]#

四、修改時區

[root@tianyi backups]# timedatectl list-timezones |grep Shanghai Asia/Shanghai [root@tianyi backups]# timedatectl set-timezone Display all 426 possibilities? (y or n)^C [root@tianyi backups]# timedatectl set-timezone Asia/Shanghai [root@tianyi backups]#

四、在shell腳本應用

[root@tianyi tmp]# cp -r /etc /backups/etc_$(date +%Y%m%d%H%M%S) [root@tianyi tmp]# cd /backups/ [root@tianyi backups]# ls etc_20210906214116 [root@tianyi backups]#

五、ntp服務器

1.檢查chrony服務

[root@tianyi backups]# systemctl status chronyd ● chronyd.service - NTP client/serverLoaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)Active: inactive (dead)Docs: man:chronyd(8)man:chrony.conf(5) [root@tianyi backups]#

2.開啟chrony服務

[root@tianyi backups]# systemctl enable --now chronyd Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service. [root@tianyi backups]# systemctl status chronyd ● chronyd.service - NTP client/serverLoaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2021-09-06 21:54:47 CST; 1s agoDocs: man:chronyd(8)man:chrony.conf(5)

3.編輯chrony.conf配置文件

[root@tianyi backups]# vim /etc/chrony.conf [root@tianyi backups]# # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). pool ntp.aliyun.com iburst

4.重啟服務并查看同步狀態

[root@tianyi backups]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 203.107.6.88 2 6 37 60 +311us[-1713us] +/- 29ms [root@tianyi backups]#

5.立即同步ntp服務器

[root@tianyi backups]# 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 =============================================================================== ^* 203.107.6.88 2 6 17 3 +305us[ +387us] +/- 28ms [root@tianyi backups]# timedatectl Local time: Mon 2021-09-06 23:24:22 CSTUniversal time: Mon 2021-09-06 15:24:22 UTCRTC time: Thu 2011-08-11 19:36:12Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: yesNTP service: activeRTC in local TZ: no [root@tianyi backups]# date Mon Sep 6 23:24:38 CST 2021 [root@tianyi backups]# hwclock -w [root@tianyi backups]# timedatectl Local time: Mon 2021-09-06 23:24:51 CSTUniversal time: Mon 2021-09-06 15:24:51 UTCRTC time: Mon 2021-09-06 15:24:51Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: yesNTP service: activeRTC in local TZ: no [root@tianyi backups]#

總結

以上是生活随笔為你收集整理的Linux系统之时间管理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。