Logstash崩溃时无法计算错误消息

时间:2019-03-05 13:08:53

标签: sql-server docker elasticsearch logstash

我正在尝试通过Logstash在Elasticsearch和SQL Server之间进行Dockerize集成。我已经制作了自己的dockerfile,因此可以在任何环境中使用它,它看起来像:

FROM logstash:6.5.0

#switch to root user
USER root

#arguments
ARG dbHost=foo
ARG dbName=foo
ARG dbUser=foo
ARG dbUserPassword=foo
ARG elasticHost=www.google.com
ARG dbTable=foo
ARG elasticIndex=foo
ARG shardNum=foo
ARG replicasNum=foo

#host where database is located
ENV dbHost ${dbHost}
#database name
ENV dbName ${dbName}
#database user
ENV dbUser ${dbUser}
#database user password
ENV dbUserPassword ${dbUserPassword}
#host where Elasticsearch is located
ENV elasticHost $elasticHost
#table to log
ENV dbTable ${dbTable}
#index name
ENV elasticIndex ${elasticIndex}
#number of shards
ENV shardNum ${shardNum}
#number of replicas
ENV replicasNum ${replicasNum}
RUN usermod -a -G root logstash
#copying jar for sql server into /bin/jdbc directorys
COPY ./sqljdbc42.jar /bin/jdbc/
#adding system variable CLASSPATH for sqljdbc
CMD ["echo 'export CLASSPATH="/bin/jdbc/sqljdbc42.jar"' >> /root/.bashrc"]

#creating Elasticsearch index for SQL Server logs
RUN echo $(curl -XPUT --silent '${elasticHost}/${elasticIndex}' -d '{"settings" : {"index" : {"number_of_shards" : ${shardNum}, "number_of_replicas" : ${replicasNum}}}}')

#setting working directory
WORKDIR /bin/jdbc

#configuring LogStash configuration file
RUN echo "input {" >> sql.conf
RUN echo "  jdbc {" >> sql.conf
RUN echo "    jdbc_connection_string => "jdbc:sqlserver://${dbHost};databaseName=${dbName};db_username=${dbUser};db_password=${dbUserPassword}"" >> sql.conf
RUN echo "    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"" >> sql.conf
RUN echo "    jdbc_user => ${dbUser}" >> sql.conf
RUN echo "" >> sql.conf
RUN echo "    statement => "select * from $dbTable"" >> sql.conf
RUN echo "  }" >> sql.conf
RUN echo "}" >> sql.conf
RUN echo "" >> sql.conf
RUN echo "output {" >> sql.conf
RUN echo "  elasticsearch {" >> sql.conf
RUN echo "    hosts => ["${elasticHost}"]" >> sql.conf
RUN echo "    index => "${elasticIndex}"" >> sql.conf
RUN echo "  }" >> sql.conf
RUN echo "}" >> sql.conf

RUN chown --recursive logstash /usr/share/logstash/bin/logstash

USER logstash
ENTRYPOINT ["/usr/share/logstash/bin/logstash", "-f", "/bin/jdbc/sql.conf", "-l", "logstash.log"]

我已经创建映像并将其推送到我的私有Docker存储库中。我正在尝试使用docker compose以及SQL Server,Elasticsearch和Kibana运行该映像。目的是在Kibana中显示“ 选择*”的结果。我的docker-compose文件看起来像这样:

version: '3.4'

services:
  elasticsearch:
    image: "elasticsearch:6.5.0"
    environment:
      - "discovery.type=single-node"
    ports:
      - "9200:9200"
      - "9300:9300"
    container_name: elasticsearch
    networks:
      - random-network

  sql_server:
    image: "mcr.microsoft.com/mssql/server:2017-latest"
    environment:
      - "ACCEPT_EULA=Y"
      - "SA_PASSWORD=RandomPassword"
    ports:
      - "1400:1433"
    container_name: apprrr-dev
    networks:
      - random-network

  kibana:
    image: "elastic/kibana:6.5.0"
    ports:
      - "5601:5601"
    container_name: kibana
    environment:
      - "ELASTICSEARCH_URL=http://elasticsearch:9200"
    networks:
      - random-network
    depends_on:
      - elasticsearch

  elasticsqlserver:
    image: "localhost:5000/ryukote2/elasticsqlserver:1.0.0"
    environment:
      - "dbHost=sql_server:1400"
      - "dbName=RandomDB"
      - "dbUser=sa"
      - "dbUserPassword=RandomPassword"
      - "elasticHost=http://elasticsearch:9200"
      - "dbTable=RandomTable"
      - "elasticIndex=TestIndex"
      - "shardNum=1"
      - "replicasNum=1"
    networks:
      - random-network
    depends_on:
      - sql_server
      - elasticsearch

networks:
  random-network
    driver: bridge

每个服务正常启动,并且服务“ elasticsqlserver ”崩溃,并显示错误:

  

elasticsqlserver_1 |错误:未知命令“ / bin / sh”   elasticsqlserver_1 | elasticsqlserver_1 |请参阅:'bin / logstash   --help'elasticsqlserver_1 | [错误] 2019-03-05 12:58:13.988 [main] Logstash-java.lang.IllegalStateException:Logstash已停止   由于错误而正在处理:(SystemExit)退出   random-network_elasticsqlserver_1以代码1退出

我在任何地方都找不到导致此错误的原因以及如何解决此问题的方法。我的dockerfile在文本的任何地方都不包含' / bin / sh '。

如果这很琐碎,我不会感到惊讶。

0 个答案:

没有答案