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

一、tzselect设置时区

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

在这里插入图片描述

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

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

按提示执行命令:

TZ='Asia/Shanghai'; export TZ
#配置用户目录下文件,追加内容TZ='Asia/Shanghai'; export TZ
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

二 、ntpdate同步时间

# 安装ntp服务器
yum -y install ntp ntpdate

# 开启服务
service ntpd start

# 同步时间
ntpdate 192.168.125.133(红色部分改为自己的IP地址)

2.1、定时同步时间

# 命令,进入一个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  

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

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

书香水墨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值