赞
踩
Logstash是一个开源的服务器端数据处理管道,可以同时从多个数据源获取数据,并对其进行转换,然后将其发送到Elasticsearch中。
解压即可
Logstash的工作是从MySQL中读取数据,向ES中创建索引,这里需要提前创建mapping的模板文件以便logstash使用。
- input {
- stdin {
- }
- jdbc {
- #serverTimezone=UTC
- #serverTimezone=Asia/Shanghai
- jdbc_connection_string => "jdbc:mysql://localhost:3306/xc_course?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8"
- # the user we wish to excute our statement as
- jdbc_user => "root"
- jdbc_password => "1234"
- # the path to our downloaded jdbc driver
- jdbc_driver_library => "../lib/mysql-connector-java-5.1.47.jar"
- # the name of the driver class for mysql
- jdbc_driver_class => "com.mysql.jdbc.Driver"
- #分页设置
- jdbc_paging_enabled => "true"
- jdbc_page_size => "50000"
- jdbc_fetch_size => 100
- #要执行的sql文件
- #statement_filepath => "/conf/course.sql"
- #statement => "select * from course_pub where timestamp > date_add(:sql_last_value,INTERVAL 8 HOUR)"
- statement => "select * from course_pub where timestamp > :sql_last_value"
- #定时配置
- schedule => "* * * * *"
- record_last_run => true
- last_run_metadata_path => "../config/logstash_metadata"
- }
- }
-
-
- output {
- elasticsearch {
- #ES的ip地址和端口
- hosts => "localhost:9200"
- #hosts => ["localhost:9200","localhost:9202","localhost:9203"]
- #ES索引库名称
- index => "xc_course"
- document_id => "%{id}"
- document_type => "CoursePub"
- template =>"../config/xc_course_template.json"
- template_name =>"xc_course"
- template_overwrite =>"true"
- }
- stdout {
- #日志输出
- codec => json_lines
- }
- }

- {
- "template" : "xc_course",
- "mappings" : {
- "CoursePub": {
- "properties": {
- "charge": {
- "type": "keyword"
- },
- "description": {
- "type": "text",
- "analyzer": "ik_max_word",
- "search_analyzer": "ik_smart"
- },
- "end_time": {
- "type": "date",
- "format": "yyyy-MM-dd HH:mm:ss"
- },
- "expires": {
- "type": "date",
- "format": "yyyy-MM-dd HH:mm:ss"
- },
- "grade": {
- "type": "keyword"
- },
- "id": {
- "type": "keyword"
- },
- "mt": {
- "type": "keyword"
- },
- "name": {
- "type": "text",
- "analyzer": "ik_max_word",
- "search_analyzer": "ik_smart"
- },
- "pic": {
- "type": "keyword",
- "index": false
- },
- "price": {
- "type": "float"
- },
- "price_old": {
- "type": "float"
- },
- "pub_time": {
- "type": "date",
- "format": "yyyy-MM-dd HH:mm:ss"
- },
- "qq": {
- "type": "keyword",
- "index": false
- },
- "st": {
- "type": "keyword"
- },
- "start_time": {
- "type": "date",
- "format": "yyyy-MM-dd HH:mm:ss"
- },
- "status": {
- "type": "keyword"
- },
- "studymodel": {
- "type": "keyword"
- },
- "teachmode": {
- "type": "keyword"
- },
- "teachplan": {
- "type": "text",
- "analyzer": "ik_max_word",
- "search_analyzer": "ik_smart"
- },
- "users": {
- "type": "text",
- "index": false
- },
- "valid": {
- "type": "keyword"
- }
- }
- }
- }
- }

logstash.bat -f ..\config\xc_course_mysql.conf
看完恭喜你,又知道了一点点!!!
你知道的越多,不知道的越多!
~感谢志同道合的你阅读, 你的支持是我学习的最大动力 ! 加油 ,陌生人一起努力,共勉!!
注: 如果本篇有需要改进的地方或错误,欢迎大神们指定一二~~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。