Logback和Graylog在Mac上使用syslog无法通信。

huangapple go评论102阅读模式
英文:

Logback and Graylog cannot communicate on a Mac using syslog

问题

以下是您提供的内容的翻译:

我想从Java应用程序将日志消息发送到Graylog,使用slf4j在logback之上,一侧使用logback GELF-appender,另一侧使用Graylog GELF-input。为了测试它,我在Docker容器中运行Graylog(使用Docker for Mac),然后在本地运行我的Java应用程序。我故事的要点是,Graylog GELF-input未能从Java应用程序接收任何内容。不知何故,Java应用程序和Graylog似乎无法进行通信。当我切换到不同的appender/input组合(基于syslog记录的组合)时也是如此。然而,当我从命令行向不同的Graylog输入发送消息,即侦听端口5555的RAW输入时,该消息会被正确接收。

有什么想法是什么问题吗?
以下是我使用GELF的设置:

Java应用程序:

  1. import org.slf4j.Logger;
  2. import org.slf4j.LoggerFactory;
  3. public class LogDemo {
  4. public static void main(String[] args) {
  5. Logger logger = LoggerFactory.getLogger(LogDemo.class);
  6. logger.error("Hello World 2");
  7. }
  8. }

pom.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>org.example</groupId>
  7. <artifactId>logdemo</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <dependencies>
  10. <dependency>
  11. <groupId>de.appelgriepsch.logback</groupId>
  12. <artifactId>logback-gelf-appender</artifactId>
  13. <version>1.5</version>
  14. </dependency>
  15. </dependencies>
  16. </project>

logback.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <appender name="GELF" class="de.appelgriepsch.logback.GelfAppender">
  4. <server>localhost</server>
  5. <port>12201</port>
  6. <protocol>TCP</protocol>
  7. </appender>
  8. <root level="error">
  9. <appender-ref ref="GELF"/>
  10. </root>
  11. </configuration>

Graylog的Docker启动:

  1. $ docker run --name mongo -d mongo:3
  2. $ docker run --name elasticsearch \
  3. -e "http.host=0.0.0.0" \
  4. -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
  5. -d docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
  6. $ docker run --link mongo --link elasticsearch \
  7. -p 9000:9000 -p 12201:12201 -p 1514:1514 -p 5555:5555 \
  8. -e GRAYLOG_HTTP_EXTERNAL_URI="http://127.0.0.1:9000/" \
  9. -d graylog/graylog:3.3

Graylog GELF tcp input(正在运行):

  1. bind_address: 0.0.0.0
  2. decompress_size_limit: 8388608
  3. max_message_size: 2097152
  4. number_worker_threads: 4
  5. override_source: <empty>
  6. port: 12201
  7. recv_buffer_size: 1048576
  8. tcp_keepalive: false
  9. tls_cert_file: <empty>
  10. tls_client_auth: disabled
  11. tls_client_auth_cert_file: <empty>
  12. tls_enable: false
  13. tls_key_file: <empty>
  14. tls_key_password: ********
  15. use_null_delimiter: true

正如所述,当我运行Java应用程序且Graylog作为Docker容器在后台运行时,Graylog未能接收我发送的日志消息。然而,当我在命令行中键入以下内容(在Mac上使用终端时),消息会被Graylog的RAW输入接收:

  1. $ echo "Testmessage" | nc localhost 5555

是否有人知道我做错了什么?

英文:

I want to send logmessages from a Java application to Graylog, using slf4j on top of logback with a logback GELF-appender on one side and a Graylog GELF-input on the other. To test it, i'm running Graylog in a Docker container (using Docker for Mac) and run my Java application locally. The gist of my story is that the Graylog GELF-input does not receive anything from the Java application. Somehow the Java application and Graylog don't seem to be able to communicate. The same applies when i switch to a different appender/input combination (one based on syslog records). However, when echoing a message from the commandline to a different Graylog input, namely the RAW input that's listening to port 5555, that message is received fine.

Any idea what the problem is?
This is my setup using GELF:

Java app:

  1. import org.slf4j.Logger;
  2. import org.slf4j.LoggerFactory;
  3. public class LogDemo {
  4. public static void main(String[] args) {
  5. Logger logger = LoggerFactory.getLogger(LogDemo.class);
  6. logger.error(&quot;Hello World 2&quot;);
  7. }
  8. }

