148、使用Logstash从MySQL导入数据到Elasticsearch
程序员文章站
2022-06-11 11:41:21
...
使用Logstash从MySQL导入数据到Elasticsearch
Logstach安装
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
在 /etc/yum.repos.d/ 中创建logstash.repo文件
[logstash-6.x]
name=Elastic repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
执行
sudo yum install logstash
cd /usr/share/logstash/bin/
sudo ./logstash-plugin install logstash-input-jdbc
sudo ./logstash-plugin install logstash-output-elasticsearch
scp mysql-connector-java-8.0.13.tar.gz [email protected]:~/
tar -zxvf mysql-connector-java-8.0.13.tar.gz
从MySQL导入数据到Elasticsearch
创建配置文件logstash_mysql.conf
input{
jdbc {
jdbc_driver_library => "/home/python/mysql-connector-java-8.0.13/mysql-connector-java-8.0.13.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/toutiao?tinyInt1isBit=false"
jdbc_user => "root"
jdbc_password => "mysql"
jdbc_paging_enabled => "true"
jdbc_page_size => "1000"
jdbc_default_timezone =>"Asia/Shanghai"
statement => "select a.article_id as article_id,a.user_id as user_id, a.title as title, a.status as status, a.create_time as create_time, b.content as content from news_article_basic as a inner join news_article_content as b on a.article_id=b.article_id"
use_column_value => "true"
tracking_column => "article_id"
clean_run => true
}
}
output{
elasticsearch {
hosts => "127.0.0.1:9200"
index => "articles"
document_id => "%{article_id}"
document_type => "article"
}
stdout {
codec => json_lines
}
}
sudo /usr/share/logstash/bin/logstash -f ./logstash_mysql.conf
推荐阅读
-
使用用SQL语句从电脑导入图片到数据库的方法
-
如何通过 Docker 部署 Logstash 同步 Mysql 数据库数据到 ElasticSearch
-
使用pyspark模仿sqoop从oracle导数据到hive的主要功能(自动建表,分区导入,增量,解决数据换行符问题)
-
如何将数据从文本导入到mysql
-
从入门到精通 MYsql的数据库学习使用心得_MySQL
-
解决大批量数据插入mysql问题:使用mysqlimport工具从文件中导入
-
从入门到精通 MYsql的数据库学习使用心得(2)_MySQL
-
Elasticsearch-MySQL数据导入到Elasticsearch中
-
logstash从MySQL导入数据到ElasticSearch的配置
-
使用 BulkProcessor 批量导入mysql数据到Elasticsearch