Linux修改时区

设置时区tzselect

#查看当前日期时区
date -R  
timedatectl
timedatectl | grep "Time zone"
tzselect #设置时区
# 选 5) Asia -> 9) China -> 1) Beijing Time -> 1) Yes

设置之后并没有生效,需按照提示修改配置

You can make this change permanent for yourself by appending the line
        TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

按提示执行命令:

vim /root/.bash_profile
# 文件底部追加 TZ='Asia/Shanghai'; export TZ

另设置时区永久生效方式

ll /etc/ |grep localtime  #查看当前localtime被软连接地址
ll /usr/share/zoneinfo    #查看目录中的时区

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime # 链接到Asia/Shanghai

时间同步ntpdate

# 安装ntp服务器
yum -y install ntp ntpdate
# 开启服务
service ntpd start
# 同步时间
ntpdate 自己的IP

定时同步时间

# 命令,进入一个VI的编辑界面,添加如下任务
crontab -e 
# 一分钟同步一次
*/1 * * * * /usr/sbin/ntpdate time-a.nist.gov  s2m.time.edu.cn ntp.sjtu.edu.cn > /dev/null 2>&1
# 查看是否已经成功添加
Crontab –l  

ntp常用服务器

国内
cn.pool.ntp.org 中国开源免费NTP服务器
ntp1.aliyun.com 阿里云NTP服务器
ntp2.aliyun.com 阿里云NTP服务器
time1.aliyun.com 阿里云NTP服务器
time2.aliyun.com 阿里云NTP服务器

国外
time1.apple.com 苹果NTP服务器
time2.apple.com 苹果NTP服务器
time3.apple.com 苹果NTP服务器
time4.apple.com 苹果NTP服务器
time5.apple.com 苹果NTP服务器
time1.google.com 谷歌NTP服务器
time2.google.com 谷歌NTP服务器
time3.google.com 谷歌NTP服务器
time4.google.com 谷歌NTP服务器
pool.ntp.org 开源免费NTP服务器

本文作者:Zzzy君不见

本文链接:https://www.cnblogs.com/Zzzyyw/p/17024947.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Zzzy君不见  阅读(581)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起