0
votes

I'm trying to export datas from a mysql table to elastic search with logstash and the jdbc mysql driver with every process in a docker container. My problem is (with no error) their is nothing sent to elastic search.

My Dockerfile :

FROM elastic/logstash:6.3.0

ENV https_proxy=
ENV http_proxy=

COPY ./mysql-connector-java-5.1.46/mysql-connector-java-5.1.46.jar /tmp/mysql-connector-java-5.1.46.jar
COPY ./logstash.conf /tmp/logstash.conf
COPY ./logstash.yml /usr/share/logstash/config/logstash.yml

RUN logstash-plugin install logstash-input-jdbc

I run it with this command :

docker run -d --rm --name=logstach -v /data/logstash:/home/logstash logstash bin/logstash -f /tmp/logstash.conf

And here is my logstash.conf :

input {
        jdbc {
            jdbc_driver_library => "/tmp/mysql-connector-java-5.1.46.jar"
            jdbc_driver_class => "com.mysql.jdbc.Driver"
            jdbc_connection_string => "jdbc:mysql://0.0.2.22:3306/itop_db"
           jdbc_user => "admin"
            jdbc_password => "password"
            statement => "SELECT * FROM contact”
        }
    }
    output {
         elasticsearch {
            index => "contact"
            document_type => "data"
            document_id => "%{id}"
            hosts => "127.0.0.1:9200"
        }
        stdout { codec => json_lines }
    }

Every thing seems to accomplish well, except their is no new index in elastic search http://localhost:9200/_cat/indices?v

This is the output I have when i run logstash :

logstash execution output

logstash error 2

2
Your MySQL server IP address is wrong - dwjv
Are you sur that the address 0.0.2.22:3306 is recheable from the logstash container? Try to execut a ping, telnet or curl command - andolsi zied
The mysql IP is good, I just changed the 2 first numbers by 0.0. I can connect to mysql with the infos in the jdbc input from the same machine I execute the docker run. I mean this works : mysql -h "0.0.2.22" -u admin -ppassword - Kalus
Can you show us Logstash's logs? - Michael Dz
Yes, done. this is the output of the command I use to run logstash - Kalus

2 Answers

1
votes

"SELECT * FROM contact” <-- this could be the problem. I imagine you copied this from the internet? Change to "

0
votes

In addition to the error in my SQL statement, I needed to specify the host ip of the container (172.17.0.2 in my case) instead of using 127.0.0.1:9200