最近遇到一个有关timezone的问题:有些application需要环境变量TZ,可是我们刚刚装好的RHEL没有设置TZ,而我又没有root权限去改,查了半天资料,发现所有对timezone的改动都需要重启机器才能生效,没有办法即时生效……Anyway,还是把查到的资料罗列在下面,以备将来用到。

  • Linux Clock Configuration
  • Howto: Linux server change or setup the timezone

原文:http://www.linuxselfhelp.com/quick/clock.html

Linux Clock Configuration

Author: Edward Buck
Version: .2
Last edited: December 19, 2002

Summary

This guide will help you setup the correct date and time on your Red Hat 7.x Linux system including setting up ntpd for online time synchronization.

Instructions

There are two clocks to configure in Linux, the hardware clock and the system clock. The hardware clock determines the system clock on system boot. While the system is running, changes to one of these doesn't affect the other.

Note: it's best to set the hardware clock and have the system clock be set upon a reboot. Changing the system clock by using the date program on a running system could cause date discontinuities and consequently problems. If you will be using ntpd, you probably don't need to set either of these clocks (unless the current time is more than 1000s off the real time). Just setup ntpd and let ntpd adjust the time (it will do it in small steps to keep system timestamps reliable).

  1. If convenient, use Red Hat's dateconfig tool. Using the dateconfig tool will update both the system clock and the hardware clock. The dateconfig tool also allows you to setup ntpd, which will keep the system clock in sync with a remote server.

    If using the dateconfig tool is not an option, follow the remaining steps to configure manually. For example, if you are using a non graphical terminal (dateconfig requires X windows), you must configure manually.

  2. You can use timeconfig to configure the timezone and UTC settings. Timeconfig will update /etc/sysconfig/clock and /etc/localtime.
  3. Set the time zone manually if not already set.

    Linux uses the file /etc/localtime to determine the time zone. This file should be either a copy of the appropriate timezone file from the directory /usr/share/zoneinfo or a symbolic link. If your time zone is incorrect, create a symbolic link to the appropriate timezone file.

    # ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
  4. Set whether hwclock uses local time or UTC

    Edit the file /etc/sysconfig/clock and change "UTC=" to true or false. If you have a dual-boot system with Windows, using UTC may cause problems for Windows.

  5. Set the system clock
    # date MMDDhhmmCCYY.ss

    where MM is month, DD is day, hh is hour, mm is minutes, CCYY is year and ss is seconds. Time should be in 24-hour notation.

    To only set the time:

    # date -s hh:mm:ss
  6. Set the hardware clock 

    To set the hardware clock to the current system clock:

    # setclock

    this method looks at /etc/sysconfig/clock to determine whether the hardware clock is set to UTC

    Another method:

    # hwclock --systohc# hwclock --systohc --utc

    use the second option if you use UTC.

    Set hwclock manually:

    # hwclock --set --date="9/22/96 16:45:05"

    Everytime you use the hwclock --set command, it will create or edit the file /etc/adjtime to determine the systematic drift. Once you have some history, you can use the --adjust option to adjust the hardware clock appropriately. Run as a cron job if you want the clock to adjust automatically on a regular schedule. Don't use the --adjust function when using ntpd since ntpd will turn the "11 minute mode" on, which is best left alone. See the hwclock manpage for more info.

  7. Setup ntpd for automatic synchronization with a remote server. 

    Run Red Hat's setup utility to make ntpd start on boot up and edit /etc/ntp.conf

    Set server and fudge options:

    server time.nist.govfudge  time.nist.gov stratum 10

    Enable multicastclient:

    multicastclient     # listen on default 224.0.1.1

    Edit /etc/sysconfig/ntpd if necessary. The default should be fine.

    Start the ntpd daemon:

    # service ntpd start

原文:http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/

Howto: Linux server change or setup the timezone

by VIVEK GITE on AUGUST 27, 2006 · 32 COMMENTS

Q. My timezone is pointing to wrong timezone. How do I setup or change the timezone under Linux operating systems?

A. Unix time, or POSIX time, is a system for describing points in time: it is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.

The definition for time zones can be written in short form as UTC±n (or GMT±n), where n is the offset in hours.

Change Linux timezone

Select the method as per your Linux distribution:

If you are using Fedora / RHEL / Cent OS Linux

Type the redhat-config-date command at the command line to start the time and date properties tool.
# redhat-config-date
OR type setup and select time zone configuration (good for remote ssh text based Linux server sessiob)
# setup

Select timezone configuration

Fig.01: Redhat / CentOS Server Setting Up Timezone

Now, just follow on screen instructions to change timezone.

Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.

Generic procedure to change timezone

Change directory to /etc
# cd /etc

Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime
OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends)
# ln -sf /usr/share/zoneinfo/EST localtime
OR if you want to set up it to IST (Asia/Calcutta):
# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime
Please mote that in above example you need to use directory structure i.e. if you want to set the timezone to Calcutta (India) which is located in the Asia directory you will then have to setup using as above.

