后台启动elasticsearch
elasticsearch -d
下载logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.10.1-linux-x86_64.tar.gz
tar zxvf logstash-7.10.1-linux-x86_64.tar.gz
cd logstash-7.10.1
后台启动logstash并且指定配置
nohup /usr/local/logstash-7.10/bin/logstash -f /usr/local/logstash-7.10/config/logstash-mysql.conf &
创建 logstash-mysql.conf配置文件
input {
jdbc {
#上海时间
jdbc_default_timezone => "Asia/Shanghai"
jdbc_driver_library => "/usr/local/logstash-7.10/mysql-connector-java-8.0.12.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/video?characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false"
jdbc_user => "root"
jdbc_password => "root"
#设置监听间隔 名字段含义(由左到右)分、时、天、月、年,全为* 默认含义每分钟执行, 如果要每秒执行设置为(* * * * * * )
schedule => "* * * * *"
clean_run => true
use_column_value => true
tracking_column => "id"
tracking_column_type => "numeric"
last_run_metadata_path => "/root/.logstash_jdbc_last_run"
statement => "SELECT * FROM video WHERE id > :sql_last_value AND update_time < NOW() ORDER BY id LIMIT 50000"
}
}
output {
elasticsearch {
index => "dsp_video" #索引名称
document_type => "_doc"
document_id => "%{id}" #自增ID 需要关联的数据库中有一个id字段,对应索引的id号
hosts => [ "http://127.0.0.1:9200" ] #ES 的IP 地址及端口
}
stdout {
codes => json_lines #JSON 格式输出
}
}