大数据集群 xsync文件同步脚本

一、简介
在大数据集群部署过程中,往往需要同步文件和配置到多台机器上,如果一台台的机器去复制,效率太低还容易出错。我们可以使用脚本的形式,批量同步文件,这里使用async进行文件同步。
二、实验环境
准备多台虚拟机,这里我准备三台
192.168.177.130  centos000
192.168.177.131  centos001
192.168.177.132  centos002
三、集群配置hostname
1、修改每台的hostname
[root@centos000 ~]# echo centos000 > /etc/hostname
[root@centos000 ~]# hostname centos000
[root@centos001 ~]# echo centos001 > /etc/hostname
[root@centos001 ~]# hostname centos001
[root@centos002 ~]# echo centos002 > /etc/hostname
[root@centos002 ~]# hostname centos002
2、配置hosts
vim /etc/hosts
192.168.177.130  centos000
192.168.177.131  centos001
192.168.177.132  centos002
四、配置SSH免密登录
1、使用命令ssh-keygen 生成rsa密钥,配置信息直接回车即可, 生成的密钥默认在当前用户主目录的.ssh目录下。
密钥文件有两个
id_rsa 存放着私钥
id_rsa.pub 存放着公钥
[root@centos000 ~]# ssh-keygen -f /root/.ssh/id_rsa -N '' #此操作在centos000上

2、下发公钥
[root@centos000 ~]ssh-copy-id centos001 #这里使用hostname,也可以使用IP进行下发
[root@centos000 ~]ssh-copy-id centos002
3、免密登录测试
[root@centos000 ~]# ssh centos001

五、xsync脚本使用
1、三台机器全部安装rsync
[root@centos000 ~]# yum install rsync -y
2、centos000的/usr/local/bin 下创建xsync文件

3、测试脚本

posted @ 2021-07-05 17:49  Carl1518  阅读(125)  评论(0编辑  收藏  举报