第八篇 elasticsearch連結mysql自動更新資料庫

來源:互聯網
上載者:User

標籤:filename   參考   any   ruby   execution   sheng   ble   名稱   lib   

累加式更新

input {  jdbc {    jdbc_driver_library => "D:\tools\mysql\mysql-connector-java-5.1.45/mysql-connector-java-5.1.45-bin.jar"    jdbc_driver_class => "com.mysql.jdbc.Driver"    jdbc_connection_string => "jdbc:mysql://localhost:3306/canyin?characterEncoding=UTF-8&useSSL=false"    jdbc_user => "root"    jdbc_password => "228151"    statement => "SELECT * FROM goods"    jdbc_paging_enabled => "true"    jdbc_page_size => "50000"    schedule => "* * * * *"    type => "foods"    record_last_run => true    last_run_metadata_path => ""    clean_run => false  }}filter {   json {        source => "message"        remove_field => ["message"]    }}output {  stdout {    codec => rubydebug  }  elasticsearch {    hosts => "127.0.0.1:9200"    index => "goods"    document_type=>"foods"      document_id=>"%{id}"    }        } 

累加式更新的參數介紹:

input {    stdin {        }    jdbc {        # 資料庫地址  連接埠  資料庫名        jdbc_connection_string => "jdbc:mysql://localhost:3306/shen"        # 資料庫使用者名稱              jdbc_user => "root"        # 資料庫密碼        jdbc_password => "rootroot"        # mysql java驅動地址         jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-5.1.43-bin.jar"        # 驅動類的名稱        jdbc_driver_class => "com.mysql.jdbc.Driver"                jdbc_paging_enabled => "true"        jdbc_page_size => "50000"        #是否記錄上次啟動並執行結果        record_last_run => true        #記錄上次運行結果的檔案位置        last_run_metadata_path => ""        #是否使用資料庫某一列的值,        use_column_value => true        tracking_column => "id"        #numeric或者timestamp        tracking_column_type => "numeric"                #如果為true則會清除 last_run_metadata_path 的記錄,即重新開始同步資料        clean_run => false        #sql_last_value根據tracking類型,預設為0或者1970-1-1        statement => "SELECT * FROM TABLE WHERE id > :last_sql_value"        # sql 語句檔案,對於複雜的查詢,可以放在檔案中。        # statement_filepath => "filename.sql"        # 設定監聽間隔,文法與Linux系統Cron相同        schedule => "* * * * *"    }}output {     stdout {        codec => json_lines    }   elasticsearch {        hosts  => "localhost:9200"        index => "contacts"     document_type => "contact"        document_id => "%{id}"    }}

chedule現在設定成每分鐘都執行一次,是為了方便觀察行為。statefile這一句是一定要加的。$metrics.lastexecutionstart就是這個指令碼的關鍵所在了,這個指的是上一次指令碼執行的時間,可以通過比較這個時間和資料庫裡的欄位來判斷是否要更新。
參考文獻:http://www.cnblogs.com/cocowool/p/mysql_data_to_elasticsearch_via_logstash.html
http://www.cnblogs.com/zhongshengzhen/p/elasticsearch_logstash.html
配置Logstash https://www.elastic.co/guide/en/logstash/current/configuration.html#

第八篇 elasticsearch連結mysql自動更新資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.