欢迎光临
我们一直在努力

linux 7设置上海时区为系统时间;

1、查看centos时间是否正确

date

2、删除centos本地时间并设置时区为上海

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

3、使用NTP来从一个时间服务器同步

ntpdate us.pool.ntp.org
#备用服务器:
#服务器一:ntpdate 1.cn.pool.ntp.org
#服务器二:ntpdate 2.asia.pool.ntp.org
#服务器三:ntpdate 3.asia.pool.ntp.org

4、如果提示command not found,那说明ntp没有安装,使用如下命令进行安装

yum -y install ntpdate ntp

5、安装完成后重新执行第三步命令,如果出现错误提示:“no server suitable for synchronization found”那你可以找台香港或美国的机器执行执行第三步命令,这里执行成功后后面显示的IP,我们可以直接利用IP来同步时间,ntpdate 71.168.219.127 就可以成功了,当然你没有香港或是美国的服务器就不能同步时间了吗,那肯定不是,我们可以利用站长工具的超级Ping功能(ping.chinaz.com),Ping上面的任一地址,如:1.cn.pool.ntp.org,然后找个最快的IP来进行时间的同步。

[root@localhost ~]# ntpdate us.pool.ntp.org
27 Oct 09:56:11 ntpdate[21837]: step time server 71.168.219.127 offset 79.495215 sec
#若是上面方式不行,可以用超级PING来获取的最快IP,然后直接用IP同步时间。
[root@localhost ~]# ntpdate 129.250.35.251
27 Oct 09:58:11 ntpdate[5943]: step time server 129.250.35.251 offset 22.128244 sec

6、执行完成后用date命令查看是否经为北京时间

最后一定要保存时钟

clock -w

1.date    {查看目前本地的时间}

2.hwclock –show   {查看硬件的时间}

3.如果硬件的时间是对不上,那就对硬件的时间进行修改、

4.hwclock –set –date ‘014-12-15 15:15:15’   {设置硬件时间}

5.hwclock  –hctosys  {设置系统时间和硬件时间同步}

6.clock -w    {保存时钟}

7.最后在通过重启,init 6 快速重启后,查看系统时间是否真正生效!

赞(1) 打赏
原创文章转载请注明出处:爱编程 » linux 7设置上海时区为系统时间;
分享到: 更多

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

爱编程、一个运维兼程序员的博客!

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