一、背景
1. 生產環境是不能直接聯網的
2. 要給 Logstash 安裝上 logstash-input-jdbc 插件用來讀取 Mysql 數據到 ES 進行全文檢索
3. 聯網環境:VM CentOS7.3 Logstash5.5.2,RPM 安裝
二、原生安裝
# /usr/share/logstash/bin/logstash-plugin install logstash-input-jdbc
Validating logstash-input-jdbc
Installing logstash-input-jdbc
WARNING: can not set Session#timeout=(0) no session context
能看到輸出的任一更新都需要非常久 - 一兩個小時沒反應,幾乎不能完成任務。
三、改鏡像源安裝
辦法:給 Ruby 加上國內的鏡像站:https://gems.ruby-china.org/,替代https://rubygems.org。
可以直接跳到第5步操作。
1. 可選
發現 Elastic 官網 ping 不通,給加上。
# echo "54.235.82.130 artifacts.elastic.co" >> /etc/hosts
2. 安裝Gem並更新
# yum install -y gem
# gem -v
2.0.14.1
# gem update --system
# gem -v
2.6.13
3. 檢查並修改鏡像源
# gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
# gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
https://gems.ruby-china.org/ added to sources
https://rubygems.org/ removed from sources
# cat ~/.gemrc
---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://gems.ruby-china.org/
:update_sources: true
:verbose: true
4. 安裝 bundle 並更改鏡像源
# gem install bundler
# bundle config mirror.https://rubygems.org https://gems.ruby-china.org
上面的步驟方便以後安裝更多插件的時候設置默認鏡像源。
5. 修改 logstash的 gem 鏡像源
# head /usr/share/logstash/Gemfile
# This is a Logstash generated Gemfile.
# If you modify this file manually all comments and formatting will be lost.
source "https://rubygems.org"
gem "logstash-core", :path => "./logstash-core"
......
更改默認的 https://rubygems.org 爲https://gems.ruby-china.org
Gemfile.jruby-1.9.lock文件不用改,會自動更新。
6. 安裝 logstash-input-jdbc
# /usr/share/logstash/bin/logstash-plugin install logstash-input-jdbc
Validating logstash-input-jdbc
Installing logstash-input-jdbc
Installation successful
終於正常的驗證安裝好了,保存在/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-4.2.2。對比下之前之後的速度。
四、打離線包
這裏安裝好了,那麼就可以打個離線的 zip 包,方便生產環境直接安裝。離線包將包含所有依賴的包。
# cd /usr/share/logstash/bin
# ./logstash-plugin prepare-offline-pack --overwrite --output logstash-input-jdbc-4.2.2.zip logstash-input-jdbc
Offline package created at: logstash-input-jdbc-4.2.2.zip
You can install it with this command `bin/logstash-plugin install file:///usr/share/logstash/bin/logstash-input-jdbc-4.2.2.zip`
OK,zip 包搞定,傳到生產上,如同 X-PACK 一樣安裝即可。