安裝logstash-input-jdbc插件,實現數據的插入
1.安裝gem
yum install gem -y
2.替換ruby庫(兩種國內源+淘寶源)
2.1.1替換爲國內源
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l
2.1.2修改配置文件
cd /opt/inst/logstash622/
vi Gemfile
#修改Gemfile文件
#source https://rubygems.org/
httpsvi Gemfile.lockgems.ruby-china.com/
vi Gemfile.lock
#remote: https://rubygems.org/
https://gems.ruby-china.com/
2.2 同上替換ruby爲淘寶源(如果上述替換國內源不成功,可以換此方法)
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
gem sources -l
由於修改ruby鏡像庫爲淘寶庫並沒有成功,這裏就需要修改Gemfile文件裏面的數據源:
cd /opt/inst/logstash622/
vi Gemfile
#修改Gemfile文件
#source https://rubygems.org/
source "https://ruby.taobao.org"
#remote: https://rubygems.org/
remote: https://ruby.taobao.org
3.安裝logstash-input-jdbc
3.1 到logstash的bin目錄下運行下面的命令,查看可用的插件
cd bin
./logstash-plugin list --verbose
3.2 上述操作看到可以使用的logstash-input-jdbc版本是4.3.3,安裝JDBC
unzip logstash-input-jdbc-4.3.3.zip
mv logstash-input-jdbc-4.3.3 /opt/inst/log_jdbc433
cd log_jdbc433/
3.3 配置Gemfile文件
vi Gemfile
source 'https://gems.ruby-china.com/'
4.測試是否成功
4.1 提供數據
需要一個mysql驅動包,sql文件,以及conf配置文件
input {
jdbc {
# mysql jdbc connection string to our backup databse
jdbc_connection_string => "jdbc:mysql://169.254.211.100:3306/test"
# the user we wish to excute our statement as
jdbc_user => "root"
jdbc_password => "root"
# the path to our downloaded jdbc driver
jdbc_driver_library => "/opt/inst/logstash622/sql/mysql-connector-java-5.1.40-bin.jar"
# the name of the driver class for mysql
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
statement_filepath => "/opt/inst/logstash622/sql/logs_20171206.sql"
schedule => "*/1 * * * *"
type => "jdbc"
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
}
output {
elasticsearch {
hosts => "169.254.211.100:9200"
index => "logs_20171206"
document_id => "%{id}"
}
stdout {
codec => json_lines
}
}
4.2 實現logstash把文件寫進mysq數據庫l中
cd /opt/inst/logstash622/bin
./logstash -f /opt/logfiter/mysql.conf