pom.xml

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  3. xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  4. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  5. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  6. &lt;groupId&gt;org.example&lt;/groupId&gt;
  7. &lt;artifactId&gt;logdemo&lt;/artifactId&gt;
  8. &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  9. &lt;dependencies&gt;
  10. &lt;dependency&gt;
  11. &lt;groupId&gt;de.appelgriepsch.logback&lt;/groupId&gt;
  12. &lt;artifactId&gt;logback-gelf-appender&lt;/artifactId&gt;
  13. &lt;version&gt;1.5&lt;/version&gt;
  14. &lt;/dependency&gt;
  15. &lt;/dependencies&gt;
  16. &lt;/project&gt;

logback.xml

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;configuration&gt;
  3. &lt;appender name=&quot;GELF&quot; class=&quot;de.appelgriepsch.logback.GelfAppender&quot;&gt;
  4. &lt;server&gt;localhost&lt;/server&gt;
  5. &lt;port&gt;12201&lt;/port&gt;
  6. &lt;protocol&gt;TCP&lt;/protocol&gt;
  7. &lt;/appender&gt;
  8. &lt;root level=&quot;error&quot;&gt;
  9. &lt;appender-ref ref=&quot;GELF&quot;/&gt;
  10. &lt;/root&gt;
  11. &lt;/configuration&gt;

Graylog docker startup:

  1. $ docker run --name mongo -d mongo:3
  2. $ docker run --name elasticsearch \
  3. -e &quot;http.host=0.0.0.0&quot; \
  4. -e &quot;ES_JAVA_OPTS=-Xms512m -Xmx512m&quot; \
  5. -d docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
  6. $ docker run --link mongo --link elasticsearch \
  7. -p 9000:9000 -p 12201:12201 -p 1514:1514 -p 5555:5555 \
  8. -e GRAYLOG_HTTP_EXTERNAL_URI=&quot;http://127.0.0.1:9000/&quot; \
  9. -d graylog/graylog:3.3

Graylog GELF tcp input (running):

  1. bind_address: 0.0.0.0
  2. decompress_size_limit: 8388608
  3. max_message_size: 2097152
  4. number_worker_threads: 4
  5. override_source: &lt;empty&gt;
  6. port: 12201
  7. recv_buffer_size: 1048576
  8. tcp_keepalive: false
  9. tls_cert_file: &lt;empty&gt;
  10. tls_client_auth: disabled
  11. tls_client_auth_cert_file: &lt;empty&gt;
  12. tls_enable: false
  13. tls_key_file: &lt;empty&gt;
  14. tls_key_password:********
  15. use_null_delimiter: true

As stated, when i run the java app and Graylog is running as a Docker container in the background, Graylog does not receive the logmessage i sent. However, when i type the following on my commandline (using Terminal on Mac), the message IS received by the Graylog RAW input:

  1. $ echo &quot;Testmessage&quot; | nc localhost 5555

Does somebody got a clue what i'm doing wrong?

答案1

得分: 1

我找到了一个解决方案,尽管我不确定问题的确切原因是什么。解决方案是使用不同的 Gelf appender。而不是我上面提到的那个,我现在使用的是以下这个:

  1. <dependency>
  2. <groupId>de.siegmar</groupId>
  3. <artifactId>logback-gelf</artifactId>
  4. <version>2.2.0</version>
  5. </dependency>

这样就解决了问题,但正如我所说的,我不确定为什么我之前使用的那个方法不起作用。

英文:

I found a solution, though i'm not sure what the exact cause of the problem was. The solution was to use a different Gelf appender. Instead of the one i mentioned above, i'm now using the following one:

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;de.siegmar&lt;/groupId&gt;
  3. &lt;artifactId&gt;logback-gelf&lt;/artifactId&gt;
  4. &lt;version&gt;2.2.0&lt;/version&gt;
  5. &lt;/dependency&gt;

That did the trick, but as i said, i'm unsure why the one i used earlier did not work.

huangapple
  • 本文由 发表于 2020年10月12日 19:39:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/64317174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定