安装使用 jruby

1
2
rvm install jruby-9.1.7.0
rvm use jruby-9.1.7.0 --default

安装 bundler

1
gem install bundler

创建项目

用工具生成项目模板

1
logstash-plugin generate --type input --name alioss --path ./

当前目录下创建了一个名为 logstash-input-alioss 的工程,目录结构如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|____CHANGELOG.md
|____CONTRIBUTORS
|____DEVELOPER.md
|____Gemfile
|____Gemfile.lock
|____lib
| |____logstash
| | |____inputs
| | | |____alioss.rb
|____LICENSE
|____logstash-input-alioss.gemspec
|____Rakefile
|____README.md
|____spec
| |____inputs
| | |____alioss_spec.rb

安装依赖

使用 gem 安装 aliyun-sdksnappy 。注意: aliyun-sdk 并未使用最新版本,而是使用 0.3.6, 详情戳这里 issue

1
2
gem install -v 0.3.6 aliyun-sdk
gem install snappy

集成 aliyun-sdk

编辑 logstash-input-alioss.gemspec,添加依赖

1
2
s.add_runtime_dependency 'aliyun-sdk', '~> 0.3.6'
s.add_runtime_dependency 'snappy'

打包工程

1
bundle install

安装插件

安装插件可以分成两种,开发模式、生产模式。参考这里

1. 开发模式

修改 logstash/Gemfile

1
echo 'gem "logstash-input-alioss", :path => "logstash-input-alioss绝对路径"' >> logstash路径/Gemfile

命令行安装

1
logstash-plugin install --no-verify

2. 生产模式

执行下面命令,会在工程下生成 logstash-input-alioss-0.1.0.gem 文件

1
gem build logstash-input-alioss.gemspec

命令行安装 (别急,这个过程可能会需要多等一会)

1
logstash-plugin install /path/to/logstash-input-alioss-0.1.0.gem

3. 检查插件是否安装成功

不论以上哪种方法,安装成功的话都会出现在列表中

1
logstash-plugin list --group input

编写配置文件

alioss.logstash.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
input {
alioss {
endpoint => 'your endpoint'
access_key_id => 'your access_key_id'
access_key_secret => 'your access_key_secret'
bucket => 'your bucket'
interval => 60
codec => json
}
}

output {
stdout {
codec=>rubydebug
}
}

测试插件

1
logstash -f alioss.logstash.conf

介绍一个以 aliyun/oss 做为数据源处理日志的插件

https://github.com/Ryfthink/logstash-input-alioss