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

[[email protected] ~]# yum install ntp

第二步,设置开机自启动

[[email protected] conf]# chkconfig ntpd on
[[email protected] conf]# chkconfig --list ntpd
ntpd               0:off    1:off    2:on    3:on    4:on    5:on    6: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

然后要找到可以正常提供时间服务的外部主机,执行以下命令

[[email protected] ~]# ntpdate -q 1.cn.pool.ntp.org
server 51.15.41.135, stratum 3, offset -0.648578, delay 0.37547
server 193.228.143.12, stratum 2, offset -0.652907, delay 0.36064
server 202.118.1.130, stratum 2, offset -0.650668, delay 0.05075
server 120.25.115.20, stratum 2, offset -0.650029, delay 0.06900
29 Sep 17:51:21 ntpdate[1500]: 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

[[email protected] ~]# 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.2restrict 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 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
#指定上层对时的外部服务器,这些都是上面刚刚得到的可以正常提供时间服务的外部主机
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 10

第四步,同步硬件时间

提君博客原创

在 Linux 下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了,那么既然两个时钟独自运行,那么时间久了必然就会产生误差了,而 NTP 默认又只更新系统时间,因此我们需要设置硬件时钟进行同步调整

[[email protected] ~]# 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/  <<

[[email protected] ~]# service ntpd start
Starting ntpd:                                             [  OK  ]

查看服务连接和监听

[[email protected] ~]# netstat -tlunp | grep ntp
udp        0      0 192.168.11.11:123           0.0.0.0:*                               1327/ntpd
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1327/ntpd
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1327/ntpd
udp        0      0 fe80::20c:29ff:fec5:88c5:123 :::*                                    1327/ntpd
udp        0      0 ::1:123                     :::*                                    1327/ntpd
udp        0      0 :::123                      :::*                                    1327/ntpd           

查看网络中的NTP服务器,同时显示客户端和每个服务器的关系