Use date command to verify that your timezone is changed:
$ date
Output:

Tue Aug 27 14:46:08 EST 2006

Use of environment variable

You can use TZ environment variable to display date and time according to your timezone:
$ export TZ=America/Los_Angeles
$ date

Sample Output:

Thu Aug 27 11:10:08 PST 2006

Linux TimeZone设置相关推荐

  1. ubuntu下更改时区_技术|如何在 Ubuntu Linux 中设置或更改时区

    你安装 Ubuntu 时,它会要求你设置时区.如果你选择一个错误的时区,或者你移动到世界的一些其它地方,你可以很容易地在以后更改它. 如何在 Ubuntu 和其它 Linux 发行版中更改时区 这里有 ...

  2. linux操作系统-设置静态ip

    在使用linux虚拟机的时候因为经常有关机的需求,然后重新开机后可能面临这上一次获取的ip被改变,在这里我分享一下在linux 下设置静态ip的经验 1.查看路由状态 [root@localhost ...

  3. 在Linux里设置环境变量的方法(export PATH)

    在Linux里设置环境变量的方法(export PATH) 在Linux里设置环境变量的方法(export PATH) 一般来说,配置交叉编译工具链的时候需要指定编译工具的路径,此时就需要设置环境变量 ...

  4. linux 下 设置 MySQL8 表名大小写不敏感方法,解决设置后无法启动 MySQL 服务的问题

    linux 下 设置 MySQL8 表名大小写不敏感方法,解决设置后无法启动 MySQL 服务的问题 参考文章: (1)linux 下 设置 MySQL8 表名大小写不敏感方法,解决设置后无法启动 M ...

  5. WIN7上VM中的LINUX如何设置上网

    WIN7上VM中的LINUX如何设置上网? 这个问题的关键是VM的版本,只有VM8开始才能支持WIN7上的调协上网.如果安装的版本比这低,直接下载VM8重新安装是最快捷的方法. 在安装VM8的过程中设 ...

  6. Linux离线时间设置(NTP)

    linux离线时间设置 为什么需要使用到NTP时间同步服务 ,在做某些服务时,我们需要所有的服务器保持同一时间执行预设好的命令,将服务同步协作. 操作方法如下: 先关闭firewalld 和 Seli ...

  7. linux系统中建立网络白名单,Linux下设置防火墙白名单(RHEL 6和CentOS 7)的步骤

    进入Linux 命令行,编辑防火墙规则配置文件 iptables vi /etc/sysconfig/iptables 下面是一个白名单设置的例子: # Firewall configuration ...

  8. Linux(Ubuntu)设置环境变量(转载)

    Linux(Ubuntu)设置环境变量(转载) http://blog.csdn.net/wumingxing0228/article/details/6050175 环境变量是和Shell紧密相关的 ...

  9. Linux里设置环境变量的方法(export PATH)

    转自:在Linux里设置环境变量的方法(export PATH) 一般来说,配置交叉编译工具链的时候需要指定编译工具的路径,此时就需要设置环境变量.例如我的mips-linux-gcc编译器在&quo ...

最新文章

  1. Helm包管理工具(简介、安装、方法)
  2. C++对象的构造和析构
  3. php快速就业教程,PHP就业快学教程004,基本语法“条件控制语句”!
  4. Day 32 processthreading_4
  5. 运维 --- Nginx高级功能介绍
  6. 谁的青春不迷惘,谁的年少不忧伤
  7. 量子力学计算机原理,量子力学的基本原理
  8. 资产配置方案(基金)
  9. fisheye calib视野调整
  10. 面经-应届生秋招上岸笔记(低难度 带项目版)
  11. rhcsa第二天作业9道题
  12. echarts 双y轴设置
  13. 重读经典(CLIP上):《Learning Transferable Visual Models From Natural Language Supervision》
  14. 线索二叉树(前中后序线索化/遍历/画线索)
  15. S3C6410(OK6410开发板介绍)
  16. 蒸发水量(mm/s)和 潜热通量(W/m2) 之间的单位转化
  17. 关于如何在XP系统上运行opencv生成的C++动态库
  18. 初试傲游浏览器/Maxthon3,4大惊喜,1点遗憾
  19. uva11400 动态规划
  20. meb备份mysql,MySQL企业版备份工具MEB

热门文章

  1. 【一年一个小知识】如何查询iPad电池寿命(使用快捷指令)?
  2. linux 下 添加 4G 模块的支持
  3. ALT::CW2AEX无法访问private成员问题解决
  4. c语言L-length与L.length
  5. zblog模板 php,ZBlogPHP模板怎么修改ZBlogPHP主题制作主题教程
  6. java基础知识大全
  7. vue2.6 + elementUI 汽车管理系统
  8. Win11重置网络后找不到wifi的解决办法
  9. 【苹果共享相册推送】imessage苹果共享相簿第一个第二代月,然后更换服务器证书
  10. 【原创】清除、删除、重置AD账户、OU属性值往AD的OU属性添加值