一。查看配置

查看时区列表: timedatectl list-timezones|grep Asia
查看当前时间: date
查看当前设置:
[root@localhost ~]# timedatectl
Local time: Mon 2017-10-09 16:44:08 CST
Universal time: Mon 2017-10-09 08:44:08 UTC
RTC time: Mon 2017-10-09 08:44:08
Time zone: Asia/Shanghai (CST, +0800)      #已设置为上海时区
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

二。进行配置
部署ntp服务端 yum install ntp -y

编辑ntp的配置文件vi /etc/ntp.conf (日志文件默认在/var/log/messages中),添加以下几个服务器域名,有些服务默认自带,无需添加一下参数
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

设置中国时区: timedatectl set-timezone Asia/Shanghai    #执行完后时间还需要重启ntpd服务

systemctl restart ntpd
systemctl enable ntpd

到这里就配置好了,需要注意的是。执行完一下命令后并不是立刻就改好时间了,大概需要半分钟才能生效

补充:

  为了让效果更明显,把服务器修改为纽约时区,另一台需要同步的linux客户端的时区修改为非洲时间,结果导致,客户端ntpdate之后没有同步,后来才发现,需要在同一时区内才能同步时间,也就是说,服务端和客户端的时区必须在中国这个时区内才可以

下面来测试我们的ntp服务器配置有没有成功
在服务器端(ip:10.0.3.66)上   
使用date -s 23:30:30 (时间可以随便改,反正改一个跟客户端时间不一样的就可以了),然后date可以看到时间变成了23:30:30
在客户端上
ntpdate 10.0.3.66 执行后发现,时间也变成了23:30:30

如果时间没有同步或报错,可以试着把防火墙关掉

让人无语的是我在centos6.5的最小化安装的系统上,timedatectl命令用不了,也不知道怎么安装,但是又想看一下当前系统的时区是哪个,有没有配置正常?对于这种情况,我们可以简单的使用date -R来查看时区,当然这样看到的时区是数字时区,而不是英文时区。如果你初中的地理课没白上,就应该记得北京时间是东八区的时间,看到后面是+0800就表示当前系统时区是东八区时间
那么问题又来了,我们又该如何设置系统时区为东八区呢?
执行命令cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ,执行完这条命令后,就设置好时区了
再date -R查看时区,可以看到时区恢复正常

[root@localhost ~]# date
Mon Oct 16 21:59:20 EDT 2017
[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite `/etc/localtime'? y
[root@localhost ~]# date
Tue Oct 17 09:59:41 CST 2017
[root@localhost ~]# date -R
Tue, 17 Oct 2017 09:59:45 +0800
[root@localhost ~]# 启动ntp服务,如果date没有显示正常,那么再重启ntp服务应该就可以了

Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间的更多相关文章

  1. CentOS7部署ntp服务器

    主机 角色 192.168.48.128 Server 192.168.48.129 Client 192.168.48.130 Client 所有主机安装ntp服务 yum install -y n ...

  2. ntp服务器同步时间详细配置

    部署NTP服务器进行时间同步   NTP服务端:linl_S    IP:10.0.0.15 NTP客户端:lin_C    IP:10.0.0.16 NTP服务概述 1.原理 NTP(Network ...

  3. centos6 & centos7搭建ntp服务器

    原理 NTP(Network TimeProtocol,网络时间协议)是用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1 ...

  4. CentOS 7.2部署NTP服务器实现时间同步

    CentOS 7.2部署NTP服务器实现时间同步 [日期:2017-12-18] 来源:Linux社区  作者:梁明远 [字体:大 中 小]   1. 前言 对于容器编排系统,前段时间主要研究kube ...

  5. CentOS7搭建NTP服务器及客户端同步时间

    一.服务器配置 1.查看服务器.客户端操作系统版本 [root@hadoop101 ~]# cat /etc/redhat-release CentOS Linux release (Core) 2. ...

  6. 【ntp】centos7下ntp服务器设置

    安装ntp #检查服务是否安装 rpm -q ntp #安装ntp服务器 yum -y install ntp 修改配置文件:/etc/ntp.conf 内容如下: restrict default ...

  7. 部署NTP服务器进行时间同步

    NTP服务端:linl_S    IP:10.0.0.15 NTP客户端:lin_C    IP:10.0.0.16 NTP服务概述 1.原理 NTP(Network TimeProtocol,网络时 ...

  8. linux篇-CentOS7搭建NTP服务器

    1查看服务器.客户端操作系统版本 2查看服务器是否安装ntp 3如果没有安装 4安装完成后重新查看服务器是否安装ntp 5查看ntp服务器状态 6修改配置文件 注释 #server 0.centos. ...

  9. 云服务器Centos7部署Tomcat服务器

    目录 部署Tomcat服务器 1.安装JDK1.8 2.安装与启动tomcat 配置安全组(8080端口) 参考文章 部署Tomcat服务器 1.安装JDK1.8 JDK下载地址:https://ww ...

随机推荐

  1. Integer与int的区别(转)

    如果面试官问Integer与int的区别:估计大多数人只会说道两点,Ingeter是int的包装类,int的初值为0,Ingeter的初值为null.但是如果面试官再问一下Integer i = 1; ...

  2. Linux命令----uname查看系统信息

    uname就是UNIXname的缩写 1.uname可以查询操作系统信息 [root@yuan ~]# uname Linux 2.uname -n显示系统的主机名 [root@yuan ~]# un ...

  3. 打开和写入excel文件

    一.使用win32读取excel内容 # -*- coding: utf-8 -*- from win32com import client as wc def open_excel(): excel ...

  4. python笔记4-if..elif-else条件语句

    python中条件判断使用if else来判断,多分支的话使用if elif ... else,也就是如果怎么怎么样就怎么怎么样,否则就怎么怎么这样,格式如下: #if是布尔类型判断,1个是真1个是假 ...

  5. StringUtils方法介绍

    引用StringUtils方法全集介绍 C标准中空白字符有:空格(‘ ’).换页(‘\f’).换行(‘\n’).回车(‘\r’).水平制表符(‘\t’).垂直制表符(‘\v’)六个.

  6. 使用keytool生成公钥、私钥、证书并且读取出来,使用私钥签名jar并验证(转)

    参考链接:http://happyqing.iteye.com/blog/2139504 :https://blog.csdn.net/arjelarxfc/article/details/52461 ...

  7. iframe 常见问题 解析

    1. jquery在iframe子页面获取父页面元素代码如下: $("#objid",parent.document) 2. jquery在父页面获取iframe子页面的元素代码如 ...

  8. <Spark><Programming><Key/Value Pairs><RDD>

    Working with key/value Pairs Motivation Pair RDDs are a useful building block in many programs, as t ...

  9. Delphi 10.3.1拍照遇到的问题

    procedure TAddOrderCamera.CameraActionExecute(Sender: TObject); var Service: IFMXCameraService; Para ...

  10. 性能测试-10.数据分析Analysis

    Analysis Summary 平均响应时间(Average TransactionResponse Time) 每秒响应数(Transactions per Second) 1.Vuser  Ru ...