linux时间调整

查看当前系统时间

[root@VM-12-12-centos ~]# date
Sat Nov 18 16:09:11 CST 2023

Sat:表示星期六Saturday的缩写

Nov:表示十一月November的缩写

18:表示日期18号

16:09:11:时间

CST:China Standard Time中国标准时间

2023:年份

查看系统时区

[root@VM-12-12-centos ~]# date -R
Sat, 18 Nov 2023 16:09:04 +0800

 +0800:+8区

如何同步网络时间

同步NTP网络时间

NTP(NetWork Time Protocol) 网络时间协议

阿里云NTP服务器地址:ntp1.aliyun.com,ntp2.aliyun.com,ntp3.aliyun.com

先安装同步工具

yum install -y ntpdate 

为了测试我先把时间调成错误的时间方便看出效果

[root@VM-12-12-centos ~]# date -R
Sat, 18 Nov 2023 17:34:18 +0800
[root@VM-12-12-centos ~]# date -s 12:00:00
Sat Nov 18 12:00:00 CST 2023
[root@VM-12-12-centos ~]# date -R
Sat, 18 Nov 2023 12:00:05 +0800

现在 同步NTP网络时间

如果出现这样的错误说明ntpdate同步已经开启过了

[root@VM-12-12-centos ~]# ntpdate  ntp1.aliyun.com
18 Nov 12:02:15 ntpdate[19383]: the NTP socket is in use, exiting

需要停止掉 ntpdate

[root@VM-12-12-centos ~]# service ntpd stop
Redirecting to /bin/systemctl stop ntpd.service

重新同步

[root@VM-12-12-centos ~]# date -R
Sat, 18 Nov 2023 12:03:20 +0800

[root@VM-12-12-centos ~]# ntpdate ntp1.aliyun.com
18 Nov 17:44:27 ntpdate[21627]: step time server 120.25.115.20 offset 20079.390137 sec

[root@VM-12-12-centos ~]# date -R
Sat, 18 Nov 2023 17:48:13 +0800

如何同步自己服务器时间 

有时候我们不管时间的对错,需求只要两个服务器时间一致就行。

 需要在被同步服务器搭建ntp服务器。

如何修改系统的时区

 只需要修改/etc/localtime的软链接指向的时区文件。

[root@VM-12-12-centos ~]# ls -l /etc/localtime 
lrwxrwxrwx 1 root root 33 Jun 14 15:06 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai

[root@VM-12-12-centos ~]# rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

[root@VM-12-12-centos ~]# ls -l /etc/localtime
lrwxrwxrwx 1 root root 36 Nov 18 03:56 /etc/localtime -> /usr/share/zoneinfo/America/New_York

[root@VM-12-12-centos ~]# date -R
Sat, 18 Nov 2023 04:02:17 -0500

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值