标签:
Rex控制台;操作系统(centos7.1)
weblogic集群操作系统:centos6.6
tomcat集群操作系统:centos6.6
nginx代理操作系统:centos6.6
远程方式:ssh公钥认证;
Rex最新版本是1.3.2 该模块功能也很强大,支持各种操作,比较轻量。基本上能满足我的所有需求。Rex的安装,使用以及配置请参perldoc或者官网;
代码如下:
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"; };
脚本写的很烂,现在还不是太熟悉,只能很机械的先用着
通过Rex控制多个集群环境中的tomcat和weblogic(待完善)
标签:
原文地址:http://my.oschina.net/u/2420214/blog/491979