美文网首页
linux 时区修改及时间同步

linux 时区修改及时间同步

作者: 大鹏一怒乘风起 | 来源:发表于2019-08-14 14:14 被阅读0次

在Linux中与时间相关的文件

/etc/localtime/etc/timezone

/etc/localtime 主要与时间相关对应得配置为

/usr/share/zoneinfo/Asia/Shanghai  替换 /etc/localtime

一般直接 

cp/usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

/usr/share/zoneinfo/Asia 下对应亚洲及相应地方

/etc/timezone 主要是服务器的时区

tzselect 可以选择相应时区,生成一个地址信息,然后重定向到/etc/timezone

echo'Asia/Shanghai'>/etc/timezone

时间同步脚本:

把shell脚本放入/ect/cron.hourly下面

编辑名称 ntpdate

内容如下:

Bash

#!/bin/bash

NTPDate=/usr/sbin/ntpdate#阿里NTP服务器:

#通用: 公网:ntp{1-7}.aliyun.com,内网:ntp.cloud.aliyuncs.com

#经典网络:ntp{1-6}..cloud.aliyuncs.com

#专用VPC:ntp{7-12}.cloud.aliyuncs.com

Server="ntp1.aliyun.com"if!test-t 0;

then

MYRAND=$RANDOM

MYRAND=${MYRAND:=$$}

if[$MYRAND -gt 9];

then

sleep

`echo$MYRAND|sed's/.*\(..\)$/\1/'|sed's/^0//'`fifi$NTPDate-su$Serverif[-f /sbin/hwclock];then/sbin/hwclock --systohcfi

时间服务器地址:

ntpdate ntp.api.bz

若要改为UTC时区,直接cp /usr/share/zoneinfo/UTC  /etc/localtime

tzselect 选择0时区即可

相关文章

网友评论

      本文标题:linux 时区修改及时间同步

      本文链接:https://www.haomeiwen.com/subject/fmugjctx.html