Centos7.1修改時區(qū)

早些時候Linux下使用NTP做時間同步。新版Cenots開始用chrony。

這里簡單記錄一下:

# 查看當(dāng)前時間
$ date
2017年 08月 11日 星期五 03:28:44 UTC
# NOTE: 這里顯示的時區(qū)為 UTC(通用協(xié)調(diào)時(UTC, Universal Time Coordinated)。UTC與格林尼治平均時(GMT, Greenwich Mean Time)一樣菲语,都與英國倫敦的本地時相同)應(yīng)該改為:中國標(biāo)準(zhǔn)時區(qū)(CST, chinese standard time),類似如下:
$ date
2017年 08月 11日 星期五 11:28:44 CST

使用timedatectl

$ timedatectl
      Local time: 五 2017-08-11 03:28:47 UTC
  Universal time: 五 2017-08-11 03:28:47 UTC
        RTC time: 五 2017-08-11 03:28:56
       Time zone: UTC (UTC, +0000)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

查看時區(qū):

$ timedatectl list-timezones 
Asia/Aden
Asia/Almaty
Asia/Amman
Asia/Anadyr
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
...
...
...
Pacific/Rarotonga
Pacific/Saipan
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Wake
Pacific/Wallis

$ timedatectl set-timezone Asia/Shanghai

$ timedatectl
      Local time: 五 2017-08-11 11:41:03 CST
  Universal time: 五 2017-08-11 03:41:03 UTC
        RTC time: 五 2017-08-11 03:41:02
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
$ date
2017年 08月 11日 星期五 11:41:05 CST

chronyd

$ systemctl restart chronyd.service

# NOTE: 當(dāng)Chrony啟動時送巡,它會讀取/etc/chrony.conf配置文件中的設(shè)置
$ vi /etc/chrony.conf

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

# Ignore stratum in source selection.
stratumweight 0
...

查看時間同步源

$ chronyc sources -v
210 Number of sources = 4

  .-- 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
||                                                /   xxxx = adjusted offset,
||         Log2(Polling interval) -.             |    yyyy = measured offset,
||                                  \            |    zzzz = estimated error.
||                                   |           |
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^+ darwin.kenyonralph.com        2   6    77    23  +3801us[+5460us] +/-  114ms
^* ntp2.flashdance.cx            2   6    77    23  -5332us[-3671us] +/-  100ms
^+ ntp4.flashdance.cx            2   6    77    21    -46ms[  -46ms] +/-  246ms
^+ li734-36.members.linode.c     2   6    77    23    +31ms[  +31ms] +/-   85ms

查看時間同步源狀態(tài)

$ chronyc sourcestats -v
210 Number of sources = 4
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples. \
                           |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
ntp2.itcompliance.dk        4   3   52m    -11.356    123.763   -101ms  8974us
61-216-153-107.hinet-ip.h   6   4   43m     +0.095      2.053  +2827us   497us
biisoni.miuku.net           6   5   43m     -0.260      3.432    -11ms   752us
61-216-153-105.hinet-ip.h   7   6   51m     -0.528      0.493  +2358us   162us
$ chronyc
chrony version 1.29.1
Copyright (C) 1997-2003, 2007, 2009-2013 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
you are welcome to redistribute it under certain conditions.  See the
GNU General Public License version 2 for details.

chronyc> help
Commands:
accheck <address> : Check whether NTP access is allowed to <address>
activity : Check how many NTP sources are online/offline
add peer <address> ... : Add a new NTP peer
add server <address> ... : Add a new NTP server
allow [<subnet-addr>] : Allow NTP access to that subnet as a default
allow all [<subnet-addr>] : Allow NTP access to that subnet and all children
burst <n-good>/<n-max> [<mask>/<masked-address>] : Start a rapid set of measurements
clients : Report on clients that have accessed the server
cmdaccheck <address> : Check whether command access is allowed to <address>
cmdallow [<subnet-addr>] : Allow command access to that subnet as a default
cmdallow all [<subnet-addr>] : Allow command access to that subnet and all children
cmddeny [<subnet-addr>] : Deny command access to that subnet as a default
cmddeny all [<subnet-addr>] : Deny command access to that subnet and all children
cyclelogs : Close and re-open logs files
delete <address> : Remove an NTP server or peer
deny [<subnet-addr>] : Deny NTP access to that subnet as a default
deny all [<subnet-addr>] : Deny NTP access to that subnet and all children
dump : Dump all measurements to save files
local off : Disable server capability for unsynchronised clock
local stratum <stratum> : Enable server capability for unsynchronised clock
makestep : Jump the time to remove any correction being slewed
manual off|on|reset : Disable/enable/reset settime command and statistics
manual list : Show previous settime entries
maxdelay <address> <new-max-delay> : Modify maximum round-trip valid sample delay for source
maxdelayratio <address> <new-max-ratio> : Modify max round-trip delay ratio for source
maxdelaydevratio <address> <new-max-ratio> : Modify max round-trip delay dev ratio for source
maxpoll <address> <new-maxpoll> : Modify maximum polling interval of source
maxupdateskew <new-max-skew> : Modify maximum skew for a clock frequency update to be made
minpoll <address> <new-minpoll> : Modify minimum polling interval of source
minstratum <address> <new-min-stratum> : Modify minimum stratum of source
offline [<mask>/<masked-address>] : Set sources in subnet to offline status
online [<mask>/<masked-address>] : Set sources in subnet to online status
password [<new-password>] : Set command authentication password
polltarget <address> <new-poll-target> : Modify poll target of source
reselect : Reselect synchronisation source
rtcdata : Print current RTC performance parameters
settime <date/time (e.g. Nov 21, 1997 16:30:05 or 16:30:05)> : Manually set the daemon time
sources [-v] : Display information about current sources
sourcestats [-v] : Display estimation information about current sources
tracking : Display system time information
trimrtc : Correct RTC relative to system clock
waitsync [max-tries [max-correction [max-skew]]] : Wait until synchronised
writertc : Save RTC parameters to file

