• linux时间调整


    查看当前系统时间

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

    Sat:表示星期六Saturday的缩写

    Nov:表示十一月November的缩写

    18:表示日期18号

    16:09:11:时间

    CST:China Standard Time中国标准时间

    2023:年份

    查看系统时区

    1. [root@VM-12-12-centos ~]# date -R
    2. 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 

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

    1. [root@VM-12-12-centos ~]# date -R
    2. Sat, 18 Nov 2023 17:34:18 +0800
    3. [root@VM-12-12-centos ~]# date -s 12:00:00
    4. Sat Nov 18 12:00:00 CST 2023
    5. [root@VM-12-12-centos ~]# date -R
    6. 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

    重新同步

    1. [root@VM-12-12-centos ~]# date -R
    2. Sat, 18 Nov 2023 12:03:20 +0800
    3. [root@VM-12-12-centos ~]# ntpdate ntp1.aliyun.com
    4. 18 Nov 17:44:27 ntpdate[21627]: step time server 120.25.115.20 offset 20079.390137 sec
    5. [root@VM-12-12-centos ~]# date -R
    6. Sat, 18 Nov 2023 17:48:13 +0800

    如何同步自己服务器时间 

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

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

    如何修改系统的时区

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

    1. [root@VM-12-12-centos ~]# ls -l /etc/localtime
    2. lrwxrwxrwx 1 root root 33 Jun 14 15:06 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
    3. [root@VM-12-12-centos ~]# rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
    4. [root@VM-12-12-centos ~]# ls -l /etc/localtime
    5. lrwxrwxrwx 1 root root 36 Nov 18 03:56 /etc/localtime -> /usr/share/zoneinfo/America/New_York
    6. [root@VM-12-12-centos ~]# date -R
    7. Sat, 18 Nov 2023 04:02:17 -0500

  • 相关阅读:
    SELinux零知识学习八、SELinux策略语言之客体类别和许可(2)
    云硬盘和物理硬盘的区别
    【LeetCode】1608. 特殊数组的特征值
    英语六级-day4
    2M大小的PDF文档上传到LangChain-ChatGLM知识图谱中,大致需要的时间
    javaScript深拷贝和浅拷贝简单梳理
    将0-255的色彩映射表导出为RGB波段
    leaflet+vue2实现地图交互
    Java进阶教程(一)关键字
    【面经】讲一下BASE理论
  • 原文地址:https://blog.csdn.net/weixin_51262054/article/details/134479611