zoukankan      html  css  js  c++  java
  • centos 7.2 同步北京时间 ,多台机器同步时间

    linux 系统没有北京时间,同步的是上海时间

    linux 系统有两个时钟:一个是硬件时钟,即BIOS时间;另一个是系统时钟,是linux系统Kernel(内核)时间。

    系统开启时,系统会读取硬件时间,设置系统时间。因此,设置了系统时间,重启时会失效。

    要想永久更改时间,可以先同步系统时间(基于网络时间,准确性较高),再同步系统时间

    第一种情况 :有网

    以网络时间为准校验

    (1)查看时区

    date    -- 查看系统时间
    [root@develop Asia]# date -R
    Fri, 22 Mar 2019 14:11:10 +0800 -- +0800 代表是东八区,如果不是,自行更改到东八区

    (2)安装ntpdate工具

    yum install ntpdate

    (3)同步时间,用的是阿里云的服务器

    systemctl stop  ntpd         -- 停掉ntpd 服务,使 ntpdate 可以运行
    ntpdate ntp1.aliyun.com

    或者 ntpdate time.windows.com
    ntpdate asia.pool.ntp.org
    ntpdate time.nuri.net

    看到上述信息,则代表同步成功,否则失败

    (4)同步硬件时间

    hwclock  查看硬件时间
    hwclock --systohc --localtime -- 同步硬件时间

    (5)永久生效

    hwclock -w 
    systemctl start  ntpd    -- 结束完之后 ,开启ntpd

     第二种情况 :没有网络

    这种同步时间的方法,很适合在无网的情况下,同步机器集群时间

    下面一起操作一遍。

    如果  有两台机器,选择其中一台机器A,作为服务端

                                                        机器B,作为客户端

    (1)修改服务端A

    ① 修改配置文件

    [root@hanadevelop Asia]# vi  /etc/ntp.conf

    ②重启ntpd

    systemctl restart ntpd   -- 要保证ntpd 服务开启,不然其它机器不能同步该机器的时间

    (2)修改客户端机器B

    ①修改配置

    [root@develop Asia]# vi  /etc/ntp.conf

    [root@demo sysconfig]# systemctl restart ntpd
    [root@demo sysconfig]# systemctl enable ntpd
    [root@demo sysconfig]# systemctl stop  ntpd

    (3)测试

    ①修改机器A的时间

    [root@hanadevelop Asia]# date -s '2019-3-22 17:00:11'
    2019年 03月 22日 星期五 17:00:11 CST

    ②同步机器B的时间

    查看

    同步完成

    ③ 同步硬件时间

    hwclock --systohc --localtime     -- 同步硬件时间
    hwclock -w     -- 永久生效
  • 相关阅读:
    .bat文件打开指定网页,并运行jar包
    jar包制作一个可执行文件
    如何让局域网其他电脑通过IP直接访问自己电脑的网站
    Sypder 安装和使用
    tomcat服务器输入localhost可以访问,ip无法访问解决办法
    【转载】高性能网站建设
    网站优化
    JavaWeb 项目开发中的技术总结
    反射工具类——ReflectUtils
    Ajax 的缺点
  • 原文地址:https://www.cnblogs.com/yancun8141/p/10577922.html
Copyright © 2011-2022 走看看