时间服务

NTP:Network Time Protocol
作用:用来给其他主机提供时间同步服务

NTP的配置文件
/etc/ntp.conf

NTP相关的命令
date:显示/修改系统时间
hwclock:显示/修改硬件时间
ntpdate:客户端用于修改自己的时候ntp服务器同步
ntpd:ntp服务的主程序,也是客户端用于做时间同步的工具
ntpstat:查看ntp服务状态
ntpq -p:查看详细的时间同步状态信息

ntp.conf详解
1、restrict
作用:对ntp做权限控制
格式:restrict [ip] [mask] [par]
par:
ignore:忽略所有类型的NTP连接请求
nomodify:限制客户端不能使用命令ntpc和ntpq来修改服务器端的时间
noquery:不提供NTP网络校时服务
notrap:不接受远程登录请求
notrust:不接受没有经过认证的客户端的请求
【如果没有用任何参数,那么表示不做任何限制】

案例:只允许10.220.5.0/24进行网络时间同步
restrict 10.220.5.0 mask 255.255.255.0 nomodify

案例:只允许所有主机进行网络时间同步
restrict default nomodify

2. server
作用:指定ntp服务器的地址
格式:server [ip or hostname] [perfer]

3. fudge
作用:设置时间服务器的层级
格式:fudge ip [startnum int]
例子:fudge 10.225.5.1 startnum 10
注意:fudge必须和server一块用, 而且是在server的下一行
startnum
0~15
0:表示顶级
10:通常用于给局域网主机提供时间服务

案例:将当前主机作为时间服务器

server 127.127.1.0
fudge 127.127.1.0 startnum 10
restrict 127.0.0.1
restrict 10.220.5.0 netmask 255.255.255.0

安装NTP Server(服务端 主机:10.220.5.63)

一、安装ntp

[root@ ~]# yum install ntp -y

二、修改ntp的配置文件

[root@ ~]# cp /etc/ntp.conf{,.bak}
[root@ ~]# vim /etc/ntp.conf
[root@ ~]# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
logfile /var/log/ntp/ntp.log
server 127.127.1.0
fudge 127.127.1.0 startnum
restrict 127.0.0.1
restrict 10.220.5.0 netmask 255.255.255.0

 三,创建问文件

[root@~]# mkdir /var/lib/ntp/
[root@ ~]# touch /var/lib/ntp/ntp.log

四、启动服务(centos7)

[root@ ~]# systemctl start ntpd
[root@~]# systemctl enable ntpd <<<开机自启

五、查看ntp的状态(第一种方法)

[root@ ~]# ntpstat
synchronised to local net at stratum
time correct to within ms
polling server every s
注意:synchronised:表示时间同步完成(ntp可以正常工作了) unsynchronised:表示时间同步尚未完成 (如果第一次启动查看状态是
unsynchronised,需要等几分钟,再次查看状态)

 第二种方法

