首页 > 其他分享 >操作系统如何更改时区

操作系统如何更改时区

时间:2022-10-29 10:00:08浏览次数:60  
标签:操作系统 etc zoneinfo 更改 share Asia 如何 usr localtime

1、查看时区的办法 通过查看时区文件的内容,了解可选择的时区。

ls /usr/share/zoneinfo/      #时区文件的一级分类
......................................
Africa      Atlantic   Chile    Eire     Factory  GMT-0      Iceland      Jamaica            localtime  Navajo   Portugal    right      Turkey     WET
America     Australia  CST6CDT  EST      GB       GMT0       Indian       Japan              MET        NZ       posix       ROC        UCT        W-SU
Antarctica  Brazil     Cuba     EST5EDT  GB-Eire  Greenwich  Iran         Kwajalein          Mexico     NZ-CHAT  posixrules  ROK        Universal  zone1970.tab
Arctic      Canada     EET      Etc      GMT      Hongkong   iso3166.tab  leap-seconds.list  MST        Pacific  PRC         Singapore  US         zone.tab
Asia        CET        Egypt    Europe   GMT+0    HST        Israel       Libya              MST7MDT    Poland   PST8PDT     SystemV    UTC        Zulu
......................................

ls /usr/share/zoneinfo/Asia/    #时区文件下的二级分类(二进制文件)
......................................
Aden      Ashkhabad  Beijing   Choibalsan  Dili       Ho_Chi_Minh  Jerusalem  Khandyga      Macau     Novokuznetsk  Qatar      Samarkand      Tbilisi   Ujung_Pandang  Wuhan
Almaty    Atyrau     Beirut    Chongqing   Dubai      Hong_Kong    Kabul      Kolkata       Magadan   Novosibirsk   Qostanay   Seoul          Tehran    Ulaanbaatar    Xian
Amman     Baghdad    Bishkek   Chungking   Dushanbe   Hovd         Kamchatka  Krasnoyarsk   Makassar  Omsk          Qyzylorda  Shanghai       Tel_Aviv  Ulan_Bator     Yakutsk
Anadyr    Bahrain    Brunei    Colombo     Famagusta  Irkutsk      Karachi    Kuala_Lumpur  Manila    Oral          Rangoon    Singapore      Thimbu    Urumqi         Yangon
Aqtau     Baku       Calcutta  Dacca       Gaza       Istanbul     Kashgar    Kuching       Muscat    Phnom_Penh    Riyadh     Srednekolymsk  Thimphu   Ust-Nera       Yekaterinburg
Aqtobe    Bangkok    Chengdu   Damascus    Harbin     Jakarta      Kathmandu  Kuwait        Nanjing   Pontianak     Saigon     Taipei         Tokyo     Vientiane      Yerevan
Ashgabat  Barnaul    Chita     Dhaka       Hebron     Jayapura     Katmandu   Macao         Nicosia   Pyongyang     Sakhalin   Tashkent       Tomsk     Vladivostok
......................................

2、如何修改时区(redhat系和debian系系统都可以)

ls -l /etc/localtime   #查看本地时间信息,确认已知时区
rm -f /etc/localtime   #删除本地时间文件
ln -s /usr/share/zoneinfo/Asia/Beijing /etc/localtime   #创建软链接到localtime;如果源文件和目的文件写反了,会导致时区文件被覆盖。
ls -l /etc/localtime  #再次查看本地时间信息,一般重新创建软连接后,等待10s左右就会更新完成

3、补充 使用ansible来进行批量的时区修改

- name: get timelocal
  shell: ls -l /etc/localtime | awk '{print $11}'
  register: timelocal
 
 
- name: delete loacltime
  shell: rm -f /etc/localtime
  when: timelocal.stdout != "../usr/share/zoneinfo/Asia/Shanghai"
 
- name: create asia time
  shell: ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  when: timelocal.stdout != "../usr/share/zoneinfo/Asia/Shanghai"

#此处是改成亚洲上海,只展示task

标签:操作系统,etc,zoneinfo,更改,share,Asia,如何,usr,localtime
From: https://blog.51cto.com/u_15380854/5805747

相关文章