๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ปTech/๐ŸงLinux

[๋ฆฌ๋ˆ…์Šค] ์—ฌ๋Ÿฌ ์„œ๋ฒ„ ์›๊ฒฉ ์ž‘์—… (parallel-ssh, ssh remote shell)

by _viper_ 2021. 3. 4.
๋ฐ˜์‘ํ˜•

๋ฆฌ๋ˆ…์Šค์—์„œ ์—ฌ๋Ÿฌ ์„œ๋ฒ„๋“ค ๋™์‹œ์— ์ž‘์—…ํ•  ๋•Œ ์œ ์šฉํ•œ 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. (parallel-ssh๋ฅผ ์ถ”์ฒœ)

โ—พ parallel-ssh ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ

1. ๋‹ค์šด ๋ฐ ์„ค์น˜
pssh-2.3.1.tar.gz ๋‹ค์šด (https://code.google.com/archive/p/parallel-ssh/downloads/)
tar xvzf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py install

2. ์ž‘์—… host ํŒŒ์ผ ์ž‘์„ฑ 
vi allnodes 
------------------------------
cdpwork01
cdpwork02
cdpwork03
------------------------------

3. keygen ์ƒ์„ฑ ๋ฐ ๋ฐฐํฌ
ssh-keygen
chmod 700 .ssh
cd .ssh
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
cd

rsync -av .ssh cdpwork01:/root
rsync -av .ssh cdpwork02:/root
rsync -av .ssh cdpwork03:/root

4. pssh ๋ช…๋ น์–ด ์‚ฌ์šฉ๋ฒ• (pssh, pscp, prsync ์‚ฌ์šฉ ๊ฐ€๋Šฅ)
pssh -i -h ./allnodes 'df -h'
-i : ๊ฒฐ๊ณผ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ (์ž‘์—…๋งŒ ํ• ๊ฑฐ๋ฉด ์ œ์™ธ)
-h : host ํŒŒ์ผ ์œ„์น˜

 

โ—พ ssh remote shell ์‚ฌ์šฉ

vi ssh.sh
------------------------------
#!/bin/bash

hosts=(
cdpwork01
cdpwork02
cdpwork03
)

for host in "${hosts[@]}"
do
 echo "===== $host ====="
 ssh $host "$@"
 echo ""
done
------------------------------

vi rsync.sh
------------------------------
#!/bin/bash

hosts=(
cdpwork01
cdpwork02
cdpwork03
)

for host in "${hosts[@]}"
do
 echo "===== $host ====="
 rsync -av $1 $host:$2
 echo ""
done