[[email protected] ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp3.itcomplian 5.103.128.88     3 u   25   64   37  446.548  -700.47   1.006
 ntp1.flashdance 193.11.166.20    2 u   21   64   17  432.794  -705.08  12.690
*202.118.1.130   202.118.1.47     2 u   23   64   37   24.599  -653.77   1.470
 120.25.115.20   10.137.38.86     2 u   18   64   37   42.456  -651.64   1.038
 LOCAL(0)        .LOCL.          10 l   90   64   36    0.000    0.000   0.000

查看时间同步状态

提君博客原创

[[email protected] ~]# ntpstat
synchronised to NTP server (202.118.1.130) at stratum 3
   time correct to within 1658 ms
   polling server every 64 s

第六步,配置NTP-client,这是在除192.168.11.11的其他机器上进行

[[email protected] ~]# 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 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

#对时服务器,配置成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 10

配置同步硬件时间

[[email protected] ~]# 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为例

[[email protected] ~]# service ntpd start
Starting ntpd:                                             [  OK  ]

手动向192.168.11.11更新一次时间

ntpdate -u 192.168.11.11

查看服务连接和监听

[[email protected] ~]# netstat -tlunp | grep ntp
udp        0      0 192.168.11.12:123           0.0.0.0:*                               10776/ntpd
udp        0      0 127.0.0.1:123               0.0.0.0:*                               10776/ntpd
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               10776/ntpd
udp        0      0 ::1:123                     :::*                                    10776/ntpd
udp        0      0 fe80::20c:29ff:fef9:26cb:123 :::*                                    10776/ntpd
udp        0      0 :::123                      :::*                                    10776/ntpd       

查看网络中的NTP服务器,同时显示客户端和每个服务器的关系

[[email protected] ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ltt1.bg.cn      202.118.1.130    3 u  880 1024  377    1.184    0.242   1.190
 LOCAL(0)        .LOCL.          10 l  14h   64    0    0.000    0.000   0.000

查看时间同步状态

>>提君博客原创  http://www.cnblogs.com/tijun/  <<

[[email protected] ~]# ntpstat
synchronised to NTP server (192.168.11.11) at stratum 4
   time correct to within 85 ms
   polling server every 1024 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/  <<

时间: 2024-08-18 16:31:47

centos6.5安装配置NTP,集群各机器间时间同步的相关文章

CentOS 6.6 上使用 luci/ricci 安装配置 RHCS 集群

1.配置 RHCS 集群的前提: 时间同步 名称解析,这里使用修改/etc/hosts 文件 配置好 yum 源,CentOS 6 的默认的就行 关闭防火墙(或者开放集群所需通信端口),和selinux, 关闭 NetworkManager 服务 2. RHCS 所需要的主要软件包为 cman 和 rgmanager cman: 是集群基础信息层,在 CentOS 6中依赖 corosync rgmanager: 是集群资源管理器, 类似于pacemaker 的功能 luci: 提供了管理 rh

配置NTP集群时间同步(二)

[[email protected] bin]# rpm -qa|grep ntp 没有的话用yum -y install ntp安装(要记着每台机器上都要安装) [[email protected] bin]# vi /etc/ntp.conf 修改内容如下 a)修改1(设置本地网络上的主机不受限制.)#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap为 restrict 192.168.8.0 mask 255.255.255.0

Hadoop2.2集群安装配置-Spark集群安装部署

配置安装Hadoop2.2.0 部署spark 1.0的流程 一.环境描写叙述 本实验在一台Windows7-64下安装Vmware.在Vmware里安装两虚拟机分别例如以下 主机名spark1(192.168.232.147),RHEL6.2-64 操作系统,usernameRoot 从机名spark2(192.168.232.152).RHEL6.2-64 操作系统,usernameRoot 二.环境准备 1.防火墙禁用.SSH服务设置为开机启动.并关闭SELINUX 2.改动hosts文件

CentOS 6.9安装配置ZooKeeper集群

一.ZooKeeper相关概念简介: ZooKeeper是一个开源的.分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.域名服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效.功能稳定的系统提供给用户. 二.演示环境: IP地址 节点名称 操作系统 JDK版本 ZooKeeper版本 192.168.1.144 s

架构(三)MongoDB安装配置以及集群搭建

一 安装 1.1 下载MongoDB 我个人不太喜欢用wget url, 之前出现过wget下载的包有问题的情况 https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.7.tgz 1.2 上传服务器并解压 tar -zxvf mongodb-linux-x86_64-3.4.7.tgz 1.3 移动到/data/program/software/mongodb mv mongodb-linux-x86_64-3.4.7/ /data/

CentOS7.5 使用 kubeadm 安装配置 Kubernetes 集群(四)

在之前的文章,我们已经演示了 yum 和二进制方式的安装方式,本文我们将用官方推荐的 kubeadm 来进行安装部署. kubeadm 是 Kubernetes 官方提供的用于快速安装Kubernetes集群的工具,伴随Kubernetes每个版本的发布都会同步更新,kubeadm会对集群配置方面的一些实践做调整,通过实验kubeadm可以学习到Kubernetes官方在集群配置上一些新的最佳实践. 一.环境准备 1.软件版本 软件 版本 kubernetes v1.12.2 CentOS 7.

安装、配置Redis集群

安装.配置Redis集群 目录 安装.配置Redis集群... 1 1.配置yum... 1 2.安装gcc. 1 3.下载软件包... 2 4.安装(主从都需要安装) 2 5.配置redis集群... 3 6.启动与关闭... 4 7.安装ruby rubygems. 4 8.初始化集群... 4 注:本例操作系统为Red Hat Enterprise Linux Server release 6.4 1.配置yum 未注册的Redhat不支持yum,调整步骤: cd /etc/yum.rep

通过tarball形式安装HBASE Cluster(CDH5.0.2)——配置分布式集群中的YARN ResourceManager 的HA

<?xml version="1.0"?> <!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses

通过tarball形式安装HBASE Cluster(CDH5.0.2)——如何配置分布式集群中的zookeeper

集群安装总览参见这里 Zookeeper的配置 1,/etc/profile中加入zk的路径设置,见上面背景说明. 2,进入~/zk/conf目录,复制zoo_sample.cfg为zoo.cfg vim zoo.conf tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/hadoop/hdfs/zk/data dataLogDir=/home/hadoop/hdfs/zk/log clientPort=2181 server.21=zk1