简体   繁体   English

如何将 gems 添加到 Logstash

[英]How to add gems into Logstash

I am running Logstash 1.4.1, comparing to the latest, I can't find anywhere in my installation folders contains gem information (versus the latest code in github has those gembag.rb, Gemfile etc..)我正在运行 Logstash 1.4.1,与最新版本相比,我在我的安装文件夹中找不到任何包含 gem 信息的地方(而 github 中的最新代码有那些 gembag.rb、Gemfile 等。)

My current issue is I need to use several gems that Logstash doesn't have out of box, simply require 'gemname' seems doesn't work.我当前的问题是我需要使用 Logstash 没有开箱即用的几个 gem,只require 'gemname'似乎不起作用。 Could anyone direct me to the readings that explains how to add these 3rd party gems or show me some sample codes which can do this.任何人都可以指导我阅读解释如何添加这些 3rd 方 gem 的阅读材料,或者向我展示一些可以做到这一点的示例代码。

Thanks very much!非常感谢!

cd /opt/logstash
env GEM_HOME=vendor/bundle/jruby/1.9 GEM_PATH="" java -jar vendor/jar/jruby-complete-1.7.11.jar -S gem install gemname

If you're installing a local gem file, put the path to the file in GEM_PATH.如果您要安装本地 gem 文件,请将文件路径放在 GEM_PATH 中。

This is what worked for me in logstash 2.0.这就是在 logstash 2.0 中对我有用的方法。

env GEM_HOME=/opt/logstash/vendor/bundle/jruby/1.9 /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION

Then I had to edit /opt/logstash/Gemfile to include the line:然后我必须编辑/opt/logstash/Gemfile以包含以下行:

gem "PACKAGE_NAME", "PACKAGE_VERSION"

I know we also did a yum install ruby-devel at some point along the way, but I don't remember if that was needed for this to work.我知道我们在此过程中的某个时候也进行了yum install ruby-devel ,但我不记得是否需要这样做才能正常工作。

I think the simplest way is:我认为最简单的方法是:

/usr/share/logstash/bin/ruby -S gem install <gem-name>

or或者

/opt/logstash/bin/ruby -S gem install <gem-name>

Work for me on recent version of logstash...在最新版本的logstash上为我工作...

For example:例如:

env GEM_HOME=vendor/bundle/jruby/1.9 vendor/jruby/bin/jruby vendor/jruby/bin/gem install zookeeper -v 1.4.11 -V

edit Gemfile:编辑 Gemfile:

gem "zookeeper", "1.4.11"

Logstash version agnostic script (can also be used for logstash 6.0.0): Logstash版本不可知脚本(也可用于logstash 6.0.0):

env GEM_HOME=$$(echo /usr/share/logstash/vendor/bundle/jruby/*/) /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION

In fact, here is the full script to both install a gem and append package metadata to the gemfile: 实际上,这里是安装gem并将包元数据附加到gemfile的完整脚本:

env GEM_HOME=$$(echo /usr/share/logstash/vendor/bundle/jruby/*/) /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION
echo 'gem \"PACKAGE_NAME\", \"PACKAGE_VERSION\"' >> /usr/share/logstash/Gemfile

Logstash may change JRuby version in the future. Logstash将来可能会更改JRuby版本。 For instance, JRuby 2.3.0 is used in logstash 6.0.0. 例如,JRuby 2.3.0用于logstash 6.0.0。 The script above does not require you to change JRuby version in the path when upgrading logstash. 升级logstash时,上面的脚本不要求您在路径中更改JRuby版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM