Linux xsync命令脚本

Linux xsync命令脚本在/bin/目录下创建xsync脚本如下:#!/bin/bash#1.判断参数个数if[$#-lt1]thenechoNotEnoughArguement!exit;fi#2.遍历集群所有机器forhostinmasternode1node2doecho====================$host====================#3.遍历所有目录,挨个发送forfilein$@do#4…

大家好,又见面了,我是你们的朋友全栈君。

在   /bin/目录下创建   xsync

首先 :yum install -y rsync

Linux xsync命令脚本

脚本如下:

#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
 echo Not Enough Arguement!
 exit;
fi

#2. 遍历集群所有机器
for host in master node1 node2
do
 echo ==================== $host ====================
 #3. 遍历所有目录,挨个发送
 for file in $@
 do
 #4. 判断文件是否存在
 if [ -e $file ]
 then
 #5. 获取父目录
 pdir=$(cd -P $(dirname $file); pwd)
 #6. 获取当前文件的名称
 fname=$(basename $file)
 ssh $host "mkdir -p $pdir"
 rsync -av $pdir/$fname $host:$pdir
 else
 echo $file does not exists!
 fi
 done
done

给xsync文件赋予执行权限:

chmod  777 xsync

然后执行 :    sudo  xsync   目录 

如:将 master机器/opt下的scp复制到  node1  node2

[root@master bin]#  xsync /opt/scp
-bash: /usr/local/bin/xsync: /bin/bash^M: 坏的解释器: 没有那个文件或目录
[root@master bin]# sudo  xsync /opt/scp
==================== master ====================
sending incremental file list

sent 134 bytes  received 18 bytes  304.00 bytes/sec
total size is 49  speedup is 0.32
==================== node1 ====================
sending incremental file list

sent 134 bytes  received 18 bytes  304.00 bytes/sec
total size is 49  speedup is 0.32
==================== node2 ====================
sending incremental file list

sent 130 bytes  received 18 bytes  296.00 bytes/sec
total size is 49  speedup is 0.33
[root@master bin]# cd 
[root@master ~]# xsync /opt/scp
-bash: /usr/local/bin/xsync: /bin/bash^M: 坏的解释器: 没有那个文件或目录
[root@master ~]# sudo xsync /opt/scp
==================== master ====================
sending incremental file list

sent 130 bytes  received 18 bytes  296.00 bytes/sec
total size is 49  speedup is 0.33
==================== node1 ====================
sending incremental file list

sent 134 bytes  received 18 bytes  304.00 bytes/sec
total size is 49  speedup is 0.32
==================== node2 ====================
sending incremental file list

sent 134 bytes  received 18 bytes  304.00 bytes/sec
total size is 49  speedup is 0.32
[root@master ~]# cd /opt/
[root@master opt]# cd scp/
[root@master scp]# ll
总用量 4
-rw-r--r-- 1 root root 45 12月 11 21:06 1.html
drwxr-xr-x 2 root root 22 12月 11 21:38 abc
[root@master scp]# mkdir aaaaa
[root@master scp]# cd aaaaa/
[root@master aaaaa]# vi aa.text
[root@master aaaaa]# cd
[root@master ~]# sudo xsync /opt/scp
==================== master ====================
sending incremental file list

sent 183 bytes  received 19 bytes  404.00 bytes/sec
total size is 62  speedup is 0.31
==================== node1 ====================
sending incremental file list
scp/
scp/aaaaa/
scp/aaaaa/aa.text

sent 249 bytes  received 48 bytes  594.00 bytes/sec
total size is 62  speedup is 0.21
==================== node2 ====================
sending incremental file list
scp/
scp/aaaaa/
scp/aaaaa/aa.text

sent 249 bytes  received 48 bytes  594.00 bytes/sec
total size is 62  speedup is 0.21
[root@master ~]# cd
[root@master ~]# cd /bin/
[root@master bin]# vi xsync
[root@master bin]# 

Linux xsync命令脚本

Linux xsync命令脚本

Linux xsync命令脚本

附:

zk.sh 脚本

#!/bin/bash
case $1 in
"start"){
for i in master node1 node2
do
 echo ---------- zookeeper $i 启动 ------------
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh  start"
done
};;
"stop"){
for i in master node1 node2
do
 echo ---------- zookeeper $i 停止 ------------ 
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop"
done
};;
"status"){
for i in master node1 node2
do
 echo ---------- zookeeper $i 状态 ------------ 
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh status"
done
};;
esac

附:

jpsall.sh 脚本:

#!/bin/bash

# 执行jps命令查询每台服务器上的节点状态
echo ======================集群节点状态====================

for i in master node1 node2
do
        echo ====================== $i ====================
        ssh $i "/opt/jdk/jdk1.8.0_202/bin/jps"
done
echo ======================执行完毕====================

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/137280.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(1)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号