NTP系统时间同步-操作记录
在初始化一台linux服务器后,发现这台服务器的时间不对
[root@dev ~]# date
2016年 10月 11日 星期二 07:04:34 CST
Linux时钟分为系统时钟 (System Clock)和硬件(Real Time Clock,简称RTC)时钟。系统时钟是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的时钟,这个硬件时钟可以在BIOS中进行设置。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。
Linux中的所有命令(包括函数)都是采用的系统时钟设置。在Linux中,用于时钟查看和设置的命令主要有date、hwclock和 clock。其中,clock和hwclock用法相近,只用一个就行,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。
------------------------------------------------------------------------------------------------------
linux系统时区由EDT改为CST
EDT:指美国东部夏令时间,波士顿、纽约市、华盛顿哥伦比亚特区,都在这个时区内,跟北京时间有12小时的时差,晚12小时。
CST:可以指下面两种:
1)美国中部标准时间(西六区,-6:00),中国是东八区(+8:00),北京时间比美国中部标准时间早14个小时。3:45 PM CST 是北京时间凌晨1:45。
2)中澳大利亚标准时间(+10:30),中国是东八区(+8:00),北京时间比中澳大利亚标准时间晚2个半小时。3:45 PM CST 是北京时间下午上午5:45。
[root@db1 ~]# date
Wed Oct 25 04:23:19 EDT 2017
修改操作:
[root@db1 ~]# mv /etc/localtime /etc/localtime.bak
[root@db1 ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@db1 ~]# date
Wed Oct 25 16:25:39 CST 2017
------------------------------------------------------------------------------------------------------
同步系统时间
(1)安装ntpdate
[root@dev ~]# yum install ntpdate
(2)接着进行在线同步,选择上海交大的NTP服务器进行同步;确保网络通畅,DNS正常解析;或者使用ntpdate cn.pool.ntp.org
[root@dev ~]# ntpdate ntp.sjtu.edu.cn
10 Oct 23:02:23 ntpdate[21945]: step time server 202.120.2.100 offset -28975.130708 sec
再次查看时间,发现时间是正确的了
[root@dev ~]# date //正常显示时区应该是CST(即中国标准时间);EST是美国东部标准时间;UTC是协调世界时间/世界标准时间;GMT是格林尼治标准时间
2016年 10月 10日 星期一 23:02:35 CST
[root@dev ~]# date --set "10/10/16 23:45:52" //--set参数等于-s. (月/日/年 时:分:秒)
2016年 10月 10日 星期一 23:45:52 CST
(3)结合crontab制定定时同步系统时间(比如每一小时执行一次同步)
[root@dev ~]# crontab -e
10 * * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn > /dev/null 2>&1
设置时区
方式1:删除本地时间,并设置时区为上海
[root@dev ~]# rm -rf /etc/localtime
[root@dev ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
修改/etc/sysconfig/clock文件,修改为:
[root@dev ~]# cat /etc/sysconfig/clock
# The time zone of the system is defined by the contents of /etc/localtime.
# This file is only for evaluation by system-config-date, do not rely on its
# contents elsewhere.
ZONE="Asia/Shanghai"
UTC=false //这一行可加可不加
ARC=false //这一行可加可不加
方式2:通过tzselect调整
[root@dev ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 输入5,亚洲
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
#? 输入9,中国
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 输入1,北京时间
The following information has been given:
China
Beijing Time
Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Sun Dec 18 21:34:19 CST 2016.
Universal Time is now: Sun Dec 18 13:34:19 UTC 2016.
Is the above information OK?
1) Yes
2) No
#? 输入1,确认
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
设置硬件时间
(1)查看硬件时间
[root@dev ~]# hwclock --show
Sun 18 Dec 2016 09:38:44 PM CST -0.902813 seconds
[root@dev ~]# clock --show
Sun 18 Dec 2016 09:38:51 PM CST -0.236699 seconds
(2)修改硬件时间
[root@dev ~]# hwclock –set –date=”07/07/06 10:19″ (月/日/年 时:分:秒)
[root@dev ~]# clock –set –date=”07/07/06 10:19″ (月/日/年 时:分:秒)
(3)硬件时间和系统时间的同步
按照前面的说法,重新启动系统,硬件时间会读取系统时间,实现同步;
但是在不重新启动的时候,需要用hwclock或clock命令实现同步:
硬件时钟与系统时钟同步
[root@dev ~]# hwclock --hctosys //hc代表硬件时间,sys代表系统时间
或者
[root@dev ~]# clock --hctosys
系统时钟和硬件时钟同步
[root@dev ~]# hwclock --systohc
或者
[root@dev ~]# clock --systohc
同步BIOS时钟,强制把系统时间写入CMOS,命令如下:
[root@dev ~]# clock -w
NTP系统时间同步-操作记录的更多相关文章
- 部署Zipkin分布式性能追踪日志系统的操作记录
Zipkin是Twitter的一个开源项目,是一个致力于收集Twitter所有服务的监控数据的分布式跟踪系统,它提供了收集数据,和查询数据两大接口服务. 部署Zipkin环境的操作记录:部署Zipki ...
- 转 部署Zipkin分布式性能追踪日志系统的操作记录
2017年02月27日 11:01:29 https://blog.csdn.net/konglongaa/article/details/58016398 阅读数:7631 Zipkin是Twitt ...
- centos 6x系统下源码安装mysql操作记录
在运维工作中经常部署各种运维环境,涉及mysql数据库的安装也是时常需要的.mysql数据库安装可以选择yum在线安装,但是这种安装的mysql一般是系统自带的,版本方面可能跟需求不太匹配.可以通过源 ...
- Linux下修改系统编码的操作记录
Linux系统安装后,发现中文显示乱码.因为系统编码为en_US.UTF-8,应改为支持中文的编码(即zh_CN.UTF-8)操作记录如下:1)检查linux的系统编码检查linux的系统编码,确定系 ...
- 使用ntp从时间同步服务器更新centos系统时间的方法
CentOS系统时间同步的步骤如下: 复制代码 代码如下: cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimentpdate us.pool.ntp ...
- CentOS系统时间同步(NTP)
CentOS系统时间同步的步骤如下: 新装的CentOS系统服务器可能设置了错误的,需要调整时区并调整时间. 如下是CentOS系统使用NTP来从一个时间服务器同步把当前时区调整为上海就是+8区,想改 ...
- 记录linux系统用户shell终端操作记录
在 /etc/profile 最后添加 export HISTTIMEFORMAT='[%F %T]: ' export PROMPT_COMMAND='{ msg=$(history 1 | { r ...
- U盘启动安装系统之旅----记录自己的第一次操作
网上也有很多装系统的教程,这篇主要是对自己第一次装系统的一个记录,很惭愧,现在才尝试第一次用U盘启动装系统.经常有人说,系统都不会装,就别说搞这行的.当你会了,你就会觉得其实它真的是一件很简单的事情. ...
- CentOS下系统时间同步和时区的修改和设置(用的这个)
一.修正时区 rm -rf /etc/localtime #删除当前默认时区www.kwx.gd ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localt ...
随机推荐
- entity framework异常 The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid
ROW_NUMBER() OVER (ORDER BY (select Null)) AS Id entity framework 查询中有这句会有异常
- 高通GPIO驱动(DTS方式)
gpio调试的方式有很多,linux3.0以上ARM架构的处理器基本上都采用了DTS的方式,在linux3.0可以通过获取sysfs的方式来获取gpio状态: sysfs文件系统的建立可以参照下面的博 ...
- Django框架的使用教程--mysql数据库[三]
Django的数据库 1.在Django_test下的view.py里面model定义模型 from django.db import models # Create your models here ...
- 01LaTeX学习系列之---TeX的介绍与认识
目录 01TeX的介绍与认识 目录 前言 (一)TeX 的宣传 TeX - Beauty and Fun 1. TeX 是什么? 2. TeX 是哪家公司生产的? 3. 我们今天主角的名字怎么念啊?& ...
- @property括号内属性讲解
一.前言 一个object的属性允许其他object监督和改变他的状态.但是在一个设计良好的面向对象程序中,直接访问一个object的内部状态是不可能的.相反,存取器(getter sett ...
- JDBC lesson 1
https://www.mkyong.com/tutorials/jdbc-tutorials/ 1.jdbc基本概念 Java Database Connectivity (JDBC)是一套提供数据 ...
- 给JDK提的一个bug(关于AbstractQueuedSynchronizer.ConditionObject)
1. 背景 之前读JUC的AQS源码,读到Condition部分,我当时也写了一篇源码阅读文章--(AbstractQueuedSynchronizer源码解读--续篇之Condition)[http ...
- call()和apply()
call()和apply()方法类似,区别是,call()方法接受的是若干个参数的列表,而apply()方法接受的是一个包含多个参数的数组. 当一个函数在其主体中使用 this 关键字时,可以通过使用 ...
- React框架简介
React的基本认识 Facebook开源的一个js库,一个用来动态构建用户界面的js库 英文官网,中文官网 React的特点 Declarative(声明式编码),Component-Based(组 ...
- Windows下面安装并运行composer的步骤
在composer官网下载得到:https://getcomposer.org/download/ Composer-Setup.exe 安装时注意:安装过程中,会提示你选择php安装目录.一直到ph ...