Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步。

一、修改时区:

# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改为中国的东八区

# vi /etc/sysconfig/clock

ZONE="Asia/Shanghai"

UTC=false

ARC=false

二、配置新的时间

日期设定:

# date -s 2017/03/06

时间设定:

# date -s 18:40:00

查看硬件时间(BIOS的):

hwclock [-rw]

-r:查看现有BIOS时间,默认为-r参数

-w:将现在的linux系统时间写入BIOS中

注:当我们进行完 Linux 时间的校时后,还需要以 hwclock -w 来更新 BIOS 的时间,因为每次开机的时候,系统会重新由 BIOS 将时间读出来,所以, BIOS 才是重要的时间依据。

[root@linuxidc ~]# hwclock -r

Wed 02 Nov 2016 02:53:35 AM CST -0.632895 seconds

同步BIOS时钟,强制把系统时间写入CMOS:

# clock -w

三、实现Internet时间同步(这里可以忽略上面两步)

方法1. 开机的时候自动网络校时:

vi /etc/rc.d/rc.local

/usr/sbin/ntpdate -u 192.168.0.2 192.168.0.3 192.168.0.4; /sbin/hwclock -w

#这里几个IP是公司内部的NTP服务器

方法2. 设定计划任务

crontab格式如下:

# For details see man 4 crontabs

# Example of job definition:

# .---------------- minute (0 - 59)

# | .------------- hour (0 - 23)

# | | .---------- day of month (1 - 31)

# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...

# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * command to be executed

设定crontab计划任务自动校时:

使用命令crontab -e

crontab -e

10 5 * * * root /usr/sbin/ntpdate -u 210.72.145.44;hwclock -w

这样每天5:10自动进行网络校时,并同时更新BIOS的时间

-------------------------------------------------------------------------------

同步网络时间:输入ntpdate time.nist.gov同步网络时间

[root@linuxidc~]# ntpdate -u time.nist.gov #网络时间同步命令

13 Mar 13:39:57 ntpdate[3318]: adjust time server 216.229.0.179 offset 0.018134 sec

#出现以上信息说明同步成功#

注:如提示命令不存在,直接输入:yum install ntp -y 安装ntp软件包。

注:若不加上-u参数, 会出现以下提示:no server suitable for synchronization found

-u:从man ntpdate中可以看出-u参数可以越过防火墙与主机同步;

210.72.145.44:中国国家授时中心的官方服务器。

ntp常用服务器:

中国国家授时中心:210.72.145.44

NTP服务器(上海) :ntp.api.bz

美国:time.nist.gov

复旦:ntp.fudan.edu.cn

微软公司授时主机(美国) :time.windows.com

台警大授时中心(台湾):asia.pool.ntp.org

注:经测试中国国家授时中心与NTP上海服务器可以正常同步时间,注意需要加上-u参数越过防火墙与主机同步!

更多NTP时间服务器相关教程见以下内容:

CentOSNTP服务器安装与配置http://www.linuxidc.com/Linux/2014-01/95258.htm

教你如何快速搭建NTP时间服务器http://www.linuxidc.com/Linux/2017-02/140875.htm

搭建企业级NTP时间服务器http://www.linuxidc.com/Linux/2014-02/97205.htm

Linux下快速搭建ntp时间同步服务器http://www.linuxidc.com/Linux/2014-07/104371.htm

CentOS 6.3 下实现NTP时间服务器http://www.linuxidc.com/Linux/2014-08/105414.htm

开源软件包的安装及ntp时间服务器简析http://www.linuxidc.com/Linux/2017-02/140342.htm

Linux时间同步NTP服务的安装与配置http://www.linuxidc.com/Linux/2016-10/135945.htm

Linux系统NTP服务细节详述http://www.linuxidc.com/Linux/2017-03/141435.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141745.htm

Linux服务器同步网络时间的更多相关文章

  1. Linux服务器同步Intetnet时间

    Linux服务器同步Intetnet时间 在使用linux服务器(虚拟机)的过程中,经常会发现使用一段时间后,linux服务器的时间和我的宿主机的时间不一致,而宿主机的时间确实是internet时间, ...

  2. 【Linux】- 同步网络时间

    转自:Linux同步网络时间 Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用 ...

  3. Linux/CentOS 同步网络时间

    由于硬件的原因,机器或多或少的跟标准时间对不上,一个月的误差几秒到几分钟不等.对于服务器来说时间不准,会有很多麻烦.例如,支付的时候,无法下单,游戏无法登录等. 方法一:用 ntpdate从时间服务器 ...

  4. 【linux配置】Linux同步网络时间

    Linux同步网络时间 1.date '+%Y%M%D' 按照格式显示当前日期,结果如下: [root@LAMP ~]# date "+%Y-%m-%d %H:%M:%S" -- ...

  5. 设置linux服务器定时与时间服务器同步

    在一些大公司经常出现这样一个情况:公司或一些机关单位的内部业务系统的应用服务器以及数据都是做的多机集群部署而且基本都是linux系统,而且都是内部网,不与外网通讯的.这样经常就会出现一个情况,我发送任 ...

  6. Linux 服务器的网络配置 - 1. 查看 Linux 服务器的网络连接

    1. 查看 Linux 服务器的网络连接 1)查看主机名: liuqian@ubuntu:~$ hostname ubuntu 2)查看 ip 地址: 用 ifconfig 即可,这里介绍命令组合用法 ...

  7. NTP同步网络时间

    为什么要同步网络时间呢,这是由于树莓派没有RTC和后备电池,不能像PC机那样关机之后仍可以走时. NTP对时步骤: 1 安装ntpdate sudo apt-get install ntpdate s ...

  8. centos 同步网络时间

    centos 同步网络时间 # yum -y install ntp ntpdate # ntpdate cn.pool.ntp.org # date

  9. Linux服务器同步时间

    进行Linux服务器的时间同步是一件需要注意的事情,不然,集群中的服务器时间不同将导致许多奇怪问题发生, 如果没有安装crontab,那么,使用yum install crontabs进行安装和启动, ...

随机推荐

  1. 生物信息学练习2- Biom-format

    The Biological Observation Matrix (BIOM) format http://biom-format.org/ biom-format有两种方式安装: 1. pytho ...

  2. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

    262144K   There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...

  3. The North American Invitational Programming Contest 2018 E. Prefix Free Code

    Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...

  4. PAT Basic 1045

    1045 快速排序 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后的 N 个互不相同 ...

  5. Java POI 操作Excel(读取/写入)

    pom.xml依赖: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi< ...

  6. shiro 系列

    http://jinnianshilongnian.iteye.com/blog/2019547 shiro学习以及附带DEMO地址: http://www.sojson.com/shiro ,git ...

  7. Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up: Can

    Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follo ...

  8. NYOJ 219 An problem about date

    An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2   描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你 ...

  9. python linux安装anaconda

    步骤: 1.在清华大学镜像站中下载anaconda版本:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ https://mirrors.t ...

  10. AS创建工程结构