时间服务器:

NTP(Network Time Protocol,网络时间协议)是用来使用网络中的各个计算机时间同步的一种协议,NTP服务器就是利用NTP协议提供时间同步服务的。

一、环境准备:

1、配置计算机IP:

Centos 7系统上配置NTP时钟服务器:

时钟服务器:192.168.13.131

客户端同步服务器:192.168.13.132

2、查看两台机器是否安装NTP包:

[root@ntp-server ~]# rpm -qa | grep ntp

ntpdate-4.2.6p5-25.el7.centos.x86_64

ntp-4.2.6p5-25.el7.centos.x86_64

这样输出表明已经安装好,如果没有可以使用“yum -y install ntp ntpdate”进行安装

3、查看当前服务器时区&列出时区并设置时区:

[root@ntp-server ~]# timedatectl

[root@ntp-server ~]# timedatectl list-timezones

[root@ntp-server ~]# timedatectl set-timezone Asia/Shanghai

4、时间时区概念理解:

GMT   UTC    CST    DST

UTC:整个地球分为二十四个时区,每个时区都有自己的本地时间,在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时。

GMT:格林威治标准时间:指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线(UTC与GMT时间基本相同)

CST:中国标准时间

GMT+8=UTC+8=CST

DST:夏令时指在夏天太阳升起的比较早时,将时间拨快一小时,以提早日光时间(中国不适用)

