参考文档:
windows下安装运行logstash5.5.1:
https://my.oschina.net/u/2601303/blog/1501588
windows下安装logstash:
https://blog.csdn.net/fenglailea/article/details/56282414
Logstash讲解与实战应用:
http://blog.51cto.com/tchuairen/1840596
Logstash使用详解:
https://blog.csdn.net/sangyongjia/article/details/52839402
Logstash使用详解:
https://blog.csdn.net/wang_quan_li/article/details/52585134
windows 下 logstash 安装启动:https://blog.csdn.net/xuyanhuiwelcome/article/details/79244867
elasticsearch-jdbc实现MySQL同步到ElasticSearch深入详解:(个人推荐仔细阅读)
https://blog.csdn.net/laoyang360/article/details/51694519
1 环境搭建
1.1 下载
https://www.elastic.co/cn/downloads/logstash
1.2 解压
1.3 运行
相关错误:
解决办法:https://blog.csdn.net/awj3584/article/details/79715907
在logstash-6.2.4\bin下的logstash.bat,找到以下内容:
给%CLASSPATH%加上双引号,内容如下:
保存重启,再次报错:
命令行输入:logstash–help:
Use the given string as the configuration data. Same syntax as the config file.
If no input is specified, then the following is used as the default input:
"input { stdin { type => stdin } }"
and if no output is specified, then the following is used as the default output:
"output { stdout { codec => rubydebug } }"
If you wish to use both defaults, please use the empty string for the '-e' flag.
命令行输入: logstash–e “”
1.4 配置
https://blog.csdn.net/plei_yue/article/details/78317980
logstash-jdbc-input:对于logstash6.x版本他自身已经集成了这个插件,不需要我们去单独安装,直接使用即可
1.5 测试
在bin目录下创建conf文件夹,并添加jdbc.conf文件:
编辑jdbc.conf文件:
在命令行界面输入:G:\ElasticSearch\logstash-6.2.4\bin>logstash-f conf/jdbc.conf
报错:
failedto execute action
Expectedone of #, input, filter, output at line 1, column 1 (byte 1) after
解决办法如下:https://blog.csdn.net/Crazy_T_B/article/details/79422602
在命令行界面输入:G:\ElasticSearch\logstash-6.2.4\bin>logstash-f conf/jdbc.conf –t
测试配置文件是否正常:
更改conf/jdbc.conf的文件格式:
在命令行界面输入:G:\ElasticSearch\logstash-6.2.4\bin>logstash-f conf/jdbc.conf –t
测试配置文件是否正常:
PS:没有报错
2 ES同步Mysql
2.1 创建测试表
2.2 下载mysql驱动包
下载mysql-connector-java:https://dev.mysql.com/downloads/connector/j/
2.3 解压
2.4 修改jdbc.conf
input {
stdin {
}
jdbc {
# mysql 数据库链接,es为数据库名
jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/es"
# 用户名和密码
jdbc_user => "root"
jdbc_password => "123456"
# 驱动
jdbc_driver_library =>
"G:/ElasticSearch/mysql-connector-java-8.0.11/mysql-connector-java-8.0.11.jar"
# 驱动类名
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
# 执行的sql 文件路径+名称
statement_filepath => "G:/ElasticSearch/logstash-6.2.4/bin/conf/test.sql"
# 设置监听间隔 各字段含义(由左至右)分、时、天、月、年,全部为*默认含义为每分钟都更新
schedule => "* * * * *"
# 设定ES索引类型
type => "content"
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
#ES索引名称(自己定义的)
index => "cmscontent"
#自增ID编号
document_id => "%{id}"
}
stdout {
codec => json_lines
}
}
2.5 增加test.sql
其所在的文件夹为
内容为:
select * from test
2.6 启动logstash
在命令行界面输入:G:\ElasticSearch\logstash-6.2.4\bin>logstash-f conf/jdbc.conf
报错:
The server time zone value ‘XXXXXX’ is unrecognized or representsmore than one time zone.
解决问题如下:http://www.bubuko.com/infodetail-1903098.html
这是由于数据库和系统时区差异所造成的,在连接数据库的url后加上 serverTimezone=GMT 即可。如:
jdbc:mysql://localhost:3306/es?characterEncoding=utf8&useSSL=true&serverTimezone=GMT
2.7 测试
除了红色框住的内容没有显示,其他的都在ES上看得到,不知道这是不是错误,知道结果并在有空的时候更新!!