1 从源代码安装

概述

如果您从源代码包安装,那么以下的信息将会帮助您配置Java gateway

If installed from sources, the following information will help you in setting up Zabbix Java gateway.

文件概述

如果您从源代码包中获取Java gateway,那么您应该最终会得到 $PREFIX/sbin/zabbix_java 下的 shell scripts、JAR 和配置文件的集合。 这些文件的作用总结如下:

If you obtained Java gateway from sources, you should have ended up with a collection of shell scripts, JAR and configuration files under $PREFIX/sbin/zabbix_java. The role of these files is summarized below.

  1. bin/zabbix-java-gateway-$VERSION.jar

Java gateway JAR 文件。

Java gateway JAR file itself.

  1. lib/logback-core-0.9.27.jar
  2. lib/logback-classic-0.9.27.jar
  3. lib/slf4j-api-1.6.1.jar
  4. lib/android-json-4.3_r3.1.jar

Java gateway 的依赖:LogbackSLF4JAndroid JSON 库。

Dependencies of Java gateway: Logback, SLF4J, and Android JSON library.

  1. lib/logback.xml
  2. lib/logback-console.xml

Logback 的配置文件。

Configuration files for Logback.

  1. shutdown.sh
  2. startup.sh

用于启动和停止 Java gateway 的便捷脚本。

Convenience scripts for starting and stopping Java gateway.

  1. settings.sh

由上面的启动和关闭脚本提供的配置文件。

Configuration file that is sourced by startup and shutdown scripts above.

配置并运行 Java gateway

在默认情况下,Java gateway 的监听端口是10052。如果您计划在其他的端口上运行 Java gateway,您可以在 settings.sh 脚本中指定其端口号。关于如何指定此选项和其他选项,详见Java gateway 配置文件

By default, Java gateway listens on port 10052. If you plan on running Java gateway on a different port, you can specify that in settings.sh script. See the description of Java gateway configuration file for how to specify this and other options.

端口号 10052 不是由 IANA 注册的

Port 10052 is not IANA registered.

一旦您熟悉了上面这些设置,那么您可以通过启动脚本来启动 Java gateway:

Once you are comfortable with the settings, you can start Java gateway by running the startup script:

  1. $ ./startup.sh

同样的,一旦您不再需要 Java gateway,那么可以运行停止脚本来停止它:

Likewise, once you no longer need Java gateway, run the shutdown script to stop it:

  1. $ ./shutdown.sh

值得注意的是,与 Server 或 Proxy 不同的是,Java gateway 是轻量级的,它并不需要数据库。

Note that unlike server or proxy, Java gateway is lightweight and does not need a database.

配置 Server 以同 Java gateway 使用

当 Java gateway 启动和运行后,您必须告诉 Zabbix server 如何找到 Java gateway。这是通过在 Server 配置文件 中指定 JavaGateway 和 JavaGatewayPort 参数来完成的。如果 Zabbix proxy 运行 JMX 的应用或主机,则需要在 Proxy 配置文件 中指定连接参数。

With Java gateway up and running, you have to tell Zabbix server where to find Zabbix Java gateway. This is done by specifying JavaGateway and JavaGatewayPort parameters in the server configuration file. If the host on which JMX application is running is monitored by Zabbix proxy, then you specify the connection parameters in the proxy configuration file instead.

  1. JavaGateway=192.168.3.14
  2. JavaGatewayPort=10052

默认情况下,Server 不会启动与 JMX 监控相关的任何进程。但是,如果您要使用它,那么就必须要指定 Java pollers 的数量。此操作与指定常规 pollers 和 trappers 相同。

By default, server does not start any processes related to JMX monitoring. If you wish to use it, however, you have to specify the number of pre-forked instances of Java pollers. You do this in the same way you specify regular pollers and trappers.

  1. StartJavaPollers=5

在完成配置后,一定不要忘记重启 Server 或 Poryx。

Do not forget to restart server or proxy, once you are done with configuring them.

调试 Java gateway

为了防止在 Java gateway 出现任何问题或在 Zabbix 前端看不到详细的报错信息的情况下,您可以通过 Java gateway 日志文件来查看。

In case there are any problems with Java gateway or an error message that you see about an item in the frontend is not descriptive enough, you might wish to take a look at Java gateway log file.

默认情况下,Java gateway 将其活动日志记录到日志级别为 “info” 的 /tmp/zabbix_java.log 文件中。有时候,该日志信息可能不够详细,需要在日志级别为 “debug” 中获取。为了提升日志级别,需要修改 lib/logback.xml 文件,并将 标记的日志等级属性更改为 “debug”:

By default, Java gateway logs its activities into /tmp/zabbix_java.log file with log level “info”. Sometimes that information is not enough and there is a need for information at log level “debug”. In order to increase logging level, modify file lib/logback.xml and change the level attribute of tag to “debug”:

  1. <root level="debug">
  2. <appender-ref ref="FILE" />
  3. </root>

值得注意的是,与 Zabbix server 或 Zabbix proxy 不同,更改 logback.xml 文件并不需要重启 Zabbix Java gateway,它会自动提交。当完成调试后,可以将日志级别修改回 “info”。

Note that unlike Zabbix server or Zabbix proxy, there is no need to restart Zabbix Java gateway after changing logback.xml file - changes in logback.xml will be picked up automatically. When you are done with debugging, you can return the logging level to “info”.

如果希望将日志记录到其他文件或完全不同的介质,如数据库,那么只需要调整 logback.xml 文件。详见 Logback 手册 获取更多信息。

If you wish to log to a different file or a completely different medium like database, adjust logback.xml file to meet your needs. See Logback Manual for more details.

有时为了调试,将 Java gateway 用作控制台应用而不是守护进程来启动是很有必要的。为此,可以在 settings.sh 中注释掉 PID_FILE 变量。如果省略掉 PID_FILE,则 startup.sh 脚本启动 Java gateway 时会作为控制台应用来启动,并将 Logback 使用 lib/logback-console.xml 文件,这不仅会记录到控制台,还会启用日志级别 “debug”。

Sometimes for debugging purposes it is useful to start Java gateway as a console application rather than a daemon. To do that, comment out PID_FILE variable in settings.sh. If PID_FILE is omitted, startup.sh script starts Java gateway as a console application and makes Logback use lib/logback-console.xml file instead, which not only logs to console, but has logging level “debug” enabled as well.

最后,请注意,由于 Java gateway 使用 SLF4J 来记录,您可以通过在 lib 目录放置合适的 JAR 文件来将 Logback 替换为您选中的框架。详见 SLF4J 手册 以获取更多信息。

Finally, note that since Java gateway uses SLF4J for logging, you can replace Logback with the framework of your choice by placing an appropriate JAR file in lib directory. See SLF4J Manual for more details.

JMX 监控

详见 JMX 监控 页面以获取更多信息。

See JMX monitoring page for more details.