以下方法简单说就是 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 后重启系统,系统时间和日志记录时间一致
更改/etc/profile
TZ='Asia/Shanghai'
export TZ
export /etc/profile只能更改系统时间,不能更日志记录时间
-------------------------------------------------------------------------------
具体测试说明
查看当前时区配置
[root@kvm ~]# tail 3 /etc/profile
unset -f pathmunge
TZ='America/New_York'
export TZ
[root@kvm ~]# echo $TZ
America/New_York
[root@kvm ~]# date
Thu Mar 31 03:08:46 EDT 2016
[root@kvm ~]# date -R
Thu, 31 Mar 2016 03:08:51 -0400
[root@kvm ~]# clock
Thu 31 Mar 2016 03:08:58 AM EDT -0.845611 seconds
查看日志时间戳
[root@kvm ~]# tail -10f /var/log/messages
ule_path: "clearlooks",
ed before gtk_init()
Mar 31 02:56:49 kvm tpvmlpd2[2450]: device read timed out
Mar 31 02:58:35 kvm tpvmlpd2[3392]: device read timed out
Mar 31 03:00:21 kvm tpvmlpd2[3414]: device read timed out
Mar 31 03:02:07 kvm tpvmlpd2[3442]: device read timed out
Mar 31 03:03:53 kvm tpvmlpd2[3520]: device read timed out
Mar 31 03:05:38 kvm tpvmlpd2[3534]: device read timed out
Mar 31 03:07:24 kvm tpvmlpd2[3557]: device read timed out
Mar 31 03:09:10 kvm tpvmlpd2[3578]: device read timed out
用更改环境变量方法更改系统时间,系统时间改变,但查看日志时间戳仍旧没有改变
[root@kvm ~]# TZ='Asia/Shanghai'
[root@kvm ~]# export TZ
[root@kvm ~]# date
Thu Mar 31 15:09:44 CST 2016
[root@kvm ~]#
[root@kvm ~]# tail -10f /var/log/messages
ule_path: "clearlooks",
ed before gtk_init()
Mar 31 02:56:49 kvm tpvmlpd2[2450]: device read timed out
Mar 31 02:58:35 kvm tpvmlpd2[3392]: device read timed out
Mar 31 03:00:21 kvm tpvmlpd2[3414]: device read timed out
Mar 31 03:02:07 kvm tpvmlpd2[3442]: device read timed out
Mar 31 03:03:53 kvm tpvmlpd2[3520]: device read timed out
Mar 31 03:05:38 kvm tpvmlpd2[3534]: device read timed out
Mar 31 03:07:24 kvm tpvmlpd2[3557]: device read timed out
Mar 31 03:09:10 kvm tpvmlpd2[3578]: device read timed out
重启系统后查看系统时间和日志记录时间仍旧不一致
[root@kvm ~]# reboot
Broadcast message from root@kvm
(/dev/pts/0) at 15:10 ...
The system is going down for reboot NOW!
[root@kvm ~]# vim /etc/profile
[root@kvm ~]# source /etc/profile
[root@kvm ~]# echo $TZ
Asia/Shanghai
[root@kvm ~]# date
Thu Mar 31 15:14:10 CST 2016
[root@kvm ~]# date -R
Thu, 31 Mar 2016 15:14:16 +0800
[root@kvm ~]# clock
Thu 31 Mar 2016 03:14:22 PM CST -0.829248 seconds
[root@kvm ~]# tail -10f /var/log/messages
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 03:11:45 kvm vmusr[3052]: [ warning] [Gtk] gtk_disable_setlocale() must be called before gtk_init()
Mar 31 03:12:55 kvm tpvmlpd2[2466]: device read timed out
Mar 31 03:14:21 kvm kernel: hpet1: lost 2 rtc interrupts
Mar 31 03:14:41 kvm tpvmlpd2[3432]: device read timed out
用cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime来更改系统时间并重启
[root@kvm ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite `/etc/localtime'? y
[root@kvm ~]# cat /etc/localtime
TZif2
剥u?'p??Z?p ~h!Iap"^J#)Cp$Gg%_?&?+(??q?LMTCDTCSTTZif2
LMTCDTCST
CST-8
[root@kvm ~]# date -R
Thu, 31 Mar 2016 15:17:50 +0800
[root@kvm ~]# cat /etc/localtime
TZif2
剥u?'p??Z?p ~h!Iap"^J#)Cp$Gg%_?&?+(??q?LMTCDTCSTTZif2
LMTCDTCST
CST-8
[root@kvm ~]# tail -10f /var/log/messages
Mar 31 03:17:07 kvm named[2098]: error (network unreachable) resolving 'L.ROOT-SERVERS.NET/AAAA/IN': 2001:503:ba3e::2:30#53
Mar 31 03:17:07 kvm named[2098]: error (network unreachable) resolving 'L.ROOT-SERVERS.NET/AAAA/IN': 2001:500:1::803f:235#53
Mar 31 03:17:16 kvm named[2098]: managed-keys-zone ./IN: Unable to fetch DNSKEY set 'dlv.isc.org': timed out
Mar 31 03:17:17 kvm named[2098]: error (network unreachable) resolving './NS/IN': 2001:7fd::1#53
Mar 31 03:17:17 kvm named[2098]: error (network unreachable) resolving './NS/IN': 2001:500:2f::f#53
Mar 31 03:17:17 kvm named[2098]: error (network unreachable) resolving './NS/IN': 2001:503:ba3e::2:30#53
Mar 31 03:17:17 kvm named[2098]: error (network unreachable) resolving './NS/IN': 2001:503:c27::2:30#53
Mar 31 03:17:17 kvm named[2098]: error (network unreachable) resolving './NS/IN': 2001:dc3::35#53
Mar 31 03:17:17 kvm named[2098]: error (network unreachable) resolving './NS/IN': 2001:500:1::803f:235#53
Mar 31 03:17:32 kvm tpvmlpd2[2455]: device read timed out
^C
[root@kvm ~]# reboot
Broadcast message from root@kvm
(/dev/pts/0) at 15:18 ...
The system is going down for reboot NOW!
[root@kvm ~]#
Connection closed by foreign host.
Disconnected from remote host(10.0.0.100:22) at 15:18:02.
Type `help' to learn how to use Xshell prompt.
[c:~]$ ssh 10.0.0.100
Connecting to 10.0.0.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Thu Mar 31 15:16:59 2016 from 10.0.0.1
重启后查看系统时间和日志记录时间一致
[root@kvm ~]# tail -10f /var/log/messages
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] Unable to locate theme engine in module_path: "clearlooks",
Mar 31 15:19:36 kvm vmusr[3032]: [ warning] [Gtk] gtk_disable_setlocale() must be called before gtk_init()
^C
[root@kvm ~]# date -R
Thu, 31 Mar 2016 15:19:56 +0800