使用logstash 同步elasticsearch与mysql

2017-02-20  本文已影响264人  qingxp9
#/etc/logstash/conf.d/logstash.conf

  jdbc {
    jdbc_driver_library => "/home/xxx/mysql-connector-java-5.1.40-bin.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://localhost:3306/kuname?useSSL=false&zeroDateTimeBehavior=convertToNull&useUnicode=yes&characterEncoding=UTF-8"
    jdbc_user => "xxxx"
    jdbc_password => "xxxxx"
    statement => "select * from tablename"
    jdbc_paging_enabled => true
    jdbc_page_size => 200000
    type => "xxxx"
  }
  
  filter {
  ...
  }
  
  output {
      stdout { codec => rubydebug }
      elasticsearch {
        hosts => ["localhost:9200"]
        index => "xxxxx"
      }
}

说明:
useSSL=false 关闭SSL
useUnicode=yes&characterEncoding=UTF-8 指定编码
zeroDateTimeBehavior=convertToNull 如果有时间字段值为0000-00-00时会报错,转化为null

jdbc_paging_enabled => true 开启分页

如果遇到内存不足错误
Error: Your application used more memory than the safety cap of 10240M.
Specify -J-Xmx####m to increase it (#### = cap size in MB).
Specify -w for full OutOfMemoryError stack trace

修改以下文件手动指定

#/etc/default/logstash
LS_HEAP_SIZE="xxxxm"
上一篇下一篇

猜你喜欢

热点阅读