1, all business testing machine different node run different business (through hosts view)
[[email protected] rex]# cat /etc/hosts127.0.0.1 mail.weike.com mx localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.0.128 node1 caisen192.168.0.129 node2 mail192.168.0.45 node3 guanwang192.168.0.164 node4 shopwap192.168.0.193 node5 gerenwap192.168.0.196 node6 appwap192.168.0.224 node7 geren192.168.0.226 node8 chaoshi192.168.0.228 node9 quanguo192.168.0.215&nbSp; node10 boss
2, the different Web services are organized in the form of modules for centralized management, rexfile configuration information is as follows:
use rex -feature => [' 1.3 '];use strict;use warnings; #use data::D umper;# Modular configuration for different service types require servers::quanguo;require servers::chaoshi;require servers::geren; Require servers::boss;require servers::shopwap;require servers::gerenwap;require servers:: appwap;require servers::guanwang; #远程连接登陆方式private_key "/root/.ssh/id_rsa";p ublic_key "/root/. Ssh/id_rsa.pub "; #设置线程数parallelism ' Max '; #所有服务器节点group all_servers => "node[1..6]";group test_servers => "node[1..2]"; desc "Turn off Tomcat and WebLogic services on all nodes";task "Stop_web",group=> "All_servers",sub{ #my @ps =ps (); #print Dumper (@ps); #my @list =grep{$_->{"command"}==-5}ps (" Command "," ni "); for my $proc (PS ()) { if ($proc->{"command"}=~/java.*tomcat/is) { run "./shutdown.sh", cwd => "/usr/local/tomcat/bin", only_if => "Pgrep java"; say "Tomcat Service shutdown complete "; exit 0; }elsif ($proc->{"command"}=~/java.*?node1.*?weblogic/is) { run "stop_node.sh", only_if=> "Pgrep java"; say "WebLogic Service shutdown Complete"; exit 0; }else{ next; } } say "Service has been closed";}; desc "Start Tomcat and WebLogic services on all nodes";task "Start_web",group=> "All_servers",sub{ if (Is_file ("/usr/local/tomcat/bin/startup.sh")) { run "./startup.sh", cwd => "/usr/loCal/tomcat/bin ", unless => "Pgrep java"; }else{ run "start_node.sh", unless => "Pgrep java"; } for my $proc (PS ()) { if ($proc->{"command"}=~/java.*tomcat/i) { say "Tomcat has started, process pID: ". $proc->{" pid "}; exit 0; }elsif ($proc->{"command"}=~/java.*?node1.*? weblogic/is) { say "WebLogic Service has started, process pid:". $proc->{"pid"}; exit 0; }else{ next; } } say "Service failed to start";};
3, the configuration contents of each module are the same except for the distributed file name. The contents of the module are as follows
package servers::appwap;use rex -feature => [' 1.3 ';d esc " Distribute the data source profile to the Personal hub WAP node server ";task " Deploy_gerenwap "," Appwap ",sub{ if (!is_dir ("/usr/local/dbsrc")) { file "/USR/LOCAL/DBSRC", ensure = > "Directory", owner => "Root", group => "Root", mode =>755; upload "/rex/conf/jdbc_moser.properties ","/USR/LOCAL/DBSRC "; }; file "/usr/local/dbsrc/jdbc_moser.properties", source=> "/rex/conf/jdbc_moser.properties", owner=> "Root", group=> " Root ", mode= >644, on_ Change=> sub { say "Data Source Configuration updated successfully"; };}; 1;
4, you can view all the tasks you have defined by Rex-t:
[[email protected] rex]# rex-ttasks start_web start Tomcat and WebLogic services on all nodes Stop_web shut down Tomcat and WebLogic services on all nodes Servers:ap Pwap:deploy_gerenwap distributing the data source profile to the Personal hub WAP node server Servers:Boss:deploy_boss distributing the data source profile to the Boss node server Servers:Chaoshi:deploy_ Chaoshi Distributing data source profiles to supermarket node servers Servers:Geren:deploy_geren distributing data source profiles to personal Hub server Servers:Gerenwap:deploy_gerenwap distributing data source profiles To the personal hub WAP node Server Servers:Guanwang:deploy_guanwang distribute the data source profile to the official website node Server Servers:Quanguo:deploy_quanguo Distribute the data source profile to the National node server Servers:Shopwap:deploy_shopwap Distributing data source profiles to Marketplace WAP node server Groups all_servers node[1..10] test_servers node[1..2]
5, running related tasks only requires Rex + task to say Yes (e.g. Rex Start_web will start the Web service on all nodes) For example, I distribute different configuration files to the appropriate Web nodes I write all the class modules in a shell script as follows
[email protected] rex]# cat deploy_dbsr.sh #!/bin/bashrex Servers:Appwap:deploy_gerenwap Servers:Boss:deploy_boss Servers:Chaoshi:deploy_chaoshi Servers:Geren:deploy_geren Servers:Guanwang:deploy_guanwang Servers:gerenwap: Deploy_gerenwap Servers:Quanguo:deploy_quanguo Servers:Shopwap:deploy_shopwap
And then I'm going to run this script again.
[[email protected] rex]# ./deploy_dbsr.sh [2015-09-05 21:15:41] info -  RUNNING TASK SERVERS:APPWAP:DEPLOY_GERENWAP ON APPWAP[2015-09-05 21:15:41] INFO - Connecting to appwap:22 (Root) [2015-09-05 21:15:41] info - connected and authenticated to appwap. [2015-09-05 21:15:41] info - successfully authenticated on appwap. [2015-09-05 21:15:43] info - running task servers:boss:deploy_boss on boss[2015-09-05 21:15:43] info - connecting to boss:22 (root) [2015-09-05 21:15:43] info - connected and authenticated to boss. [2015-09-05 21:15:43] info - successfully authenticated on boss. [2015-09-05 21:15:44] INFO - RUNNING TASK SERVERS:CHAOSHI:DEPLOY_CHAOSHI&Nbsp;on chaoshi[2015-09-05 21:15:44] info - connecting to chaoshi:22 ( Root) [2015-09-05 21:15:44] info - connected and authenticated to Chaoshi. [2015-09-05 21:15:44] info - successfully authenticated on chaoshi. [2015-09-05 21:15:45] info - running task servers:geren:deploy_geren on geren[2015-09-05 21:15:45] INFO - Connecting to geren:22 (Root) [ 2015-09-05 21:15:45] info - connected and authenticated to geren. [2015-09-05 21:15:45] info - successfully authenticated on geren. [2015-09-05 21:15:46] info - running task servers:guanwang:deploy_guanwang on guanwang[2015-09-05 21:15:46] info - connecting to guanwang:22 ( root) [2015-09-05 21:15:46] INFO&NBsp;- connected and authenticated to guanwang. [2015-09-05 21:15:46] info - successfully authenticated on guanwang. [2015-09-05 21:15:47] info - running task servers:gerenwap:deploy_gerenwap on gerenwap[2015-09-05 21:15:47] info - connecting to gerenwap:22 ( Root) [2015-09-05 21:15:47] info - connected and authenticated to Gerenwap. [2015-09-05 21:15:47] info - successfully authenticated on gerenwap. [2015-09-05 21:15:48] info - running task servers:quanguo:deploy_quanguo on quanguo[2015-09-05 21:15:48] INFO - Connecting to quanguo:22 (Root) [ 2015-09-05 21:15:48] info - connected and authenticated to quanguo. [2015-09-05 21:15:48] info - successfully Authenticated on quanguo. [2015-09-05 21:15:49] info - running task servers:shopwap:deploy_shopwap on shopwap[2015-09-05 21:15:49] INFO - Connecting to shopwap:22 (Root) [ 2015-09-05 21:15:49] info - connected and authenticated to shopwap. [2015-09-05 21:15:49] info - successfully authenticated on shopwap.
If any one of the connection operation fails, it will print out the relevant information, according to the information can troubleshoot the cause of the error!
Distribution of configuration files to different service nodes and centralized control of Web services for each node via Rex + module