[root@ ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL() .LOCL. l 0.000 0.000 0.000

参数说明:

*:表示当前主机当做上游服务器工作
+:表示当前主机当做备用服务器
.LOCL.:表示基于当前主机做时间服务的
ip :表示上游服务器的地址
when:表示几秒钟前做过时间同步
poll:表示下一次同步在几秒之后
reach :表示向上游服务器发送请求的次数
delay表示传输报文时间延迟
offset: 表示延迟补偿
jitter:表示系统时间和软件时间差

六,关闭防火墙

[root@ ~]# systemctl stop firewalld
[root@~]# systemctl disable firewalld

安装NTP client(10.220.5.64)

一、安装

[root@~]# yum install ntp ntpdate -y

二、修改ntp的配置文件

[root@ ~]# vim /etc/ntp.conf

server 10.220.5.63 <<<服务端ip
fudge 10.220.5.1 startnum 10
restrict 127.0.0.1
statsdir /var/log/ntp
logfile /var/log/ntp/ntp.log

三、创建日志文件

[root@64r ~]# mkdir /var/log/ntp
[root@64r ~]#touch /var/log/ntp/ntp.log

四、关闭防火墙

同上

五、先执行一次ntpdate时间同步

[root@ ~]# ntpdate 10.220.5.63
May :: ntpdate[]: the NTP socket is in use, exiting

六、启动ntpd

[root@~]# systemctl start ntpd

七、检查状态

[root@ ~]# ntpstat
synchronised to NTP server (10.220.5.63) at stratum
time correct to within ms
polling server every s 表示同步完成

######################################

实现客户端的时间同步

基于ntpdate
方案:cron+ntpdate
优点:
实现简单
缺点:
会导致客户端的时间不连续,对于数据库业务影响是比较大,生产环境尽量不要用

基于ntpd
方案:
ntpdate+ntpd
优点:
可以实现顺滑的时间同步
缺点:
时间同步往往不会立刻完成
ntpd
要求该ntpd节点和上游服务器的时间相差不同太大

#############################################

 

 

NTP时间服务的更多相关文章

  1. ntp时间服务同步

    第一种方式:同步到网络时间服务器 # ntpdate time.windows.com将硬件时间设置为当前系统时间. #hwclock –w 加入crontab: 30 8 * * * root /u ...

  2. syslog日志系统

    目前,linux依旧使用syslogd作为日志监控进程,而在主流的linux发行版中依旧使用sysklog这个比较老的日志服务器套件.从前一篇日志可以看到,对其进行必要的配置能减少很多麻烦,并且可更有 ...

  3. linux同步windows的时间

    找了很多的资料,都没有windows做时间服务,linux同步windows的时间的,最后自己找了一些软件,终于搞定了,写出来给大家共享,以免大家多走弯路 首先在http://www.meinberg ...

  4. openstack-ocata-环境准备1

    Openstack环境准备1. 最少两台机器2. Controller:1核cpu 4G内存 5G硬盘3. Computer:1核cpu 2G内存 10G硬盘4. 至少两个网卡,本次采用四个网卡(1网 ...

  5. Hadoop异常总结

    版权声明:本文为yunshuxueyuan原创文章.如需转载请标明出处:http://www.cnblogs.com/sxt-zkys/QQ技术交流群:299142667 Hadoop异常总结 had ...

  6. Centos7基本命令

    shell基本命令 linux命令行的组成结构 linux系统命令操作语法格式 命令 空格 参数 空格 文件路径或者需要处理的内容 rm   -rf   /tmp/* ls   -la   /home ...

  7. OpenStack Train版 简单部署流程

    environment 1.网络平面 management(管理网络)→软件安装,组件通信 provider(提供实例网络)→:提供者网络:直接获取ip地址,实例之间直接互通   自服务网络(私有网络 ...

  8. 搭建Ceph分布式存储

    环境: 系统 IP地址 主机名(登录用户) 承载角色 Centos 7.4 64Bit 1611 10.199.100.170 dlp(yzyu) ceph-client(root) admin-no ...

  9. k8s环境部署(一)

    环境介绍 1.单masrer节点 (安装下面图中介绍的四个组件) 2.俩个node节点(安装kubelet和docker) 3.为了支持master与node之前的通信,我们还需要在master上安装 ...

随机推荐

  1. layui select 选完其他选项, 手工清空选项 又恢复最初的选项?

    启用layui的select  下拉搜索项: lay-search <div class="layui-inline"> <label class="l ...

  2. Python 标准库笔记(1) — String模块

    原文出处: j_hao104 String模块包含大量实用常量和类,以及一些过时的遗留功能,并还可用作字符串操作. 1. 常用方法 常用方法 描述 str.capitalize() 把字符串的首字母大 ...

  3. html限制文本框只能输入数字和一个小数点

    近期在做一个前台页面,有一个文本框是用来输入充值金额的,就想到了限制用户只能输入纯数字的数据且只能包含一个小数点.下面就是我实现的代码 $(function() { //阻止数字键以外的按键输入 $( ...

  4. 使用xheditor时 cloneRange错误 ext.net

    使用ext.net 加  xheditor时,一直报 cloneRange错误. 于是 按照说明但独使用xheditor  ,检查无错,正常使用, 因此排除版本问题. <ext:panel ru ...

  5. python-实现3级菜单(作业课)

    #任务: #显示3级菜单 #1级菜单#显示 3个城市 => 1北京 2上海 3广州 #2级菜单 #显示 选择1 北京 => B1 B2 B3 #2级菜单 #显示 选择2 上海 => ...

  6. nginx1.14.0版本server、location、rewrite配置

    server配置demo 在192.168.10.140(centos7)上修改: /home/program/nginx/conf/nginx.conf 添加一个server server { li ...

  7. selenium 目录结构解释

    common目录         定义了通用的异常类 webdriver目录 android.backberry.chrome.edge.firefox.ie.opera.phantomjs.safa ...

  8. [UE4]Add Offset

    在原来值的基础上增加偏移

  9. C++调用JS函数

    1 调用方法 https://blog.csdn.net/donglinshengan/article/details/29828103 https://blog.csdn.net/sunmz_wjx ...

  10. C# Winform开发程序调用VLC播放器控件播放视频.

    VLC是个好东西,支持的格式多,还无广告,关键还有调用它的播放控件不用安装. 开个文章记录下调用这个控件的流水账,以便以后需要的时候查阅 创建工程 首先新建一个Winform工程. 这里姑且叫做VLC ...