centos6.5安装配置NTP,集群各机器间时间同步
试验环境
>>提君博客原创 http://www.cnblogs.com/tijun/ <<
IP | 主机名 | 角色 | 描述 | 同步方式 |
192.168.11.11 | ltt1.bg.cn |
NTPD服务 |
1、负责与外部公共NTPD服务同步标准时间 2、作为内外网络的NTPD服务 |
NTPD服务平滑同步 |
192.168.11.12 | ltt2.bg.cn | 内外NTP客户端 | 内网设备与192.168.11.11同步时间 | NTPD服务平滑同步 |
192.168.11.13 | ltt3.bg.cn | 内外NTP客户端 | 内网设备与192.168.11.11同步时间 | NTPD服务平滑同步 |
192.168.11.14 | ltt4.bg.cn | 内外NTP客户端 | 内网设备与192.168.11.11同步时间 | NTPD服务平滑同步 |
192.168.11.15 | ltt5.bg.cn | 内外NTP客户端 | 内网设备与192.168.11.11同步时间 | NTPD服务平滑同步 |
第一步,以上所有的机器都安装ntp
[root@ltt1 ~]# yum install ntp
第二步,设置开机自启动
[root@ltt1 conf]# chkconfig ntpd on
[root@ltt1 conf]# chkconfig --list ntpd
ntpd :off :off :on :on :on :on :off
第一、第二,以上两步,在各机器上都要执行
第三步,配置内网NTP-server(192.168.11.11)
此步是在你要设置成NTP服务的机器上配置,它将给内网所有的机器进行授时,即内网所有机器都是以它的时间为准。
我这里选择的是192.168.11.11。
先使用ntpdate手动同步下内网中作为 NTPD 服务器的时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。即在 192.168.11.11 上执行
ntpdate -u 1.cn.pool.ntp.org
然后要找到可以正常提供时间服务的外部主机,执行以下命令
[root@ltt1 ~]# ntpdate -q .cn.pool.ntp.org
server 51.15.41.135, stratum , offset -0.648578, delay 0.37547
server 193.228.143.12, stratum , offset -0.652907, delay 0.36064
server 202.118.1.130, stratum , offset -0.650668, delay 0.05075
server 120.25.115.20, stratum , offset -0.650029, delay 0.06900
Sep :: ntpdate[]: step time server 202.118.1.130 offset -0.650668 sec
这里可以看到列出了四个外部主机,以及和本机时间的时间差异。
最后一行的末尾,time server 202.118.1.130 offset -0.650668 sec,这说明时间差异最小的一个外部主机为202.118.1.130
必要的信息已经获取,现在正是开始配置NTP
[root@ltt1 ~]# vi /etc/ntp.conf
这里列出的只是注释掉内容和添加的内容,
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#设置对内网主机提供NTP服务。我的集群网关是192.168.11.2
restrict 192.168.11.2 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#注释掉centos默认的对时服务器,如果主机能访问外网,最好做这一步
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#指定上层对时的外部服务器,这些都是上面刚刚得到的可以正常提供时间服务的外部主机
server 51.15.41.135
server 193.228.143.12
server 202.118.1.130 perfer
server 120.25.115.20
#修改上层服务器对本机的权限
restrict 51.15.41.135 nomodify notrap noquery
restrict 193.228.143.12 nomodify notrap noquery
restrict 202.118.1.130 nomodify notrap noquery
restrict 120.25.115.20 nomodify notrap noquery
#外部时间服务器不可用时,设置以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum
第四步,同步硬件时间
在 Linux 下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了,那么既然两个时钟独自运行,那么时间久了必然就会产生误差了,而 NTP 默认又只更新系统时间,因此我们需要设置硬件时钟进行同步调整
[root@ltt1 ~]# vi /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
第五步,启动ntp服务,查看相关状态,验证
>>提君博客原创 http://www.cnblogs.com/tijun/ <<
[root@ltt1 ~]# service ntpd start
Starting ntpd: [ OK ]
查看服务连接和监听
[root@ltt1 ~]# netstat -tlunp | grep ntp
udp 192.168.11.11: 0.0.0.0:* /ntpd
udp 127.0.0.1: 0.0.0.0:* /ntpd
udp 0.0.0.0: 0.0.0.0:* /ntpd
udp fe80::20c:29ff:fec5:88c5: :::* /ntpd
udp ::: :::* /ntpd
udp ::: :::* /ntpd
查看网络中的NTP服务器,同时显示客户端和每个服务器的关系
[root@ltt1 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+ntp3.itcomplian 5.103.128.88 u 446.548 -700.47 1.006
ntp1.flashdance 193.11.166.20 u 432.794 -705.08 12.690
*202.118.1.130 202.118.1.47 u 24.599 -653.77 1.470
120.25.115.20 10.137.38.86 u 42.456 -651.64 1.038
LOCAL() .LOCL. l 0.000 0.000 0.000
查看时间同步状态
[root@ltt1 ~]# ntpstat
synchronised to NTP server (202.118.1.130) at stratum
time correct to within ms
polling server every s
第六步,配置NTP-client,这是在除192.168.11.11的其他机器上进行
[root@ltt2 ~]# vi /etc/ntp.conf
注意,这里的配置是和192.168.11.11有区别的
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap # Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst #对时服务器,配置成ntp-server的机器
server 192.168.11.11
restrict 192.168.11.11 nomodify notrap noquery server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum
配置同步硬件时间
[root@ltt2 ~]# vi /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
第七步,启动ntp-client,手动更新时间,查看相关状态,验证,这里以ltt2为例
[root@ltt2 ~]# service ntpd start
Starting ntpd: [ OK ]
手动向192.168.11.11更新一次时间
ntpdate -u 192.168.11.11
查看服务连接和监听
[root@ltt2 ~]# netstat -tlunp | grep ntp
udp 192.168.11.12: 0.0.0.0:* /ntpd
udp 127.0.0.1: 0.0.0.0:* /ntpd
udp 0.0.0.0: 0.0.0.0:* /ntpd
udp ::: :::* /ntpd
udp fe80::20c:29ff:fef9:26cb: :::* /ntpd
udp ::: :::* /ntpd
查看网络中的NTP服务器,同时显示客户端和每个服务器的关系
[root@ltt2 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ltt1.bg.cn 202.118.1.130 u 1.184 0.242 1.190
LOCAL() .LOCL. l 14h 0.000 0.000 0.000
查看时间同步状态
>>提君博客原创 http://www.cnblogs.com/tijun/ <<
[root@ltt2 ~]# ntpstat
synchronised to NTP server (192.168.11.11) at stratum
time correct to within ms
polling server every s
到此,机器的同步时间就配置完成了。
附:ntpq -p指令,显示的各项含义
位置 | 标志 | 含义 |
符号 | * | 响应的NTP服务器和最精确的服务器 |
+ | 响应这个查询请求的NTP服务器 | |
blank(空格) | 没有响应的NTP服务器 | |
标题 | remote | 响应这个请求的NTP服务器的名称 |
refid | NTP服务器使用的更高一级服务器的名称 | |
st | 正在响应请求的NTP服务器的级别 | |
when | 上一次成功请求之后到现在的秒数 | |
poll | 本地和远程服务器多少时间进行一次同步,单位秒,在一开始运行NTP的时候这个poll值会比较小,服务器同步的频率大,可以尽快调整到正确的时间范围,之后poll值会逐渐增大,同步的频率也就会相应减小 | |
reach | 用来测试能否和服务器连接,是一个八进制值,每成功连接一次它的值就会增加 | |
delay | 从本地机发送同步要求到ntp服务器的往返时间 | |
offset | 主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒,offset越接近于0,主机和ntp服务器的时间越接近 | |
jitter | 统计了在特定个连续的连接数里offset的分布情况。简单地说这个数值的绝对值越小,主机的时间就越精确 |
>>提君博客原创 http://www.cnblogs.com/tijun/ <<
centos6.5安装配置NTP,集群各机器间时间同步的更多相关文章
- Linux中安装配置spark集群
一. Spark简介 Spark是一个通用的并行计算框架,由UCBerkeley的AMP实验室开发.Spark基于map reduce 算法模式实现的分布式计算,拥有Hadoop MapReduce所 ...
- Linux中安装配置hadoop集群
一. 简介 参考了网上许多教程,最终把hadoop在ubuntu14.04中安装配置成功.下面就把详细的安装步骤叙述一下.我所使用的环境:两台ubuntu 14.04 64位的台式机,hadoop选择 ...
- 配置NTP集群时间同步(二)
[root@hadoop1 bin]# rpm -qa|grep ntp 没有的话用yum -y install ntp安装(要记着每台机器上都要安装) [root@hadoop1 bin]# vi ...
- hadoop集群环境搭建之安装配置hadoop集群
在安装hadoop集群之前,需要先进行zookeeper的安装,请参照hadoop集群环境搭建之zookeeper集群的安装部署 1 将hadoop安装包解压到 /itcast/ (如果没有这个目录 ...
- 架构(三)MongoDB安装配置以及集群搭建
一 安装 1.1 下载MongoDB 我个人不太喜欢用wget url, 之前出现过wget下载的包有问题的情况 https://fastdl.mongodb.org/linux/mongodb-li ...
- 安装配置Spark集群
首先准备3台电脑或虚拟机,分别是Master,Worker1,Worker2,安装操作系统(本文中使用CentOS7). 1.配置集群,以下步骤在Master机器上执行 1.1.关闭防火墙:syste ...
- 离线环境下使用二进制方式安装配置Kubernetes集群
本文环境 Redhat Linux 7.3,操作系统采用的最小安装方式. Kubernetes的版本为 V1.10. Docker版本为18.03.1-ce. etcd 版本为 V3.3.8. 1. ...
- Hadoop2.2集群安装配置-Spark集群安装部署
配置安装Hadoop2.2.0 部署spark 1.0的流程 一.环境描写叙述 本实验在一台Windows7-64下安装Vmware.在Vmware里安装两虚拟机分别例如以下 主机名spark1(19 ...
- CentOS7安装配置redis5集群
一.服务器准备 本文准备了3台服务器 , 分别是 172.18.0.231 172.18.0.232 172.18.0.233 每台运行2个redis实例, 端口分别为7000 7001 ,即总共6个 ...
随机推荐
- postgresql 按日期范围查询
Timestamp without timezone 方法一: select * from user_info where create_date >= '2015-07-01' and cre ...
- C#反射の一个泛型反射实现的网络请求框架
点击下载源码 C#反射の反射详解(点击跳转)C#反射の反射接口(点击跳转)C#反射反射泛型接口(点击跳转)C#反射の一个泛型反射实现的网络请求框架(点击跳转)
- [AH2017/HNOI2017]影魔
嘟嘟嘟 这题真的挺神的,我是真没想出来. 洛谷的第一篇题解说的非常妙,实在是佩服. 就是我们首先预处理出对于第\(i\)个数,在\(i\)左边比第一个比\(i\)大的数\(l_i\),在\(i\)右边 ...
- 转://使用insert插入大量数据的总结
使用insert插入大量数据的个人经验总结在很多时候,我们会需要对一个表进行插入大量的数据,并且希望在尽可能短的时间内完成该工作,这里,和大家分享下我平时在做大量数据insert的一些经验. 前提:在 ...
- ①---Java开发环境配置
Java 开发环境配置 以下将为大家介绍如何搭建Java开发环境. window系统安装java 下载JDK 首先我们需要下载java开发工具包JDK,下载地址:http://www.oracle.c ...
- direct path read temp的处理方法
Examine the SQL statement currently being run by the session experiencing waits to see what is causi ...
- Spring Security(二):一、Preface(前言)
Spring Security is a powerful and highly customizable authentication and access-control framework. I ...
- 理解JSON Web Token (一)
一:理解单系统登录的原理及实现? web应用采用的 browser/server 架构的,http是无状态协议的,也就是说用户从A页面跳转到B页面会发起http请求,当服务器返回响应后,当用户A继续访 ...
- 使用 OAuth2-Server-php 搭建 OAuth2 Server
Yii 有很多 extension 可以使用,在查看了 Yii 官网上提供的与 OAuth 相关的扩展后,发现了几个 OAuth2 的客户端扩展,但是并没有找到可以作为 OAuth2 Server 的 ...
- kafka+storm结合存在的一些问题与解决方法
在配置kafka和storm的时候, 经常的会出现一些问题, 主要在以下几个: 1. 打jar包上去storm集群的时候会出现jar包冲突,类似于log4j或者sf4j的报错信息. 2. kafka ...