xsync.sh 配置 安装 并实现文件在各节点上的分发

学向勤中得,萤窗万卷书。这篇文章主要讲述xsync.sh 配置 安装 并实现文件在各节点上的分发相关的知识,希望能为你提供帮助。
xsync.sh 配置 安装 并实现文件在各节点上的分发 一 设置hosts相关信息
1. 设置 hosts

root@node130:~# vim /etc/hosts 10.172.200.130node130 10.172.200.131node131 10.172.200.132node132 10.172.200.133node133 10.172.200.134node134 10.172.200.135node135 10.172.200.136node136 10.172.200.137node137 10.172.200.138node138

2. 设置hostname (对应机器上执行该操作)
root@node130:~# hostnamectl --static set-hostname node130 root@node130:~# hostname node130 root@node130:~# hostname -i 10.172.200.130

  • 每台机器上都执行以上操作
二 设置免密登录相关信息
1. 客户端生成公钥
# 一路回车就行 root@node130:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:7e50VJXJc9ixQvEziR0ry00ka5uIbZrK7yJQH0YK+7w root@node130 The key\'s randomart image is: +---[RSA 2048]----+ |+o*=| |... O*B| |o o*.Xo| |. o o .o +.O o| |+ o S..+.= . | |. o . .+.| |. .oo .| |E...o .| |.o++o| +----[SHA256]-----+

2. 复制公钥到对应服务器
root@node130:~/.ssh# ssh-copy-id -i ~/.ssh/id_rsa.pubroot@10.172.200.131 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host \'10.172.200.131 (10.172.200.131)\' can\'t be established. ECDSA key fingerprint is SHA256:gd/XArnlj987R5oB/08R3RhoMrhzVKUvRqrl0yNXbvw. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@10.172.200.139\'s password: Number of key(s) added: 1Now try logging into the machine, with:"ssh \'root@10.172.200.131\'" and check to make sure that only the key(s) you wanted were added.

3. 查看对应服务器的授权信息
root@node131:~# cd ~/.ssh/ root@node131:~/.ssh# ls authorized_keysid_rsaid_rsa.pubknown_hosts root@node139:~/.ssh# vim authorized_keys # 这个是 客户端写入到服务器的 id_rsa.pub (公钥)内容。

4. 测试登录
root@node130:~# ssh root@10.172.200.131 Welcome to uos 20 GNU/Linux* Homepage:https://www.chinauos.com/* Bugreport:https://bbs.chinauos.com/Last login: Sat Jun 26 11:00:00 2021 from 10.173.134.66 root@node131:~#

  • 每台机器上都执行以上操作
三 rsync相关操作
1. 各个服务器上分别安装 rsync
root@node130:~# apt-y install rsync 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: fbterm imageworsener libc-ares2 libde265-0 libheif1 liblqr-1-0 libmaxminddb0 libqtermwidget5-0 libsbc1 libsmi2ldbl libspandsp2 libutf8proc2 libwireshark-data libwireshark11 libwiretap8 libwscodecs2 libwsutil9 qtermwidget5-data squashfs-tools 使用\'apt autoremove\'来卸载它(它们)。 下列【新】软件包将被安装: rsync 升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 232 个软件包未被升级。 需要下载 391 kB 的归档。 解压缩后会消耗 848 kB 的额外空间。 获取:1 https://enterprise-packages.chinauos.com/server-enterprise fou/sp3/main mips64el rsync mips64el 3.1.3-6 [391 kB] 已下载 391 kB,耗时 1秒 (643 kB/s) 正在选中未选择的软件包 rsync。 (正在读取数据库 ... 系统当前共安装有 180489 个文件和目录。) 准备解压 .../rsync_3.1.3-6_mips64el.deb... 正在解压 rsync (3.1.3-6) ... 正在设置 rsync (3.1.3-6) ... Created symlink /etc/systemd/system/multi-user.target.wants/rsync.service → /lib/systemd/system/rsync.service. 正在处理用于 man-db (2.8.5-2) 的触发器 ... 正在处理用于 systemd (241.8-1+dde) 的触发器 ...

  • 每台机器上都执行以上操作
2. 编写脚本,并把它放置在node130 上
#!/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` echo user=$user#5 循环 for((host=1; host< 9; host++)); do #echo $pdir/$fname $user@node13$host:$pdir echo --------------- node13$host ---------------- rsync -rvl $pdir/$fname $user@node13$host:$pdir done

【xsync.sh 配置 安装 并实现文件在各节点上的分发】保存文件并命名为 xsync.sh
3. 授权
root@node130:~# chmod 777 xsync.sh root@node130:~# ls -l -rw-r--r--1 root root49063732 6月25 11:35 seeyon.zip -rwxrwxrwx1 root root951 6月26 14:00 xsync.sh

4. 使用并测试
root@node130:~# ./xsync.shseeyon.zip fname=seeyon.zip pdir=/data/seeyon/G6N5/ApacheJetspeed/webapps user=root --------------- node131 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node132 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node133 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node134 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node135 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node136 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes30,892.00 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node137 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29 --------------- node138 ---------------- sending incremental file list seeyon.zipsent 28,125 bytesreceived 49,105 bytes51,486.67 bytes/sec total size is 49,063,732speedup is 635.29


    推荐阅读