5、使用NTP公共服务器池同步的服务器时间(http://www.pool.ntp.org

6、NTP配置文件

修改NTP配置文件:

vim /etc/ntp.conf

添加NTP服务的日志目录:

4 driftfile /var/lib/ntp/drift

5

6 logfile /var/log/ntpd.log

设置授权198.168.13.0/24网段上的所有机器都可以从这台机器上查询和同步时间。

15 restrict 127.0.0.1

16 restrict ::1

17 restrict 192.168.13.0 mask 255.255.255.0 nomodify notrap

设置时间服务器列表:

 24 server 0.centos.pool.ntp.org iburst(系统默认的,可以注释)

 25 server 1.centos.pool.ntp.org iburst

 26 server 2.centos.pool.ntp.org iburst

 27 server 3.centos.pool.ntp.org iburst

当外部时间不可用时,使用本地时间:

 29 server 192.168.13.131 iburst(无上层时间时配置为:server 127.127.1.0

 30 fudge 127.127.1.0 stratum 11

设置允许上层时间服务器主动修改本机时间:

37 #manycastclient 239.255.254.254 autokey # manycast client

38

 39 restrict 0.centos.pool.ntp.org nomodify notrap noquery

 40 restrict 1.centos.pool.ntp.org nomodify notrap noquery

 41 restrict 2.centos.pool.ntp.org nomodify notrap noquery

 42 restrict 3.centos.pool.ntp.org nomodify notrap noquery

7、设置开启自启动:

[root@ntp-server ~]# systemctl enable ntpd

[root@ntp-server ~]# systemctl enable ntpdate

[root@ntp-server ~]# systemctl is-enabled ntpd

手动修改服务器时间时:

[root@ntp-server ~]# timedatectl set-ntp no

[root@ntp-server ~]# timedatectl set-time 10:00:00

8、查看服务器硬件时间:

[root@ntp-server ~]# hwclock

硬件时钟与系统时钟同步:

# hwclock --hctosys 或者 # clock --hctosys  hc代表硬件时间,sys代表系统时间,即用硬件时钟同步系统时钟

系统时钟和硬件时钟同步:

# hwclock --systohc或者# clock --systohc  即用系统时钟同步硬件时钟

9、服务端重启NTP服务:

[root@ntp-server ~]# systemctl restart ntpdate

二、客户端配置ntp:

1、通过ntpd方式同步时间

vim /etc/ntp.conf

server 192.168.13.131

fudge 127.127.1.0 stratum 11         #这里必须是11,因为不是顶级的

[root@ntp-client ~]# ntpq -np                  #通过配置ntp配置文件,完成自动时间同步

remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

192.168.13.131  LOCAL(0)        12 u   12   64    1    0.432    2.574   0.000

2、通过ntpdate方式同步时间

[root@ntp-client ~]# ntpdate 192.168.13.131          #手动NTP同步时间

[root@ntp-client ~]# crontab -e                                    #通过定时任务完成同步

0 0 * * * /usr/sbin/sntp -P no -r 192.168.13.131;hwclock -w

四、命令解析:

一、ntpq

1、简介:

ntpq是查询ntpd工作状态的命令,一般使用“ntpq -np”参数

二、ntpdate

1、简介:

ntpdate通过轮询指定为服务器参数的网络时间协议(NTP)服务器来设置本地日期和时间,从而确定正确的时间,在使用ntpdate同步时间时,需要保证ntpd服务处于关闭状态。

2、使用条件:

root身份

ntpd未运行(ntpd运行时占用udp123端口)

3、常用方法:

ntpdate -d ip

debug模式,查询与服务器的时差,状态。ip是指时间服务器的IP地址

ntpdate ip

与服务器同步本地系统时间

三、hwclock

1、简介:

是一个硬件时钟访问工具,它可以显示当前时间、设置硬件时钟的时间和设置硬件时钟为系统时间,也可设置系统时间为硬件时钟的时间。

在Linux中有硬件时钟与系统时钟等两种时钟。硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。当linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。所有linux相关指令与函数都是读取系统时钟的设定。

2、选项:

--adjust:hwclock每次更改硬件时钟时,都会记录在/etc/adjtime文件中。使用--adjust参数,可使hwclock根据先前的记录来估算硬件时钟的偏差,并用来校正目前的硬件时钟;
--debug:显示hwclock执行时详细的信息;
--directisa:hwclock预设从/dev/rtc设备来存取硬件时钟。若无法存取时,可用此参数直接以I/O指令来存取硬件时钟;
--hctosys:将系统时钟调整为与目前的硬件时钟一致;
--set --date=<日期与时间>:设定硬件时钟;
--show:显示硬件时钟的时间与日期;
--systohc:将硬件时钟调整为与目前的系统时钟一致;
--test:仅测试程序,而不会实际更改硬件时钟;
--utc:若要使用格林威治时间,请加入此参数,hwclock会执行转换的工作;
--version:显示版本信息。

centos配置NTP服务器的更多相关文章

  1. Linux配置NTP服务器,时间同步

    当服务器多了,时间准确与否,一致与否是个大问题.虽然这个问题总是被忽略,但是统一一致的时间是很有必要的.下面说一下在局域网内配置Linux时间服务器的方法. 配置的环境及要求: 假设在192.168. ...

  2. 95、配置ntp服务器

    95.1.ntp简介: ntp服务使用的是udp的123端口,如果开启了防火墙要记得放开这个端口: NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步 ...

  3. 日常工作问题解决:配置NTP服务器以及一些常见错误解决

    1.配置NTP服务端 环境:redhat 6.5 服务器主机名 ip地址 说明 server 192.168.57.20 NTP服务端 client 192.168.57.21 NTP客户端 搭建说明 ...

  4. centos 配置NFS服务器

    转载:http://boloveyo.blog.163.com/blog/static/203926187201232383956558/ 系统是CentOS5.6,假设NFS Server IP为1 ...

  5. 【原创】Centos配置turn服务器

    使用ssh工具,进入命令行,安装下面的就是可以配置turn-server(coturn) 转请注明出处. 1.安装centos必须的库文件      yum install -y make gcc c ...

  6. CentOS配置SVN服务器

    系统环境:CentOS系统:CentOS 6.5 1.检查是否安装了低版本的SVN rpm -qa subversion 2.卸载旧版本SVN yum remove subversion 3.安装SV ...

  7. linux centos 配置 svn 服务器

    首先介绍一下吧,Subversion(SVN) 是一个开源的版本控制系統, 也就是说 Subversion 管理着随时间改变的数据. 这些数据放置在一个中央资料档案库 (repository) 中.  ...

  8. CentOS配置LDAP服务器

    环境:centos 5.8 安装: 1.yum安装oepnldap.openldap-servers.openldap-clients.openldap-devel [root@hao-linux ~ ...

  9. CentOS配置DHCP服务器

    知识储备 bootp (boot protocol) 早前用于无盘工作站,dhcp的前身 IP初次分配完成,以后固定mac和IP绑定关系 dhcp基础 获取IP步骤 step1: Client dhc ...

随机推荐

  1. 【Leetcode】【Medium】Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  2. MEGER sentence in oracle

    MEGE Sentence This oracle tutorial explains how to use the oralce MEGER sentence with syntax and sam ...

  3. 使用websploit在局域网全自动渗透

    原理为 websploit调用dnsdpoof进行dns欺骗配合神器metasploit的web_autopwn模块进行渗透:特点:过程基本全自动. 终端输入websploit打开websploit: ...

  4. 记两个std接口equal_range,set_difference

    1.equal_range equal_range是C++ STL中的一种二分查找的算法,试图在已排序的[first,last)中寻找value,它返回一对迭代器i和j,其中i是在不破坏次序的前提下, ...

  5. PhoneGap 的文件 api

    一. 文件系统的请求 请求文件系统通过 window.requestFileSystem 来完函数声明如下: window.requestFileSystem(type, size, successC ...

  6. #20145238荆玉茗《网络对抗》-逆向及Bof进阶实践

    20145238荆玉茗<网络对抗>-逆向及Bof进阶实践 实践目的:注入shellcode 准备一段shellcode代码 Shellcode实际是一段代码(也可以是填充数据),是用来发送 ...

  7. Windows环境下ELK简单搭建记录

    前言 ELK已经是一套成熟的日志解决方案,虽然出现了好久,今日才终于研究了一下,不过是在windows平台上安装的. 搭建步骤 下载软件 安装软件 修改配置文件 启动软件 集成测试 下载软件 首先从官 ...

  8. ASP.NET Web API编程——使用Odata

    路由配置 routePrefix路由前缀,必须含有Odata字符串,否则路由不到Odata控制器. V1表示版本,可以使用这种方式进行版本控制,也可以使用其他方式. config.Count().Fi ...

  9. Visual C++中MFC消息的分类

    Visual C++中MFC消息的分为三类:标准(窗口)消息.命令消息.控件消息. 1.标准(窗口)消息:窗口消息一般与窗口内部运作有关,如创建窗口,绘制窗口,销毁窗口,通常,消息是从系统发到窗口,或 ...

  10. 关于Queue的相关问题

    在多线程中使用Queue,发现总是有莫名的问题, 经折腾好久之后发现是因为没有加锁! 以下测试代码中, 如果不加锁, 添加 100W对象, 可能只会成功50W, 然后并不会产生异常! );//(如果初 ...