修改liunx系统时区

系统时间设置

查看系统时间 date

设置系统时间 date -s (月/日/年 时:分:秒)

[root@localhost ~]# rm -rf  /etc/localtime
[root@localhost ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

现在就要办法解决jvm执行取得的时间和系统时间不一致的问题。通过在网上查阅资料,应该是jvm运行的时区设置问题。
解决的办法有几种:

1、在程序中使用java的函数设定时区。
2、在启动java程序时加参数-Duser.timezone=GMT+8
3、调整系统的时区设置

 [root@localhost ~]#vi /etc/sysconfig/clock   #编辑时间配置文件
    ZONE="Asia/Shanghai"
    UTC=false                   #设置为false,硬件时钟不于utc时间一致
    ARC=false
[root@localhost ~]#ln -sf /usr/share/zoneinfo/Asia/Shanghai    /etc/localtime    #linux的时区设置为上海时区
[root@localhost ~]#ntpdate cn.pool.ntp.org    #对准时间
[root@localhost ~]#/sbin/hwclock --systohc   #设置硬件时间和系统时间一致并校准 

发现/etc/sysconfig/clock 配置文件的时区还是纽约时间,难怪会差近8个小时咯。可能是装系统的时候没有没有选择时区默认的纽约时间。

时间不一样,相差8小时,可检查数据库时间是否于服务器时间一致。如果不一致,先修改服务时间,在将数据库重启。

同步网络

ntpdate命令:

 [root@localhost ~]#ntpdate -u 210.72.145.44 :网络时间同步命令

注意:若不加上-u参数, 会出现以下提示:no server suitable for synchronization found
-u:从man ntpdate中可以看出-u参数可以越过防火墙与主机同步;
210.72.145.44:中国国家授时中心的官方服务器。

ntp常用服务器:
中国国家授时中心:210.72.145.44
NTP服务器(上海) :ntp.api.bz
美国:time.nist.gov 
复旦:ntp.fudan.edu.cn 
微软公司授时主机(美国) :time.windows.com 
台警大授时中心(台湾):asia.pool.ntp.org

硬件时间设置
查看硬件时间

[root@localhost ~]#hwclock --show

或者

[root@localhost ~]#clock --show

设置硬件时间

[root@localhost ~]#hwclock --set --date="07/07/06 10:19" (月/日/年 时:分:秒)

或者

[root@localhost ~]# clock --set --date="07/07/06 10:19" (月/日/年 时:分:秒)

硬件时间和系统时间的同步
按照前面的说法,重新启动系统,硬件时间会读取系统时间,实现同步,但是在不重新启动的时候,需要用hwclock或clock命令实现同步。
硬件时钟与系统时钟同步:# hwclock --hctosys(hc代表硬件时间,sys代表系统时间)或者# clock --hctosys
系统时钟和硬件时钟同步:# hwclock --systohc或者# clock --systohc

发布了197 篇原创文章 · 获赞 30 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/Rio520/article/details/104370607