1. 时区设置
1.1 Timezone文件
ls -F /usr/share/zoneinfo
1.2 Timezone Details
zdump Asia/Shanghai
1.3 设置timezone
方法一:直接link或者拷贝Timezone文件至/etc/localtime
ls -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
方法二:使用tzselect命令,设置环境变量TZ
tzselect
其中环境变量TZ的优先级更高,同时存在时,以TZ为准
2. 时间设置
Real Time Clock(RTC): 硬件时钟,BIOS
System Time Clock: 系统时间,Kernel
2.1 显示硬件时间
hwclock --show
2.2 BIOS to Kernel
hwclock --hctosys
2.3 Kernel to BOIS
hwclock --systohc
3. 夏令时(DST)
一般情况下,夏令时规则已经被写入Timezone文件中,当系统时间满足夏令时规则时,系统自动调整时间。
3.1 通过TZ来设置DST, 以系统默认bash为例:
vi /etc/profile
TZ=BEIST-8BEIDT-9,M6.2.4/15:00,M6.2.4/20:00
source /etc/profile
参数说明:
BEIST-8:切换前的时区,UTC+08
BEIDT-9: 切换后的时区,UTC+09 (其实不存在,测试使用)
M6.2.4: 六月的第二个星期四
表达式的含义:六月的第二个星期四,从15:00至20:00,系统时间向前跳变一小时
3.2 DST变换,对oracle的影响
不会影响oracle数据库时区,但会影响登录session时区
select dbtimezone, sessiontimezone from dual;
alter database set time_zone='+09:00';
alter session set time_zone='+08:00';
4. NTP 时间同步
4.1 NTP Server
4.1.1 修改ntp配置文件
vi /etc/ntp.conf
# broardcastclient
server 127.127.1.0
4.1.2 restart ntp
rcntp restart
4.1.3 状态检查
ntpq -p
4.1.4 添加到启动服务
chkconfig -a ntp
4.2 NTP Client
4.2.1 修改crontab
crontab -e
0,30 * * * * /usr/sbin/ntpdate ntp.server.com