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 ...
随机推荐
- Android中SELinux的TE简介【转】
转自:https://blog.csdn.net/murphykwu/article/details/52457667 selinux的概念如上一篇链接所示: http://www.cnblogs.c ...
- JavaWeb后台购物车类的具体实现
相信大家肯定都在电商网站买过东西,当我们看中一件喜欢又想买的东西时,这时候你又不想这么快结账,这时候你就可以放入购物车: 就像我们平时去超市买东西一样,会推着购物车去买东西: 那么我们接下来看看jav ...
- 团队Alpha博客链接目录
Dipper团队Alpha博客链接目录 团队Alpha冲刺博客 第一次冲刺 第二次冲刺 第三次冲刺 第四次冲刺 第五次冲刺 第六次冲刺 第七次冲刺 第八次冲刺 第九次冲刺 第十次冲刺 第十一次冲刺 第 ...
- 控件_DatePicker
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view ...
- 寒假集训——搜索 B - Sudoku
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream&g ...
- BZOJ1023:[SHOI2008]cactus仙人掌图(圆方树,DP,单调队列)
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus). 所谓简单回路就是指在图上不重复经过任何一个顶点 ...
- Semaphore实现的生产者消费者程序
Semaphore:Semaphores are often used to restrict the number of threads than can access some (physical ...
- 很好的一篇eureka的讲解文章
文章地址 http://nobodyiam.com/2016/06/25/dive-into-eureka/
- Springboot入门程序
springboot简化之前的很多xml文件,不需要大量配置xml文件,没有很多xml文件是多么的愉快 下面进入正题,演示简单的入门程序,虽然简单,但足以振奋初学者们 我新建的工程名叫hello,大家 ...
- centos7之docker安装
下午四点左右,我准备接触docker这个技术.之所以接触它,原因来自tomcat服务器老是挂,也不能说老是挂,一周一次吧,或者不定时,最初出现的问题,分为这么几类? 一类,java代码的问题,某个类导 ...