Rex - Remote Execution
描述:
Rex 是一个命令行工具执行命令在远程servers,
定义tasks在perl和执行它们在远程服务器
task "task1", sub {
say template("ntpd.conf");
};
task "task2", group=>"myservers", sub {
my $output = run "ld";
say '----------------------';
say $?;
say '----------------------';
say $output;
};
[root@node01 Rex]# rex task2
[2017-05-01 07:04:50] INFO - Running task task2 on 192.168.137.3
----------------------
1
----------------------
[2017-05-01 07:05:01] INFO - All tasks successful on all hosts
[root@node01 Rex]# rex task1
[2017-05-01 07:05:14] INFO - Running task task1 on <local>
aaaaaaaa
bbbbbbbb
cccccccc
111111111
22222222
33333333
Rex 可以用于:
1.利用web 应用到服务器顺序的或者并发的
2.自动执行任务
3.提供 servers使用Rex的内置工具
简介:
[root@node01 Rex]# cat Rexfile
use Rex -feature => ['1.0'];
no strict;
user "root";
private_key "/root/.ssh/id_rsa"; ##私钥
public_key "/root/.ssh/id_rsa.pub"; ##公钥
key_auth;
group myservers => "192.168.137.3";
use Rex -feature => [qw/1.3/];
desc "Show Unix version";
task "uname", group=>"myservers", sub {
say run "uname -a";
};
[root@node01 Rex]# rex uname
[2017-05-01 07:39:25] INFO - Running task uname on 192.168.137.3
Linux node2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[2017-05-01 07:39:36] INFO - All tasks successful on all hosts
类方法:
[root@node01 Rex]# cat Rexfile
use Rex -feature => ['1.0'];
no strict;
use Data::Dumper;
user "root";
private_key "/root/.ssh/id_rsa"; ##私钥
public_key "/root/.ssh/id_rsa.pub"; ##公钥
key_auth;
group myservers => "192.168.137.3";
use Rex -feature => [qw/1.3/];
desc "Show Unix version";
task "uname", group=>"myservers", sub {
say run "uname -a";
#print Dumper( Rex::get_current_connection());
print "
";
print Rex::get_current_connection()->{server};
};
[root@node01 Rex]# rex uname
[2017-05-01 07:48:12] INFO - Running task uname on 192.168.137.3
Linux node2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
192.168.137.3[2017-05-01 07:48:23] INFO - All tasks successful on all hosts