예전에 PuTTYCS - 여러개의 putty를 띄워 같은 작업을 동시에 라는 글을 올리고 나서 주변에서 듣는 말.
"""그거 기껏해야 수십 대 정도밖에 안되는거 아니에요? 관리해야 할 서버가 몇댄데..."
"""화면은 안봐도 되니 그냥 자동화시켜 쭉 돌려버리고 싶어요."
"""후후 전 이미 그런 작업을 하기위한 스크립트를 만들어(기존에 있는 걸 약간 고쳐서) 쓰고 있어요. 즐~"
"""간단하게 하려면 ssh cmd로 해도 되긴 한데 여러 줄 명령을 못 내리기 때문에 여러 줄 명령을 실행하려면 스크립트를 서버 쪽으로 보내서 실행해야 하는 문제가 있어요."
등등...
뭐 맞는 말도 있고 틀린 말도 있다.
PuttyCS는 예전에 구글에서도 쓴다고 소개한 적 있는 clusterssh처럼 많아야 십여대정도 서버에 인터렉티브하게 함께 보면서 작업하고 싶을 때 쓰는 것이다.
만약 그 단위가 수백 대, 수천 대 단위로 넘어간다면 한 화면에 보기는 불가능하고 어떤 자동화된 절차를 통해서 명령을 내려야 할 것이다.
그렇다면 어떻게 그런 작업을 할 수 있을까?
ssh을 통해 특정서버에 명령을 실행시키려면 다음과 같이 한다.
<myserver 서버에 id로 로그인 하여 ls명령 실행>
ssh id@myserver ls
<ssh키를 등록해놓았을 때는 id는 생략하고 로그인 절차 없이 바로 실행, ;로 구분하여 여러 명령 실행>
""ssh myserver "ls -la;df"
그러면 여러줄의 명령이나 특정 쉘스크립트,Perl스크립트 등등을 원격서버에 실행 시키면 어떻게 해야 할까? 간단한 쉘명령이야 ;로 나눠서 한 줄에 넣어서 실행하면 되지만 작업이 복잡해지면 그런 형태로는 한계가 있다. 그럴때는 다음과 같은 방법을 쓸 수 있다.
<HEREDOC을 사용하는 방법>
ssh myserver <<\EOF
ls -la
df
EOF
<별도의 쉘스크립트를 만들고 원격에 스크립트 해석기를 실행시키고 파이프나 리다이렉션으로 보내는 방법>
#!/bin/sh
ls -la
df
가 test_script.sh 이라고 하면
cat test_script.sh | ssh myserver sh
또는
ssh myserver sh < test_script.sh
<Perl 스크립트를 ssh를 통해 실행>
cat perl_script.pl | ssh myserver perl
또는
ssh myserver perl < perl_script.pl
이것을 기초로 여러 서버에 명령을 내리려면 다음처럼 서버의 리스트를 만들고 리스트에 대해 루프를 돌면서 위의 명령을 서버별로 실행하면 될 것이다.
<여러 서버에 루프를 돌면서 지정한 스크립트를 실행하는 스크립트>
#!/bin/sh
"SERVERS="
myserver1
myserver2
""
for m in $SERVERS
do
ssh $m sh < test_script.sh
done
이렇게 하면 문제는 순차적으로 실행을 하기 때문에 한 서버씩 실행이 끝날 때 까지 기다려야 해서 속도가 늦고 나중에 결과를 보기가 힘들다는 것이다.
그러면
ssh $m sh < test_script.sh
줄을 다음과 같이
ssh $m sh < test_script.sh > $m.log &
고치면 각 ssh 명령이 fork되어서 백그라운드로 돌고 각 서버에 대한 결과는 서버이름.log 파일로 남게 된다. ( 작업결과는 *.log 파일들에 대해 grep이나 기타 유틸리티로 일괄적으로 확인 가능할 것이다. )
지금까지는 별도의 프로그램을 쓰지 않고 순수하게 기본 명령과 쉘스크립트 가지고 하는 방법이다. 하지만 이런 류의 작업은 다수의 서버를 관리 할 때 빈번하게 발생하므로 좀 더 많은 기능을 지원하면서 이런 작업을 해주는 프로그램이 많다.
shmux 라는 프로그램이 그런 것 중 하나인데 http://web.taranis.org/shmux/ 에 가보면 아랫쪽에 비슷한 기능을 하는 다음과 같은 프로그램 리스트가 쭉 있다.
•dsh
•dssh
•fanout
•'Kees Cook's gsh
•Mr. Shell
•multi-rsh
•multixterm
•mussh
•pssh
•p-run
•PyDsh
•remote_update.pl
•RGANG
•rshall
•tentakel
•vxargs
그리고 최근에 NHN에서 새로 문을 연 네이버개발자센터에서도 내부적으로 python으로 개발했다는 이런 류의 작업을 하는데 쓰는 dist라는 프로그램을 공개했다.
Perl을 쓴다면 CPAN에만 해도 이런 류의 작업을 위한 모듈/유틸리티들로
http://search.cpan.org/perldoc?Net::SSH
http://search.cpan.org/perldoc?Net::SSH::Expect
http://search.cpan.org/perldoc?GRID::Machine
http://search.cpan.org/perldoc?Script::Remote
http://search.cpan.org/perldoc?Net::FullAuto
http://search.cpan.org/perldoc?netrun
이런 것들 등등.. 이 있다. (물론 이보다 많겠지만 다 찾지는 못했다.)
우와 많다!
보다시피 이런 건 무슨 대단한 기술도 아니고 찾아보면 널리고 널린 게 이런 류의 프로그램이다. 하지만 다들 자기 입맛에 맞지 않는지 아니면 기존에 이런 프로그램이 있는 걸 모르는지 계속 바퀴를 재발명하는 것 같아 안타깝다.
""그래서 결론은 "니맘대로 적당한거 골라서 쓰세요." :)
http://zosel.net/trackback/6
from.Negozi Ugg 2015/11/10 01:47
nike free run womens zappos
from.Italia Ugg Online 2015/11/10 08:40
nike air bruin max
from.buy birkenstock 2015/11/10 18:17
birkenstock australia outlet
from.birkenstock online 2015/11/10 18:35
birkenstock australia store
from.Negozi Ugg A Roma 2015/11/10 20:41
nike free 2
from.Ugg Treviso 2015/11/11 10:53
blue nike free
from.Ugg Milano 2015/11/11 11:06
nike air max in sale
from.Ugg Prezzo Italia 2015/11/11 11:28
nike free trainers
from.Ugg Classic Tall 2015/11/12 19:57
mcm backpack outlet
from.Italia Ugg Online 2015/11/12 20:22
mcm purse
from.Ugg On Line 2015/11/13 04:11
nike air vs air max
from.Negozi Ugg Roma 2015/11/13 08:32
air max nike id
from.Ugg Australian 2015/11/13 08:33
mcm backpack review
from.Scarpe Ugg Australia 2015/11/13 08:54
nike shoe jordan
from.Ugg Italia Shop Online 2015/11/15 22:33
nike flash
from.Offerte Ugg Australia 2015/11/15 22:46
nike air max zappos
from.Ugg Mini Bailey 2015/11/15 23:29
where is the nike outlet store
from.Ugg Como 2015/11/16 10:35
nike free run 3.0 blue
from.Sito Ugg Australia 2015/11/16 10:36
nike flyknit online
from.Ugg Verdi 2015/11/18 11:13
nike for men
from.Costo Ugg Italia 2015/11/18 18:10
nike shoe sales
from.Compra Ugg Online 2015/11/18 22:07
mcm brand
from.Ugg 38 2015/11/18 22:32
nike free runs
from.Ugg Australia Official Site 2015/11/21 05:14
nike free run 3.0 running shoes
from.Stivali Ugg Prezzi Scontati 2015/11/21 11:05
nike running air max shoes
from.Ugg Australia Official Site 2015/11/21 11:12
womens nike shox nz
from.Ugg Scarpe 2015/11/23 18:15
nike free 5.0 womens
from.Boots Ugg Outlet 2015/11/23 19:46
nike shoe outlet
from.Negozi Ugg 2015/11/25 23:46
nike store custom
from.Ugg Boots Outlet Online 2015/11/26 01:48
nike air max green
from.Stivali Ugg Prezzo Italia 2015/11/26 02:08
nike outlet discount
from.Stivali Ugg Prezzi 2015/11/26 11:02
pink nike free run trainers
from.Ugg Baby 2015/11/26 15:22
cheap nike air max 2011
from.Ugg Scontati Online 2015/11/28 07:36
nike id basketball
from.Ugg Boots Outlet Italia 2015/11/28 07:56
nike outlet tucson
from.Mcm Outlet Stores 2016/02/04 14:15
nike free run shop online
from.Cheap Mcm Bags For Sale 2016/02/05 00:56
nike mercurial vapor superfly iii
from.Mcm Medium Backpack 2016/02/05 10:11
nike free runs women
from.Mcm Comic Con London 2014 2016/02/05 10:29
nike free runs 5.0 kids
from.Mcm Uk Online Shop 2016/02/05 12:37
nike sandals
from.Mcm Latest Collection 2016/02/05 12:56
nike free run 3.0 cheap
from.Mcm Handbags Outlet Sale 2016/02/05 18:56
nike free run sale
from.Mcm Bags London 2016/02/05 20:18
nike free training shoes
from.Buy Mcm Bag 2016/02/05 20:36
coupons for nike outlet
from.Ugg Boots Outlet Italia 2016/02/05 20:51
nike kids free run
from.Sito Ugg Scontati 2016/02/05 21:47
nike id store uk
from.Men Mcm Bags 2016/02/06 01:01
cheap nike training shoes
from.Mcm Mens Wallet 2016/02/06 01:19
nike air max for men on sale
from.Ugg Bottoni 2016/02/06 06:15
nike men shoes
from.Mcm Online Store Uk 2016/02/06 06:48
nike jordan shoes on sale
from.Shop Mcm 2016/02/06 07:22
nike air max am90
from.Cheap Mcm Wallet 2016/02/06 13:24
cheap nike shoes for girls
from.Mcm Outlet Stores 2016/02/06 16:16
nike id basketball shoes
from.Mcm Mens Shoes 2016/02/06 20:06
nike free custom
from.Mcm Purse Prices 2016/02/07 02:52
nike shox agent
from.Mcm Usa 2016/02/07 08:38
nike.com create your own shoes
from.Mcm Designer 2016/02/07 12:41
nike air a
from.Mcm In Uk 2016/02/07 14:32
nike free runs 3.0 v4
from.Mcm Bag Outlet 2016/02/07 14:50
cheap nike sneakers women
from.Mcm Travel Bag 2016/02/07 20:43
discounted nike shoes
from.Mcm Comic Con October 2014 2016/02/07 21:03
nike air max for women 2013
from.Where Can I Buy Mcm Backpack 2016/02/07 22:45
nike id kd
from.Mcm Mens Shoes 2016/02/08 02:30
mcm official online shop
from.Mcm Uk Online Shop 2016/02/08 08:32
nike outlet store uk
from.Mcm Bag Black 2016/02/08 08:33
nike free run price
from.Mcm Cheap 2016/02/08 17:41
nike running shoes discount
from.Mcm Bags For Men 2016/02/08 18:00
nike air maxes 2014
from.Mcm Sale Backpack 2016/02/08 19:58
nike free run trainers womens
from.Mcm Backpack Women 2016/02/09 02:08
mcm studded backpack
from.Mcm Brand 2016/02/09 07:43
nike shoes cheap prices online
from.Mcm Wallets Price 2016/02/09 08:02
nike air max 2010 womens
from.Mcm Backpack Prices 2016/02/09 13:47
womens nike free run 3.0 v4
from.Mcm Products 2016/02/09 13:52
nike free run womens discount
from.Mcm Bags For Women 2016/02/09 19:52
nike free print
from.Mcm Large 2016/02/09 23:45
mcm discount
from.Mcm Sneakers Men 2016/02/10 02:16
nike id order
from.Ugg Stivali Offerte 2016/02/10 06:19
cheap air max nike
from.Ugg Verdi 2016/02/10 07:28
nike air max 2014 buy
from.Mcm Official Store 2016/02/10 18:52
the nike outlet store
from.Mcm Backpack Shop 2016/02/10 19:55
nike runners for women
from.Mcm For Women 2016/02/11 03:19
cheap nike air max trainers
from.Ugg Leopardati 2016/02/11 04:31
nike free 5.0 women
from.Mcm Purses For Cheap 2016/02/11 13:28
shoes online nike air max
from.Mcm Electronics Location 2016/02/11 14:47
new nike shoes 2014
from.Mcm Shop London 2016/02/12 00:58
nike hi tops
from.Mcm 2016/02/12 02:11
nike flyknit air max womens
from.Ugg Black 2016/02/12 11:59
womens nike free run trainers
from.Mcm Jackets 2016/02/12 13:59
nike free v2
from.Mcm Bags Prices 2016/02/12 19:58
nike customise your own shoes
from.Mcm Backpack Australia 2016/02/13 13:50
nike free run shoes kids
from.Mcm Bags Cheap 2016/02/13 14:29
replica mcm
from.Costo Stivali Ugg 2016/02/13 15:46
air max nike.com
from.Mcm Backpack Women 2016/02/14 02:00
flyknit nike air max
from.Mcm Bags Vintage 2016/02/14 11:36
nike 3.0 free run
from.Mcm Pink Backpack 2016/02/14 11:54
buy cheap nike sneakers online
from.Mcm London Comic Con May 2014 2016/02/14 14:08
cheap womens nike shoes
from.Ugg Uomo Milano 2016/02/14 16:45
nike mogan
from.Mcm Bag For Cheap 2016/02/14 22:11
nike free run 5.0 nike.com
from.Shop Mcm Korea 2016/02/15 08:31
shop online nike air max
from.Mcm Online Shop 2016/02/16 00:11
black nike air max men
from.Ugg Australia Shop 2016/02/16 17:49
mcm london
from.Classic Cardy Ugg 2016/02/16 18:12
nike free 5.0 discount
from.Mcm Promo Code 2016/02/17 11:47
nike air max defy run men
from.Mcm Elctronics 2016/02/18 21:57
nike factory outlet online
from.Ugg Catalogo 2016/02/19 00:41
nike womens running shoe
from.Ugg Originali Online 2016/02/19 04:40
black white and grey nike air max
from.Paraorecchie Ugg 2016/02/21 01:29
nike discount
from.What Is Mcm Comic Con 2016/02/21 06:35
womens nike air max 2009
from.Ugg Stivali Online 2016/02/21 09:14
nike cheap free run
from.Mcm Official Store 2016/02/22 07:03
nike 6.0 id
from.Ugg Australia 2016/02/23 11:58
nike footwear women
from.Stivali Ugg Originali 2016/02/23 12:12
nike outlet shops
from.Ugg Bimbi 2016/02/23 12:32
nike training 5.0
from.Paraorecchie Ugg 2016/02/25 18:10
free 5.0 nike
from.Ugg Boots Milano 2016/02/25 18:26
nike air max 90 cheap
from.Stivali Pelosi Ugg 2016/02/25 23:17
nike fre
from.Mcm Backpacks Price 2016/02/26 19:54
nike toddler shoes
from.Ugg S 2016/02/27 21:52
nike free run 3.0 v4 womens
from.Discount Oakley Sunglasses Sale 2016/02/28 00:24
air max nike blue
from.Oakley Conduct Sunglasses 2016/03/01 02:36
nike shoe outlet stores
from.Cheap Oakley Sunglasses For Women 2016/03/01 02:48
mcm handbags
from.Ray Ban Justin Review 2016/03/01 08:53
nike air max order online
from.Ray Ban Wayfarer 2016/03/01 08:58
nike air max shoes shop
from.Brazilian body wave 2016/03/02 20:55
I simply most recently experienced my to begin with couple of Brazilian body wave. I adore him or her they can be sooooo adorable. I have never had time to generate him or her a lot of because it really has been at the same time style,nevertheless are...
from.Cheap Oakley Golf Shirts 2016/03/05 03:25
shop nike clothing
from.Oakley Women Sunglasses 2016/03/05 03:26
nike design own shoe
from.Cheap Oakley Hijinx Sunglasses 2016/03/05 09:29
http://lesnaja-poljana.ru/wp-content/oakley-thump-pro/Cheap-Oakley-Turbine-Sunglasses-twvfh5.htmlCheap Oakley Turbine Sunglasses
from.Discount Oakley Sunglasses Sale 2016/03/05 09:35
nike free runs with diamonds
from.Oakley Outlet Eagan Mn 2016/03/05 09:50
http://lesnaja-poljana.ru/wp-content/oakley-thump-pro/Oakley-Discount-Luggage-fbiz1f.htmlOakley Discount Luggage
from.Oakley Outlet Online 2016/03/05 09:55
nike shoes cheap sale
from.Cheap Fake Oakley Sunglasses Uk 2016/03/07 06:51
nike air max premium
from.Oakley Outlet Store Illinois 2016/03/07 07:09
cheap nike free run 4.0
from.Oakley Sunglasses On Sale 2016/03/07 20:50
womens nike free run 5.0
from.Oakley Outlet Rehoboth Beach 2016/03/11 14:02
2013 nike air max for women
from.Cheap Oakley Inmate Sunglasses 2016/03/11 14:24
cheap kids nike shoes
from.Oakley Sunglasses Military 2016/03/12 19:46
nike air max sale
from.Discount Oakley Sunglasses Cheap 2016/03/12 20:12
company mcm
from.Cheap Oakley Antix 2016/03/13 02:17
buy mcm backpack online
from.Cheap Oakley Hong Kong 2016/03/13 22:44
tiffany nike
from.Oakley Sunglass For Men 2016/03/14 22:07
nike id womens
from.Oakley Outlet Branson Mo 2016/03/15 11:14
http://lesnaja-poljana.ru/wp-content/oakley-thump-pro/Cheap-Oakley-Polos-sr0qma.htmlCheap Oakley Polos
from.nike air max 2016/03/16 00:33
::: ZOSEL ::: :: SSH로 많은 서버에 동시에 같은 명령내리기,nike air max
from.air max shoes 2016/03/16 01:09
::: ZOSEL ::: :: SSH로 많은 서버에 동시에 같은 명령내리기,air max shoes
from.Oakley Sunglasses Accessories 2016/03/16 15:34
nike id kd
from.fifa 17 coins for sale 2016/10/16 21:29
youre looking sharp!
145