Rex控制檯;操做系統(centos7.1)java
weblogic集羣操做系統:centos6.6node
tomcat集羣操做系統:centos6.6nginx
nginx代理操做系統:centos6.6web
遠程方式:ssh公鑰認證;centos
Rex最新版本是1.3.2 該模塊功能也很強大,支持各類操做,比較輕量。基本上能知足個人全部需求。Rex的安裝,使用以及配置請參perldoc或者官網;tomcat
代碼以下:ssh
use Rex -feature => ['1.3']; use strict; use warnings; use Data::Dumper; #webservers跑的都是weblogic服務 #mobservers是移動web服務 #proxyservers是代理服務 private_key "/root/.ssh/id_rsa"; public_key "/root/.ssh/id_rsa.pub"; #設置線程數 parallelism 'max'; group webservers =>"webserver[1..6]"; group mobservers =>"mobserver[1..3]"; group proxyservers =>"proxy[224,226,228]"; desc "查看運行的進程"; task "ps",group=>"webservers",sub{ for my $prc(ps()){ say "command :".$prc->{"command"}; say "pid :".$prc->{"pid"}; say "user :".$prc->{"user"}; } }; desc "檢查webservers集羣上的weblogic是否在運行,並獲取pid號"; task "chk_wls",group=>"webservers",sub{ for my $prc(ps()){ if($prc->{command}=~/java/i){ say "weblogic正在運行"; say "pid:".$prc->{"pid"}; }else{ next; } } }; desc "中止webservers集羣上的weblogic服務"; task "stop_wls",group=>"webservers",sub{ for my $process(ps()){ if($process->{"command"}=~/java/i){ say run "stop_node.sh"; last; }else{ next; } } say "welbogic服務已經關閉"; }; desc "啓動webservers集羣上的weblogic服務"; task "start_wls",group=>"webservers",sub{ for my $process(ps()){ if($process->{"command"}=~/java/i){ say "服務已經在運行"; exit(1); }else{ next; } } run "start_node.sh"; say "weblogic服務啓動成功"; }; desc "啓動mobservers集羣上的tomcat"; task "start_tomcat",group=>"mobservers",sub{ my $star_cmd='/usr/bin/startup.sh'; for my $process(ps()){ if($process->{"command"}=~/java/i){ say "服務已經在運行"; exit(1); }else{ next; } } if(is_file($star_cmd) && is_readable($star_cmd)){ say run "startup.sh"; }else{ chdir("/usr/local/tomcat/bin"); cp("./startup.sh","/usr/bin/"); say run "startup.sh"; } say "tomcat啓動...ok"; }; desc "關閉mobservers集羣上的tomcat"; task "stop_tomcat",group=>"mobservers",sub{ my $stop_cmd='/usr/bin/shutdown.sh'; for my $process(ps()){ if($process->{"command"} !~ /java/i){ say "服務已經中止"; exit(1); }else{ next; } } if(is_file($stop_cmd) && is_readable($stop_cmd)){ say run "shutdown.sh"; }else{ chdir("/usr/local/tomcat/bin"); cp("./shutdown.sh","/usr/bin/"); say run "shutdown.sh"; } say "tomcat服務關閉...ok"; };
腳本寫的很爛,如今還不是太熟悉,只能很機械的先用着centos7