文章转载于:

1、https://blog.csdn.net/u010316188/article/details/79503376?utm_source=blogxgwz9

2、https://blog.csdn.net/weixin_35852328/article/details/79506453

1、手动设置

Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。

系统时间:指当前Linux Kernel中的时间。

硬件时间:主板上有电池供电的时间。

查看系统时间的命令: #date

设置系统时间的命令: #date –set(月/日/年 时:分:秒)

例:#date –set “10/11/10 10:15”

查看硬件时间的命令: # hwclock

设置硬件时间的命令: # hwclock –set –date = (月/日/年 时:分:秒)

上述提到的是手动设置时间到一个时间点,可能与当前网络的时间有误差。

2、与时间服务器上的时间同步

  1. 安装ntpdate工具

yum -y install ntp ntpdate

2、设置时间为阿里服务器的时间

ntpdate ntp1.aliyun.com

3、将系统时间写入硬件时间

hwclock –systohc

3、把自己的一台服务器当成时间服务器,可以让别的服务器来同步

搭建步骤,我这里是centos系统,不同系统可能会不一样
      3.1、修改vi /etc/ntp.conf 文件,可参考

[root@learn ~]# cat /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.37.255 mask 255.255.255.0 nomodify notrap
##开启上面这一行,去掉注释,  这里192.168.37.255是你电脑广播地址,在ifconfig命令中能看到【inet addr:192.168.37.141  Bcast:192.168.37.255  Mask:255.255.255.0】
#Use public servers from the pool.ntp.org project.
#Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#由于是把自己电脑机器当成ntpd服务器,不需要连接外网,所以注释下上面四行,  添加下面两行,
server 127.127.1.0 #local clock
fudge 127.127.1.0 startnum 10
#broadcast 192.168.1.255 autokey    # broadcast server
#broadcastclient            # broadcast client
#broadcast 224.0.1.1 autokey        # multicast server
#multicastclient 224.0.1.1      # multicast client
#manycastserver 239.255.254.254     # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
--------------------- 

3.2、修改完成开启ntpd服务器
              [root@learn ~]# sudo service ntpd start  --开启ntpd服务器
              [root@learn ~]# sudo chkconfig ntpd on --设置ntpd服务
      3.3、其他机器可通过ntpdate命令来同步时间
              /usr/sbin/ntpdate learn.hadoop1.com --这里的learn.hadoop1.com是我的机器主机名

设置linux时间为北京时间相关推荐

  1. 微软电脑怎么设置时间服务器地址,如何配置Internet时间设置,让电脑时间与北京时间分秒不差...

    分秒不差的时间在如今这个时代什么时候最有用呢?呵呵,就是秒杀商品时.之前天猫搞了一个秒杀活动,就因为Microsoft酋长相信了电脑上的时间,结果比准确的北京时间晚了10多秒,错过了时机.而且今天Mi ...

  2. java 设置utc时间格式_UTC时间和北京时间(Java处理)

    1.时间说明 具体时间说明:https://blog.csdn.net/top_code/article/details/50462922 图借鉴上述链接中的内容: UTC时间:是世界标准的时间. 北 ...

  3. php输出世界时转北京时,php中把美国时间转为北京时间的自定义函数分享

    php中把美国时间转为北京时间的自定义函数分享 由于最近做邮件系统用到了时间转化,需要把从谷歌gmail下载下来的邮件时间转化为北京时间,于是乎就写了一个时间转化函数,希望对有需要的盆友所有启迪,我们 ...

  4. 修改Centos的系统时间为北京时间

    修改Centos的系统时间为北京时间 今天添加自动任务的时候发现服务器的时候不是北京时间,现在我们将它改为北京时间. 1.删除本地时间并设置时区为上海 rm -rf /etc/localtime ln ...

  5. UTC时间、GMT时间、CST时间(北京时间)、时间戳

    一.几个时间相关的概念. GMT时间:Greenwich Mean Time,格林尼治平时,又称格林尼治平均时间或格林尼治标准时间.是指位于英国伦敦郊区的皇家格林尼治天文台的标准时间. GMT存在较大 ...

  6. UTC时间与北京时间

    每个地区都有自己的本地时间,在网上以及无线电通信中时间转换的问题就显得格外突出.我自己就经常混淆于此,特地研究了一下,记录在此以备忘. 整个地球分为二十四时区,每个时区都有自己的本地时间.在国际无线电 ...

  7. JavaScript把世界各地客户端时间转为北京时间,并取得时间戳

    1.把客户端时间转换为北京时间 function getBeijingtime() {//获得当前运行环境时间var d = new Date();currentDate = new Date();t ...

  8. c语言utc时间转换北京时间_C/C++标准库之转换UTC时间到local本地时间详解

    前言 UTC 时间DateTime.UtcNow 和 系统本地时间 DateTime.Now 相差8个时区 ,美国本地时间和北京时间相差15个时区: 美国,而一般使用UTC时间方便统一各地区时间差异. ...

  9. 获取北京时间授时api stm32 esp8266获取北京时间、年月日、星期api GMT格林威时间转换北京时间

    苏宁获取北京时间的api不要太方便:http://quan.suning.com/getSysTime.do 使用 Fidder抓包调试,查看HTTP返回报文: 双击左侧抓取到的HTTP返回报文.使用 ...

  10. C#之Unix时间和北京时间互转

    Unix时间起始时间为1970年1月1日0时0分0秒 北京时间起始时间为1970年1月1日8时0分0秒 北京时间转Unix时间如下: DateTime dtUnix = new DateTime(19 ...

最新文章

  1. 小程序工程化实践(上篇)-- 手把手教你撸一个小程序 webpack 插件,一个例子带你熟悉 webpack 工作流程...
  2. JQuery+CSS3实现封装弹出登录框效果
  3. Android中文API(127) —— MessageQueue
  4. 建立桌面文件管理格子_你不知道文件管理神器,一键收拾乱糟糟的桌面
  5. ATI显卡开启fedora9的3d后果的一些条记
  6. Linux中source是什么指令?
  7. java与安卓接口_Android-Java-接口Interface
  8. XML入门的常见问题
  9. mysql游戏调整等级_mysql求游戏排名
  10. 人脸检测FDDB测试ROC曲线生成
  11. python复数类型的虚部通过_Python 复数数据类型详解(complex)[学习 Python 必备基础知识][看此一篇就够了]...
  12. 校友故事|我在科大感受理工科“严谨的浪漫主义”
  13. 怎样给证件照快速改底色?告诉大家一个简单方法
  14. SEBank银行项目第一个星期的进度安排
  15. 怎么调整计算机显示屏,电脑显示器画面怎么调整
  16. 大学计算机作业互评评语简短,大学学生互评评语简短
  17. 【面试题目】2019年中心面试题目记录
  18. 机器学习基础 LR学习
  19. 分享一个技术知识类电子书网站
  20. 在STM32F103C8T6上使用RT_Thread Nano移植控制台和Finsh

热门文章

  1. 台式计算机软件安装的完整过程,台式电脑怎么自己动手组装 史上最全的组装电脑详细图文教程...
  2. smarty模板引擎工作原理
  3. Android App卡顿分析,以及使用Choreographer进行帧率统计监测
  4. TCP /IP协议详解【转】
  5. python中shutil.copyfile的用法_python模块之shutil
  6. 利用C语言编写一个网络分析器
  7. Ghost使用中的异常情况及应对方法
  8. [答疑]激活码的数据模型
  9. python列表、字典text:用户输入整数n,生成长度为n的列表,将n个随机数放入列表中
  10. 文化使者“字幕组”拥抱BCH