authhash <name>: Set command authentication hash function
dns -n|+n : Disable/enable resolving IP addresses to hostnames
dns -4|-6|-46 : Resolve hostnames only to IPv4/IPv6/both addresses
timeout <milliseconds> : Set initial response timeout
retries <n> : Set maximum number of retries
exit|quit : Leave the program
help : Generate this help

問題及解決

Failed to create bus connection: No such file or directory

問題:

在Docker容器中嘗試修改時區(qū),遇到下面的問題盒卸。
[root@43e8c77668a8 opt]# timedatectl
Failed to create bus connection: No such file or directory

解決:

直接修改時區(qū)配置文件骗爆。


[root@b378039ce558 /]# ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
[root@b378039ce558 /]# cat  /etc/localtime
TZif?\???'p?????Z??6i?p ~h?!Iap"^J?#)Cp$Gg%_?&'I&?A?(+(?#?~?p?CDTCSTTZif2
                                                                         ????~6C)?????\???????'p?????????????Z??6i?p ~h?!Iap"^J?#)Cp$Gg%_?&'I&?A?(+(?#?q?~?pLMTCDTCST
CST-8
[root@b378039ce558 /]# date
Mon Oct  9 17:33:06 CST 2017

擴(kuò)展閱讀:
Failed to create bus connection: No such file or directory.
https://bbs.archlinux.org/viewtopic.php?id=218576

簡介:

# ln -sf /usr/share/zoneinfo/<MYzone>/<MySubZone> /etc/localtime


擴(kuò)展閱讀:

RHEL7 -- 使用Chrony設(shè)置時間與時鐘服務(wù)器同步
http://www.mamicode.com/info-detail-1676443.html
簡介:
對 chronyd和chronyc 的介紹很好。

[置頂] CentOS7 的時間同步方法
http://blog.csdn.net/ghost_leader/article/details/52915833
簡介:
CSDN 上的一篇文章蔽介,介紹的很好...

CHAPTER 2. CONFIGURING THE DATE AND TIME
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/chap-Configuring_the_Date_and_Time.html

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Using_chrony.html
簡介:

redhadt 官網(wǎng)摘投, 解釋還是很詳細(xì)的。

How to configure NTP on CentOS 7
https://blacksaildivision.com/ntp-centos

Set Timezone
https://www.server-world.info/en/note?os=CentOS_7&p=timezone
簡介:

介紹了 timedatectl 的使用虹蓄。

How To Change Timezone on a CentOS 6 and 7
https://www.cyberciti.biz/faq/centos-linux-6-7-changing-timezone-command-line/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末犀呼,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子薇组,更是在濱河造成了極大的恐慌外臂,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,695評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件律胀,死亡現(xiàn)場離奇詭異宋光,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)炭菌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,569評論 3 399
  • 文/潘曉璐 我一進(jìn)店門罪佳,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人黑低,你說我怎么就攤上這事赘艳。” “怎么了投储?”我有些...
    開封第一講書人閱讀 168,130評論 0 360
  • 文/不壞的土叔 我叫張陵第练,是天一觀的道長。 經(jīng)常有香客問我玛荞,道長娇掏,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,648評論 1 297
  • 正文 為了忘掉前任勋眯,我火速辦了婚禮婴梧,結(jié)果婚禮上下梢,老公的妹妹穿的比我還像新娘。我一直安慰自己塞蹭,他們只是感情好孽江,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,655評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著番电,像睡著了一般岗屏。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上漱办,一...
    開封第一講書人閱讀 52,268評論 1 309
  • 那天这刷,我揣著相機(jī)與錄音,去河邊找鬼娩井。 笑死暇屋,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的洞辣。 我是一名探鬼主播咐刨,決...
    沈念sama閱讀 40,835評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼挠说,長吁一口氣:“原來是場噩夢啊……” “哼腺办!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起笨篷,我...
    開封第一講書人閱讀 39,740評論 0 276
  • 序言:老撾萬榮一對情侶失蹤畜挥,失蹤者是張志新(化名)和其女友劉穎仔粥,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蟹但,經(jīng)...
    沈念sama閱讀 46,286評論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡躯泰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,375評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了华糖。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片麦向。...
    茶點(diǎn)故事閱讀 40,505評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖客叉,靈堂內(nèi)的尸體忽然破棺而出诵竭,到底是詐尸還是另有隱情,我是刑警寧澤兼搏,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布卵慰,位于F島的核電站,受9級特大地震影響佛呻,放射性物質(zhì)發(fā)生泄漏裳朋。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,873評論 3 333
  • 文/蒙蒙 一吓著、第九天 我趴在偏房一處隱蔽的房頂上張望鲤嫡。 院中可真熱鬧送挑,春花似錦、人聲如沸暖眼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,357評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽诫肠。三九已至司澎,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間栋豫,已是汗流浹背惭缰。 一陣腳步聲響...
    開封第一講書人閱讀 33,466評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留笼才,地道東北人。 一個月前我還...
    沈念sama閱讀 48,921評論 3 376
  • 正文 我出身青樓络凿,卻偏偏與公主長得像骡送,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子絮记,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,515評論 2 359

推薦閱讀更多精彩內(nèi)容