class=
"se-preview-section-delimiter">
div>
[root@VM_27_195_centos logstash-5.5.1]# bin/logstash -f jdbc.conf
等上大约半分钟(没办法,买的虚机配置很低, 只有1G的内存), 开始工作:
![这里写图片描述](http://img.blog.csdn.net/20170802114003824?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2ltb25saW5iaW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
系统会每一秒钟执行一次, 在elasticsearch里面执行:
<div class="se-preview-section-delimiter">div>
[root@VM_27_195_centos ~]# curl http://localhost:9200/mysql01/_search?pretty
会显示已经导入的记录:
<div class="se-preview-section-delimiter">div>
{
“took” : 120,
“timed_out” : false,
“_shards” : {
“total” : 5,
“successful” : 5,
“failed” : 0
},
“hits” : {
“total” : 7,
“max_score” : 1.0,
“hits” : [
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “5”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.220Z”,
“name” : “linzhongyue”,
“@version” : “1”,
“id” : 5,
“type” : “jdbc”,
“age” : 81
}
},
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “2”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.218Z”,
“name” : “wuraorao”,
“@version” : “1”,
“id” : 2,
“type” : “jdbc”,
“age” : 36
}
},
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “4”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.219Z”,
“name” : “zouwangbei”,
“@version” : “1”,
“id” : 4,
“type” : “jdbc”,
“age” : 5
}
},
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “6”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.220Z”,
“name” : “zouyong”,
“@version” : “1”,
“id” : 6,
“type” : “jdbc”,
“age” : 33
}
},
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “1”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.218Z”,
“name” : “simon”,
“@version” : “1”,
“id” : 1,
“type” : “jdbc”,
“age” : 43
}
},
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “7”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.223Z”,
“name” : “hanxiaodong”,
“@version” : “1”,
“id” : 7,
“type” : “jdbc”,
“age” : 44
}
},
{
“_index” : “mysql01”,
“_type” : “jdbc”,
“_id” : “3”,
“_score” : 1.0,
“_source” : {
“@timestamp” : “2017-08-02T03:11:00.219Z”,
“name” : “lingwangnan”,
“@version” : “1”,
“id” : 3,
“type” : “jdbc”,
“age” : 6
}
}
]
}
}
“`
测试结果: 增加和更改MariaDB中的原表,都可以在ES中反馈出来,但如果是删除了一条记录,但是在ES该记录仍然存在,只是他的@timestamp不再更行了,见下图:
第二条记录在MariaDB中已经删除了,你可以看到它的时间比上面的记录早3分钟。
[root@VM_27_195_centos ~]
会显示已经导入的记录:
{
"took" : 120,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 7,
"max_score" : 1.0,
"hits" : [
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.220Z",
"name" : "linzhongyue",
"@version" : "1",
"id" : 5,
"type" : "jdbc",
"age" : 81
}
},
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.218Z",
"name" : "wuraorao",
"@version" : "1",
"id" : 2,
"type" : "jdbc",
"age" : 36
}
},
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.219Z",
"name" : "zouwangbei",
"@version" : "1",
"id" : 4,
"type" : "jdbc",
"age" : 5
}
},
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.220Z",
"name" : "zouyong",
"@version" : "1",
"id" : 6,
"type" : "jdbc",
"age" : 33
}
},
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.218Z",
"name" : "simon",
"@version" : "1",
"id" : 1,
"type" : "jdbc",
"age" : 43
}
},
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "7",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.223Z",
"name" : "hanxiaodong",
"@version" : "1",
"id" : 7,
"type" : "jdbc",
"age" : 44
}
},
{
"_index" : "mysql01",
"_type" : "jdbc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2017-08-02T03:11:00.219Z",
"name" : "lingwangnan",
"@version" : "1",
"id" : 3,
"type" : "jdbc",
"age" : 6
}
}
]
}
}
测试结果: 增加和更改MariaDB中的原表,都可以在ES中反馈出来,但如果是删除了一条记录,但是在ES该记录仍然存在,只是他的@timestamp不再更行了,见下图:
第二条记录在MariaDB中已经删除了,你可以看到它的时间比上面的记录早3分钟。