Rex + module 형식으로 프로필을 서로 다른 서비스 노드에 나누어 주고 각 노드를 집중적으로 제어하는 웹 서비스
[root@localhost rex]# cat /etc/hosts
127.0.0.1 mail.weike.com mx localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.128 node1 caisen
192.168.0.129 node2 mail
192.168.0.45 node3 guanwang
192.168.0.164 node4 shopwap
192.168.0.193 node5 gerenwap
192.168.0.196 node6 appwap
192.168.0.224 node7 geren
192.168.0.226 node8 chaoshi
192.168.0.228 node9 quanguo
192.168.0.215 node10 boss
2. 각각 다른 웹 서비스를 모듈로 구성하여 집중적으로 관리한다. Rexfile 구성 정보는 다음과 같다.
use Rex -feature => ['1.3'];
use strict;
use warnings;
#use Data::Dumper;
#
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";
public_key "/root/.ssh/id_rsa.pub";
#
parallelism 'max';
# web
group all_servers =>"node[1..2,4..10]";
desc " tomcat weblogic ";
task "stop_web",group=>"all_servers",sub{
#my @ps=ps();
#print Dumper(@ps);
#my @list=grep{$_->{"command"}==-5}ps("command","ni");
my $server = Rex::get_current_connection()->{server};
for my $proc(ps()){
if($proc->{"command"}=~/java.*tomcat/is){
run "./shutdown.sh",
cwd =>"/usr/local/tomcat/bin",
only_if =>"pgrep java";
say "[$server]: tomcat ";
last;
}elsif($proc->{"command"}=~/java.*?node1.*?weblogic/is){
run "stop_node.sh",
only_if=>"pgrep java";
say "[$server]: weblogic ";
last;
}else{
next;
}
}
say "[$server]: ";
};
desc " tomcat weblogic ";
task "start_web",group=>"all_servers",sub{
my $server = Rex::get_current_connection()->{server};
if(is_file("/usr/local/tomcat/bin/startup.sh")){
run "./startup.sh",sub {
my($stdout,$stderr)=@_;
say "[$server]: $stdout";
},
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 "[$server]: tomcat , pid:".$proc->{"pid"};
last;
}elsif($proc->{"command"}=~/java.*weblogic/isg){
say "[$server]: weblogic , pid:".$proc->{"pid"};
last;
}else{
next;
}
}
};
desc " tomcat weblogic ";
task "restart_web",group=>"all_servers",sub {
my $server = Rex::get_current_connection()->{server};
needs 'stop_web';
sleep 3;
needs 'start_web';
say "[$server]: ";
};
desc " web ";
task "deploy_file",group=>"all_servers",sub {
my $server = Rex::get_current_connection()->{server};
Servers::Quanguo->deploy_quanguo if $server eq 'node9';
Servers::Chaoshi->deploy_chaoshi if $server eq 'node8';
Servers::Geren->deploy_geren if $server eq 'node7';
Servers::Boss->deploy_boss if $server eq 'node10';
Servers::Shopwap->deploy_shopwap if $server eq 'node4';
Servers::Gerenwap->deploy_gerenwap if $server eq 'node5';
Servers::Appwap->deploy_appwap if $server eq 'node6';
Servers::Guanwang->deploy_guanwang if $server eq 'node3';
};
desc " ";
task "current_time",group=>"all_servers",sub{
say run "date";
};
3, 각 모듈의 설정 내용은 모두 같다. 나누어 준 파일 이름을 제외하고.모듈 내용은 다음과 같습니다.
package Servers::Appwap;
use Rex -feature => ['1.3'];
desc " wap ";
task "deploy_appwap","appwap",sub{
my $server = Rex::get_current_connection()->{server};
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 "[$server]: ";
};
};
1;
4, rex -T를 통해 자신이 정의한 모든 작업을 볼 수 있습니다.
[root@localhost rex]# rex -T
Tasks
deploy_file web
restart_web tomcat weblogic
start_web tomcat weblogic
stop_web tomcat weblogic
Servers:Appwap:deploy_appwap wap
Servers:Boss:deploy_boss Boss
Servers:Chaoshi:deploy_chaoshi
Servers:Geren:deploy_geren
Servers:Gerenwap:deploy_gerenwap wap
Servers:Guanwang:deploy_guanwang
Servers:Quanguo:deploy_quanguo
Servers:Shopwap:deploy_shopwap wap
Server Groups
all_servers node[1..2,4..10]
5. 어떤 인물을 운행하려면 rex+task만 사용하면 된다. 예를 들어 나는 모든 노드의tomcat과 웹logic 서비스를 시작할 것이다. 다음과 같다.
[root@localhost rex]# rex start_web
[2015-09-06 06:07:51] INFO - Running task start_web on node1
[2015-09-06 06:07:51] INFO - Connecting to node1:22 (root)
[2015-09-06 06:07:51] INFO - Connected and authenticated to node1.
[2015-09-06 06:07:51] INFO - Successfully authenticated on node1.
[node1]: tomcat , pid:5147
[2015-09-06 06:07:52] INFO - Running task start_web on node2
[2015-09-06 06:07:52] INFO - Connecting to node2:22 (root)
[2015-09-06 06:07:52] INFO - Connected and authenticated to node2.
[2015-09-06 06:07:52] INFO - Successfully authenticated on node2.
[node2]: tomcat , pid:5220
[2015-09-06 06:07:52] INFO - Running task start_web on node4
[2015-09-06 06:07:52] INFO - Connecting to node4:22 (root)
[2015-09-06 06:07:53] INFO - Connected and authenticated to node4.
[2015-09-06 06:07:53] INFO - Successfully authenticated on node4.
[node4]: tomcat , pid:13178
[2015-09-06 06:07:53] INFO - Running task start_web on node5
[2015-09-06 06:07:53] INFO - Connecting to node5:22 (root)
[2015-09-06 06:07:54] INFO - Connected and authenticated to node5.
[2015-09-06 06:07:54] INFO - Successfully authenticated on node5.
[node5]: tomcat , pid:23775
[2015-09-06 06:07:54] INFO - Running task start_web on node6
[2015-09-06 06:07:54] INFO - Connecting to node6:22 (root)
[2015-09-06 06:07:55] INFO - Connected and authenticated to node6.
[2015-09-06 06:07:55] INFO - Successfully authenticated on node6.
[node6]: tomcat , pid:19614
[2015-09-06 06:07:55] INFO - Running task start_web on node7
[2015-09-06 06:07:55] INFO - Connecting to node7:22 (root)
[2015-09-06 06:07:56] INFO - Connected and authenticated to node7.
[2015-09-06 06:07:56] INFO - Successfully authenticated on node7.
[node7]: weblogic , pid:26615
[2015-09-06 06:07:56] INFO - Running task start_web on node8
[2015-09-06 06:07:56] INFO - Connecting to node8:22 (root)
[2015-09-06 06:07:56] INFO - Connected and authenticated to node8.
[2015-09-06 06:07:57] INFO - Successfully authenticated on node8.
[node8]: weblogic , pid:24851
[2015-09-06 06:07:57] INFO - Running task start_web on node9
[2015-09-06 06:07:57] INFO - Connecting to node9:22 (root)
[2015-09-06 06:07:57] INFO - Connected and authenticated to node9.
[2015-09-06 06:07:57] INFO - Successfully authenticated on node9.
[node9]: weblogic , pid:670
[2015-09-06 06:07:58] INFO - Running task start_web on node10
[2015-09-06 06:07:58] INFO - Connecting to node10:22 (root)
[2015-09-06 06:07:58] INFO - Connected and authenticated to node10.
[2015-09-06 06:07:58] INFO - Successfully authenticated on node10.
[node10]: weblogic , pid:9809
6, 서로 다른 파일을 서로 다른 웹 서비스 노드에 나누어 보내는 것은 동기화 업로드를 통해 다음과 같이 할 수 있다.
[root@localhost rex]# rex deploy_file
[2015-09-06 06:13:36] INFO - Running task deploy_file on node1
[2015-09-06 06:13:36] INFO - Connecting to node1:22 (root)
[2015-09-06 06:13:36] INFO - Connected and authenticated to node1.
[2015-09-06 06:13:36] INFO - Successfully authenticated on node1.
[2015-09-06 06:13:37] INFO - Running task deploy_file on node2
[2015-09-06 06:13:37] INFO - Connecting to node2:22 (root)
[2015-09-06 06:13:37] INFO - Connected and authenticated to node2.
[2015-09-06 06:13:37] INFO - Successfully authenticated on node2.
[2015-09-06 06:13:37] INFO - Running task deploy_file on node4
[2015-09-06 06:13:37] INFO - Connecting to node4:22 (root)
[2015-09-06 06:13:37] INFO - Connected and authenticated to node4.
[2015-09-06 06:13:37] INFO - Successfully authenticated on node4.
[2015-09-06 06:13:38] INFO - Running task deploy_shopwap on current connection
[node4]:
[2015-09-06 06:13:38] INFO - Running task deploy_file on node5
[2015-09-06 06:13:38] INFO - Connecting to node5:22 (root)
[2015-09-06 06:13:38] INFO - Connected and authenticated to node5.
[2015-09-06 06:13:38] INFO - Successfully authenticated on node5.
[2015-09-06 06:13:39] INFO - Running task deploy_gerenwap on current connection
[node5]:
[2015-09-06 06:13:39] INFO - Running task deploy_file on node6
[2015-09-06 06:13:39] INFO - Connecting to node6:22 (root)
[2015-09-06 06:13:40] INFO - Connected and authenticated to node6.
[2015-09-06 06:13:40] INFO - Successfully authenticated on node6.
[2015-09-06 06:13:40] INFO - Running task deploy_appwap on current connection
[node6]:
[2015-09-06 06:13:40] INFO - Running task deploy_file on node7
[2015-09-06 06:13:40] INFO - Connecting to node7:22 (root)
[2015-09-06 06:13:41] INFO - Connected and authenticated to node7.
[2015-09-06 06:13:41] INFO - Successfully authenticated on node7.
[2015-09-06 06:13:41] INFO - Running task deploy_geren on current connection
[node7]:
[2015-09-06 06:13:42] INFO - Running task deploy_file on node8
[2015-09-06 06:13:42] INFO - Connecting to node8:22 (root)
[2015-09-06 06:13:42] INFO - Connected and authenticated to node8.
[2015-09-06 06:13:42] INFO - Successfully authenticated on node8.
[2015-09-06 06:13:42] INFO - Running task deploy_chaoshi on current connection
[node8]:
[2015-09-06 06:13:43] INFO - Running task deploy_file on node9
[2015-09-06 06:13:43] INFO - Connecting to node9:22 (root)
[2015-09-06 06:13:43] INFO - Connected and authenticated to node9.
[2015-09-06 06:13:43] INFO - Successfully authenticated on node9.
[2015-09-06 06:13:43] INFO - Running task deploy_quanguo on current connection
[node9]:
[2015-09-06 06:13:44] INFO - Running task deploy_file on node10
[2015-09-06 06:13:44] INFO - Connecting to node10:22 (root)
[2015-09-06 06:13:44] INFO - Connected and authenticated to node10.
[2015-09-06 06:13:44] INFO - Successfully authenticated on node10.
[2015-09-06 06:13:44] INFO - Running task deploy_boss on current connection
[node10]:
7. 만약에 Rex를 배치한 시스템의 성능이 비교적 높다면 관리하는 노드가 매우 많다. 여러 라인을 통해 연결하고 싶은 각 노드는parallelism 파라미터를 설정할 수 있다. 예를 들어 내가 최대치parallelism'max'로 설정한 경우.최대 값은 연결할 노드 수에 따라 달라집니다. 기본값은 단일, 즉 항상 하나의 연결입니다.예를 들어 내 테스트에서 10개의 노드 서버를 연결하려면 이 파라미터를 설정하지 않은 상태에서 다음과 같다.
[root@localhost rex]# rex current_time
[2015-09-06 06:22:30] INFO - Running task current_time on node1
[2015-09-06 06:22:30] INFO - Connecting to node1:22 (root)
[2015-09-06 06:22:30] INFO - Connected and authenticated to node1.
[2015-09-06 06:22:30] INFO - Successfully authenticated on node1.
Sun Sep 6 18:22:20 CST 2015
[2015-09-06 06:22:31] INFO - Running task current_time on node2
[2015-09-06 06:22:31] INFO - Connecting to node2:22 (root)
[2015-09-06 06:22:31] INFO - Connected and authenticated to node2.
[2015-09-06 06:22:31] INFO - Successfully authenticated on node2.
Sun Sep 6 18:22:30 CST 2015
[2015-09-06 06:22:31] INFO - Running task current_time on node4
[2015-09-06 06:22:31] INFO - Connecting to node4:22 (root)
[2015-09-06 06:22:31] INFO - Connected and authenticated to node4.
[2015-09-06 06:22:31] INFO - Successfully authenticated on node4.
Sun Sep 6 18:23:14 CST 2015
[2015-09-06 06:22:32] INFO - Running task current_time on node5
[2015-09-06 06:22:32] INFO - Connecting to node5:22 (root)
[2015-09-06 06:22:32] INFO - Connected and authenticated to node5.
[2015-09-06 06:22:32] INFO - Successfully authenticated on node5.
Sun Sep 6 18:23:14 CST 2015
[2015-09-06 06:22:33] INFO - Running task current_time on node6
[2015-09-06 06:22:33] INFO - Connecting to node6:22 (root)
[2015-09-06 06:22:33] INFO - Connected and authenticated to node6.
[2015-09-06 06:22:33] INFO - Successfully authenticated on node6.
Sun Sep 6 18:23:09 CST 2015
[2015-09-06 06:22:34] INFO - Running task current_time on node7
[2015-09-06 06:22:34] INFO - Connecting to node7:22 (root)
[2015-09-06 06:22:34] INFO - Connected and authenticated to node7.
[2015-09-06 06:22:34] INFO - Successfully authenticated on node7.
Sun Sep 6 18:23:46 CST 2015
[2015-09-06 06:22:34] INFO - Running task current_time on node8
[2015-09-06 06:22:34] INFO - Connecting to node8:22 (root)
[2015-09-06 06:22:35] INFO - Connected and authenticated to node8.
[2015-09-06 06:22:35] INFO - Successfully authenticated on node8.
Sun Sep 6 18:25:22 CST 2015
[2015-09-06 06:22:35] INFO - Running task current_time on node9
[2015-09-06 06:22:35] INFO - Connecting to node9:22 (root)
[2015-09-06 06:22:35] INFO - Connected and authenticated to node9.
[2015-09-06 06:22:35] INFO - Successfully authenticated on node9.
Sun Sep 6 18:23:48 CST 2015
[2015-09-06 06:22:36] INFO - Running task current_time on node10
[2015-09-06 06:22:36] INFO - Connecting to node10:22 (root)
[2015-09-06 06:22:36] INFO - Connected and authenticated to node10.
[2015-09-06 06:22:36] INFO - Successfully authenticated on node10.
Sun Sep 6 18:25:23 CST 2015
이런 상황에서 하나하나 조작을 하게 됩니다.최대치를 설정한 경우 내 서버가 10대이기 때문에 (이 파라미터도 숫자를 지정할 수 있다) 나는 max로 직접 설정하여 실행한 후 다음과 같다.
[root@localhost rex]# rex current_time
[2015-09-06 06:25:25] INFO - Running task current_time on node2
[2015-09-06 06:25:25] INFO - Connecting to node2:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node1
[2015-09-06 06:25:25] INFO - Connecting to node1:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node4
[2015-09-06 06:25:25] INFO - Connecting to node4:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node5
[2015-09-06 06:25:25] INFO - Connecting to node5:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node7
[2015-09-06 06:25:25] INFO - Connecting to node7:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node8
[2015-09-06 06:25:25] INFO - Connecting to node8:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node6
[2015-09-06 06:25:25] INFO - Connecting to node6:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node9
[2015-09-06 06:25:25] INFO - Connecting to node9:22 (root)
[2015-09-06 06:25:25] INFO - Running task current_time on node10
[2015-09-06 06:25:25] INFO - Connecting to node10:22 (root)
[2015-09-06 06:25:25] INFO - Connected and authenticated to node2.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node1.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node2.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node1.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node4.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node7.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node8.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node10.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node9.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node5.
[2015-09-06 06:25:25] INFO - Connected and authenticated to node6.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node4.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node10.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node8.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node6.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node5.
[2015-09-06 06:25:25] INFO - Successfully authenticated on node7.
[2015-09-06 06:25:26] INFO - Successfully authenticated on node9.
Sun Sep 6 18:25:24 CST 2015
Sun Sep 6 18:25:15 CST 2015
Sun Sep 6 18:28:12 CST 2015
Sun Sep 6 18:28:12 CST 2015
Sun Sep 6 18:26:08 CST 2015
Sun Sep 6 18:26:08 CST 2015
Sun Sep 6 18:26:01 CST 2015
Sun Sep 6 18:26:38 CST 2015
Sun Sep 6 18:26:38 CST 2015
속도가 매우 빠릅니다. 물론 실제 생산에서는 시스템의 부하 능력에 따라 네트워크 상황에 따라 서비스 노드의 수량을 관리하여 적당한 값을 설정할 수 있습니다.
연결 시간 초과 스레드 수 인증 로그인 방식 서버 정보 설정, 파일 조작, 시스템 서비스 관리, 파일 관리 등은 모두 Rexfile에서 정의할 수도 있고 모듈로 정의할 수도 있다.rex는 템플릿 기능도 제공하고 구체적으로는 아직 연구 중이다.후속 업데이트가 계속됩니다...
rex를 배울 때perldoc 문서를 진지하게 보십시오. 새로운 버전에서 함수가 제거되었을 수도 있습니다. rex의 관리는 매우 간단합니다. ssh를 통해 연결하고 명령을 통해 상대방의 서버를 관리하는 것입니다.각종 명령과 모듈은perldoc Rex::Commands를 통해 볼 수 있으며 기본적으로 소개된 것도 매우 섬세합니다. 그리고 실험을 통해 여러 가지 실천을 하면 곧 습득할 수 있습니다!
모든 연결 작업이 실패하면 관련 정보를 출력합니다. 정보에 따라 오류의 원인을 조사할 수 있습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.