2014年12月1日星期一

Re: [PerlChina] PerlChina Advent Day 1

使用rex,可能会遇到一个问题:
如何获得命令行参数? 参考。




2014-12-01 18:39 GMT-08:00 Fayland Lam <fayland@gmail.com>:
Rexify

=for advent_year 2014

=for advent_day 1

=for advent_title Rexify

=for advent_author Chenlin Rao

=encoding utf8

Perl 一直以来都是系统管理员们的好朋友。早在L<09 年的 advent Day 5|../../2009/05/SSHBatch.pod> 上,就介绍过一个 Perl 工具叫 L<SSH::Batch>。随着时代变迁,更完备的集群架构管理工具 Puppet、SaltStack、Ansible 等大行其道。在这方面,Perl 社区也出现了新的项目,这就是 (R)?ex 项目。

(R)?ex 项目的设计以配置管理和部署为核心。这个 (R)? ,可以是 SSH 到远程主机,可以是直接到本地主机,也可以是调用 API 控制各大云平台。

(R)?ex 本身的 DSL 设计,是仿照了 Puppet 的语法。(作者本身是德国一位 IDC 运维,本身手上也有 Puppet 环境)

=head2 资源定义语法示例

=begin code

user "ubuntu";
group frontend => "frontend[01..05]";
sudo TRUE;

desc "Prepare Frontend Server";
task "prepare", group => "frontend", sub {
  pkg "apache2",
    ensure => "latest";

  service "apache2",
    ensure => "started";
};

desc "Keep Configuration in sync";
task "configure", group => "frontend", sub {
  prepare();

  file "/etc/apache2/apache2.conf",
    source    => "files/etc/apache2/apache2.conf",
    on_change => sub { service apache2 => "reload"; };
};

=end code

非常一目了然,之前没用过的人也可以一眼看懂这段配置是要干嘛——安装最新的 apache 软件包,启动 apache 服务,传输本地的 "files/etc/apache2/apache2.conf" 到远程主机的 "/etc/apache2/apache2.conf",然后重载 apache 服务。

=head2 即时运行

如果 Rex 止于这种程度,那么我就建议大家直接使用 Puppet 好了。Puppet 的一个问题:无法即时生效。在 Rex 中,实际就是一个很类似之前 SSH::Batch 的用法:

=begin code

$ rex -qw -H "frontend[01..15] middleware[01..05] db[01..04]" -e "say run 'uptime'"

=end code

=head2 云平台 API

云平台,其实也就是一种 Rex 内部资源,所以其使用方式跟普通的 pkg/file/service/cron/ps/tail 等资源并无不同:

=begin code

use Rex::Commands::Cloud;

user "root";
public_key "/path/to/your/just/created/amazon-public.key";
private_key "/path/to/your/just/downloaded/amazon-private-key.pem";

my $access_key = "your-access-key";
my $secret_access_key = "your-secret-key";

cloud_service "Amazon";
cloud_auth "$access_key", "$secret_access_key";

task "create", sub {
   cloud_instance create => { 
            image_id => "ami-02103876",
            name     => "static01",
            key      => "dev-test",
         };
};

=end code

大家可能注意到上面配置中多了一行 C<use Rex::Commands::Cloud>,事实上大家可以任意自己扩展 Rex::Commands 接口,实现自己的资源(名字空间叫 Rex::Commands 而不是 Rex::Resources,倒也可以说明 Rex 的实质,依然是一个命令执行式的工具)。

事实上,Rex 有专门的 modules.rexify.org 来收集发布各种第三方资源。之前,就有国内的朋友制作了 Rex::Commands::Zabbix2 模块。

=head2 web 界面

任何自动化工具最终都会走向 web 界面展示。Rex 最近用 Mojolicious 框架完成了官方的 JobControl 界面。这里就不占用篇幅了,大家可以自行访问官网文档:L<http://www.rexify.org/howtos/jobcontrol/create_project.html>

