rsync远程同步和时间同步

1、基本语法

rsync  -rvl  $pdir/$fname  $user@hadoop$host:$pdir/$fname

2、xsync集群分发脚本

touch xsync.sh

vim xsync.sh

#!/bin/bash
# $#:表示传递给脚本或函数的参数个数。
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount==0)); then
echo no args;
exit;
fi
 
#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname
 
#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir
 
#4 获取当前用户名称
user=`whoami`
 
#5 循环
#for((host=0; host<5; host++)); do
        #echo $pdir/$fname $user@hadoop$host:$pdir
 #       echo --------------- hadoop$host ----------------
 #       rsync -rvl $pdir/$fname $user@192.168.3.15$host:$pdir
#done
 
#5 循环
for host in {master,slaver1,slaver2,slaver3,slaver4,slaver5}; do
        #echo $pdir/$fname $user@$host:$pdir
        echo --------------- $host ----------------
        rsync -rvl $pdir/$fname $user@$host:$pdir
done

3、赋予执行权限chmod , 测试./xsync.sh hadoop/

 

 

时间服务器搭建

1、检查是否有ntp

rpm -qa | grep ntp
删除旧版
yum -y remove ntpdate-4.2.6p5-10.el6.centos.x86_64
或者
rpm -e --nodeps ntp-4.2.6p5-10.el6.centos.x86_64
安装最新版
yum -y install ntp

2、修改各个节点vim /etc/ntp.conf

当前节点IP地址
restrict 192.168.88.137 nomodify notrap nopeer noquery

集群所在网段的网关(Gateway),子网掩码(Genmask)
restrict 192.168.88.1 mask 255.255.255.0 nomodify notrap


例子:
restrict 192.168.88.131 nomodify notrap nopeer noquery

restrict 127.0.0.1
restrict -6 ::1

restrict 192.168.88.2 mask 255.255.255.0 nomodify notrap

3、选择一个主节点vim /etc/ntp.conf

# 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 127.127.1.0
Fudge 127.127.1.0 stratum 10

4、修改其他节点/etc/ntp.conf指向主节点

# 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 192.168.88.137
Fudge 192.168.88.137 stratum 10

5、启动各个节点的ntp服务

service ntpd start

6、其他节点查看ntp服务器有无和上层ntp连通

ntpstat

如果出现

unsynchronised polling server every 8 s

这种情况属于正常,ntp服务器配置完毕后,需要等待5-10分钟才能与/etc/ntp.conf中配置的标准时间进行同步。

等一段时间之后,再次使用ntpstat命令查看状态,就会变成正常结果

设置开机启动

chkconfig ntpd on

 

同步137节点的时间

ntpdate -u 192.168.88.137

可以配置定时任务

crontab -e进入定时任务编辑页面
00 22 * * 1 ntpdate -u 192.168.88.137 表示每周一晚上的十点同步一次

查看ntp服务器与上层ntp的状态

ntpq -p

remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先

refid:参考上一层ntp主机地址

st:stratum阶层

when:多少秒前曾经同步过时间

poll:下次更新在多少秒后

reach:已经向上层ntp服务器要求更新的次数

delay:网络延迟

offset:时间补偿

jitter:系统时间与bios时间差

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值