使用logstash同步mysql數(shù)據(jù)到elasticsearch實(shí)現(xiàn)
更新時(shí)間:2022年12月14日 14:15:52 作者:大數(shù)據(jù)技術(shù)派
這篇文章主要為大家介紹了使用logstash同步mysql數(shù)據(jù)到elasticsearch實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
mysql建表test;

安裝logstash(跟es版本一致)
# 下載 wget https://repo.huaweicloud.com/logstash/7.14.2/logstash-7.14.2-linux-x86_64.tar.gz # 解壓 tar -zxvf logstash-7.14.2-linux-x86_64.tar.gz # 需要mysql-connector-java-5.1.40.jar,隨便放到比如目錄 # /var/lib/hadoop-hdfs/logstash-7.14.2/lib/mysql-connector-java-5.1.40.jar
新建es索引test
curl -u elastic:changeme -X PUT http://192.168.20.130:9200/test -H 'Content-Type: application/json' -d'
{
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
},
"mappings" : {
"properties": {
"id": {
"type" : "long"
},
"type": {
"type": "keyword"
},
"keyword_1": {
"type": "text",
"analyzer" : "ik_smart"
},
"keyword_2": {
"type": "text",
"analyzer" : "ik_smart"
},
"keyword_3": {
"type": "text",
"analyzer" : "ik_smart"
},
"data": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
},
"updated_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
}
}
}
}'
編輯配置文件
vim ~/script/logstash/logstash_mysql2es.conf
input {
stdin{
}
jdbc{
# 連接的數(shù)據(jù)庫地址和數(shù)據(jù)庫,指定編碼格式,禁用ssl協(xié)議,設(shè)定自動(dòng)重連
# 此處10.112.103.2為MySQL所在IP地址,也是elastic search所在IP地址
jdbc_connection_string => "jdbc:mysql://192.168.13.28:3306/test?characterEncoding=UTF-8&useSSL=FALSE&autoReconnect=true"
#數(shù)據(jù)庫用戶名
jdbc_user => "root"
# 數(shù)據(jù)庫用戶名對(duì)應(yīng)的密碼
jdbc_password => "root"
# jar包存放位置
jdbc_driver_library => "/var/lib/hadoop-hdfs/logstash-7.14.2/lib/mysql-connector-java-5.1.40.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_default_timezone => "Asia/Shanghai"
jdbc_paging_enabled => "true"
jdbc_page_size => "320000"
lowercase_column_names => false
statement => "select id, type, tags, title from test"
}
}
filter {
# 移除無關(guān)的字段
mutate {
remove_field => ["@version", "@timestamp"]
}
}
output {
elasticsearch {
hosts => ["http://192.168.20.130:9200"]
user => "elastic"
password => "changeme"
index => "test"
document_type => "_doc"
# 將字段type和id作為文檔id
document_id => "%{type}_%{id}"
}
stdout {
codec => json_lines
}
}
重要配置參數(shù)說明:
remove_field => ["@version", "@timestamp"]: 默認(rèn)logstash會(huì)添加這兩個(gè)字段,這里去掉;document_id => "%{type}_%{id}": 將兩個(gè)字段拼接作為es的文檔id;
啟動(dòng)任務(wù)
./logstash-7.14.2/bin/logstash -f script/logstash/logstash_mysql2es.conf
參考資料
以上就是使用logstash同步mysql數(shù)據(jù)到elasticsearch實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于logstash mysql數(shù)據(jù)同步elasticsearch的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:
- MySQL數(shù)據(jù)同步Elasticsearch的4種方案
- logstash將mysql數(shù)據(jù)同步到elasticsearch方法詳解
- 使用canal監(jiān)控mysql數(shù)據(jù)庫實(shí)現(xiàn)elasticsearch索引實(shí)時(shí)更新問題
- Mysql到Elasticsearch高效實(shí)時(shí)同步Debezium實(shí)現(xiàn)
- 詳解Mysql如何實(shí)現(xiàn)數(shù)據(jù)同步到Elasticsearch
- 用python簡單實(shí)現(xiàn)mysql數(shù)據(jù)同步到ElasticSearch的教程
- MySQL 與 Elasticsearch 數(shù)據(jù)不對(duì)稱問題解決辦法
- 如何在Elasticsearch中啟用和使用SQL功能
相關(guān)文章
Maven方式構(gòu)建SpringBoot項(xiàng)目的實(shí)現(xiàn)步驟(圖文)
Maven是一個(gè)強(qiáng)大的項(xiàng)目管理工具,可以幫助您輕松地構(gòu)建和管理Spring Boot應(yīng)用程序,本文主要介紹了Maven方式構(gòu)建SpringBoot項(xiàng)目的實(shí)現(xiàn)步驟,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09
Map集合中獲取key-value值的實(shí)現(xiàn)方法
這篇文章主要介紹了Map集合中獲取key-value值的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
java實(shí)現(xiàn)實(shí)時(shí)通信聊天程序
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)實(shí)時(shí)通信聊天程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06