最后值得说明的是:Rex 官网有中文同步翻译,地址见 L<http://rex.perl-china.com>

http://perlchina-advent.herokuapp.com/calendar/2014/01/


Thanks

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

[PerlChina] perl北京聚会——2014年12月7日

嗨,各位:

本周末北京举行个perl小聚会。主要由三斗讲一下elasticsearch的ELK套件。其他演讲尚未确定,欢迎自荐。剩下的是讨论环节。欢迎大家参加。

时间:12月7日14:00 —— 18:00
地点:北京市朝阳区中远幸福大厦A座14层 (地铁10号线亮马桥站出来,往北走一点(约300米),路西就是。)
联系人: Achilles Xu 18611952631

最好能先跟邮件或贴报名,当然也欢迎空降。


Achilles Xu
formalin14@gmail.com



--
您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com
通过以下网址访问此论坛:http://groups.google.com/group/perlchina
要查看更多选项,请访问 https://groups.google.com/d/optout

[PerlChina] PerlChina Advent Day 02

# Lingua::Identify::CLD

[Lingua::Identify::CLD](https://metacpan.org/pod/Lingua::Identify::CLD) 使用 Chrome 的语言识别功能来得到文字或者网页的语言。

它的使用超级简单

    use Lingua::Identify::CLD;

    my $cld = Lingua::Identify::CLD->new();
    my @lang = $cld->identify("Text"); # 'ENGLISH', 'en', 100, 1
    # $lang[0] -> language name
    # $lang[1] -> language id
    # $lang[2] -> confidence
    # $lang[3] -> is_reliable (bool)

## 适用场景

 * 判断某网页 url 是哪国语言,类似 Google Chrome 的判断

        use LWP::Simple;
        use Lingua::Identify::CLD;
        my $cld = Lingua::Identify::CLD->new(isPlainText => 0);
        my @langs = $cld->identify(get('http://www.163.com/'));
        print join(", ", @langs); # CHINESE, zh-CN, 97, 1

## 命令行

*identify-cld*

    ➜  mojo-advent git:(master) ✗ cat articles/2014/02/Lingua-Identify-CLD.md | identify-cld
    STDIN: CHINESE

## 作者
[Fayland Lam](http://fayland.me/)


Thanks

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

[PerlChina] PerlChina Advent Day 1

Rexify

=for advent_year 2014

=for advent_day 1

=for advent_title Rexify

=for advent_author Chenlin Rao

=encoding utf8

Perl 一直以来都是系统管理员们的好朋友。早在L<09 年的 advent Day 5|../../2009/05/SSHBatch.pod> 上,就介绍过一个 Perl 工具叫 L<SSH::Batch>。随着时代变迁,更完备的集群架构管理工具 Puppet、SaltStack、Ansible 等大行其道。在这方面,Perl 社区也出现了新的项目,这就是 (R)?ex 项目。

(R)?ex 项目的设计以配置管理和部署为核心。这个 (R)? ,可以是 SSH 到远程主机,可以是直接到本地主机,也可以是调用 API 控制各大云平台。

(R)?ex 本身的 DSL 设计,是仿照了 Puppet 的语法。(作者本身是德国一位 IDC 运维,本身手上也有 Puppet 环境)

=head2 资源定义语法示例

=begin code

user "ubuntu";
group frontend => "frontend[01..05]";
sudo TRUE;

desc "Prepare Frontend Server";
task "prepare", group => "frontend", sub {
  pkg "apache2",
    ensure => "latest";

  service "apache2",
    ensure => "started";
};

desc "Keep Configuration in sync";
task "configure", group => "frontend", sub {
  prepare();

  file "/etc/apache2/apache2.conf",
    source    => "files/etc/apache2/apache2.conf",
    on_change => sub { service apache2 => "reload"; };
};

=end code

非常一目了然,之前没用过的人也可以一眼看懂这段配置是要干嘛——安装最新的 apache 软件包,启动 apache 服务,传输本地的 "files/etc/apache2/apache2.conf" 到远程主机的 "/etc/apache2/apache2.conf",然后重载 apache 服务。

=head2 即时运行

如果 Rex 止于这种程度,那么我就建议大家直接使用 Puppet 好了。Puppet 的一个问题:无法即时生效。在 Rex 中,实际就是一个很类似之前 SSH::Batch 的用法:

=begin code

$ rex -qw -H "frontend[01..15] middleware[01..05] db[01..04]" -e "say run 'uptime'"

=end code

=head2 云平台 API

云平台,其实也就是一种 Rex 内部资源,所以其使用方式跟普通的 pkg/file/service/cron/ps/tail 等资源并无不同:

=begin code

use Rex::Commands::Cloud;

user "root";
public_key "/path/to/your/just/created/amazon-public.key";
private_key "/path/to/your/just/downloaded/amazon-private-key.pem";

my $access_key = "your-access-key";
my $secret_access_key = "your-secret-key";

cloud_service "Amazon";
cloud_auth "$access_key", "$secret_access_key";

task "create", sub {
   cloud_instance create => { 
            image_id => "ami-02103876",
            name     => "static01",
            key      => "dev-test",
         };
};

=end code

大家可能注意到上面配置中多了一行 C<use Rex::Commands::Cloud>,事实上大家可以任意自己扩展 Rex::Commands 接口,实现自己的资源(名字空间叫 Rex::Commands 而不是 Rex::Resources,倒也可以说明 Rex 的实质,依然是一个命令执行式的工具)。

事实上,Rex 有专门的 modules.rexify.org 来收集发布各种第三方资源。之前,就有国内的朋友制作了 Rex::Commands::Zabbix2 模块。

=head2 web 界面

任何自动化工具最终都会走向 web 界面展示。Rex 最近用 Mojolicious 框架完成了官方的 JobControl 界面。这里就不占用篇幅了,大家可以自行访问官网文档:L<http://www.rexify.org/howtos/jobcontrol/create_project.html>

最后值得说明的是:Rex 官网有中文同步翻译,地址见 L<http://rex.perl-china.com>

http://perlchina-advent.herokuapp.com/calendar/2014/01/


Thanks

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

2014年11月30日星期日

[PerlChina] 2014年12月14日上海地区Perl爱好者聚会

各位,

上海地区Perl爱好者好久没有聚会了,计划在2014年12月14日10点到13点办一次Perl 爱好者聚会,把上海地区的Perl活动恢复起来。本次活动的内容主要是大家认识一下。基本消费是50元,包括茶和中午的一份快餐。特别欢迎还在上学的同学参加,可以免单。

活动地点基本定在上海体育场 4号地铁站附近,同时方便浦西和浦东的朋友。

请有意参加本次活动的Perl 爱好者通过邮件 xu.hejun@163.com 联系我。

请在邮件中告知 姓名和手机号,方便及时通知活动信息。

我会在或者活动前三天通知活动的具体地址。

另外,也请在perlchian.org上有帐号的朋友将本信息转发到perlchina.org 的上海版上,让更多上海朋友知道。

-Jack

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

2014年11月13日星期四

Re: [PerlChina] perlchina@googlegroups.com 的简略摘要 - “1 个主题”有 9 个帖子

请不要回复摘要

在 2014年11月14日 上午9:52,郑书磊 <sulerzh@sina.com>写道:

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout

回复:[PerlChina] perlchina@googlegroups.com 的简略摘要 - “1 个主题”有 9 个帖子

--
您收到此邮件是因为您订阅了Google网上论坛中的"PerlChina Mongers 讨论组"论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到perlchina+unsubscribe@googlegroups.com
要发帖到此论坛,请发送电子邮件至perlchina@googlegroups.com
通过http://groups.google.com/group/perlchina访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout