Linux设置系统时区以及同步系统时间

悠悠 2023-10-02 10:16 95阅读 0赞

一、tzselect设置时区

  1. date -R #查看当期时区
  2. tzselect #设置时区

在这里插入图片描述

设置后会提示永久生效的提示,提示信息如下:

  1. You can make this change permanent for yourself by appending the line
  2. TZ='Asia/Shanghai'; export TZ
  3. to the file '.profile' in your home directory; then log out and log in again.
  4. Here is that TZ value again, this time on standard output so that you
  5. can use the /usr/bin/tzselect command in shell scripts:
  6. Asia/Shanghai

按提示执行命令:

  1. TZ='Asia/Shanghai'; export TZ
  2. #配置用户目录下文件,追加内容TZ='Asia/Shanghai'; export TZ
  3. vim /root/.bash_profile >> TZ='Asia/Shanghai'; export TZ

另设置时区永久生效方式

  1. ll /etc/ |grep localtime #查看当前localtime被软连接地址
  2. ll /usr/share/zoneinfo #查看目录种的时区
  3. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

二 、ntpdate同步时间

  1. # 安装ntp服务器
  2. yum -y install ntp ntpdate
  3. # 开启服务
  4. service ntpd start
  5. # 同步时间
  6. ntpdate 192.168.125.133(红色部分改为自己的IP地址)

2.1、定时同步时间

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

2.2、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服务器

发表评论

表情:
评论列表 (有 0 条评论,95人围观)

还没有评论,来说两句吧...

相关阅读

    相关 设置Linux系统时区

    最近在写Dockerfile制作docker镜像的时候,发现生成的容器里面的系统时间不对。这才注意到还需要设置下系统时区。 设置linux系统时区的方法很简单(可以通过:da