转载请复制本声明!
:运维漫谈
编辑:漫谈君
来源链接:https://www.wljslmz.cn/1092.html
OpenNMS 是一个免费、开源且功能最强大的网络监控和网络管理平台之一,用于从中央位置监控远程设备,它支持许多功能,包括供应、服务监控、事件管理、图表支持等。OpenNMS 使用 SNMP 和 JMX 并从远程系统收集信息,它在 Linux 和 Windows 操作系统上运行,并提供基于 Web 的界面以方便监控。
在本教程中,我将向您展示如何在 Debian 11 上安装 OpenNMS。
目录
先决条件
运行 Debian 11 的服务器。使用您的服务器 IP 指向的有效域名。在服务器上配置了 root 密码。在 Debian 11 上安装 Java
OpenNMS 是一个基于 Java 的应用程序,所以Java必须安装在你的服务器上。如果未安装,您可以通过运行以下命令来安装它:
apt-get install default-jdk -y安装 Java 后,使用以下命令验证 Java 版本:
java --version您将在以下输出中获得 Java 版本:
openjdk 11.0.13 2021-10-19OpenJDK Runtime Environment (build 11.0.13+8-post-Debian-1deb11u1)OpenJDK 64-Bit Server VM (build 11.0.13+8-post-Debian-1deb11u1, mixed mode, sharing)在 Debian 11 上安装 OpenNMS
默认情况下,OpenNMS 不包含在 Debian 11 主存储库中。因此,您需要将 OpenNMS 官方存储库添加到 APT。
首先,使用以下命令安装所有必需的依赖项:
apt-get install curl gnupg2 wget -y安装完所有软件包后,使用以下命令创建 OpenNMS 存储库文件:
nano /etc/apt/sources.list.d/opennms.list添加以下行:
deb ;stable maindeb-src ;stable main保存并关闭文件,然后使用以下命令导入 GPG 密钥:
wget -O - ;| apt-key add -您将获得以下输出:
Connecting to debian.opennms.org (debian.opennms.org)|3.214.84.83|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 1335 (1.3K)Saving to: ‘STDOUT’- 100%[=================================================================>] 1.30K --.-KB/s in 0s 2021-11-28 07:58:07 (16.0 MB/s) - written to stdout [1335/1335]OK接下来,更新存储库缓存并使用以下命令安装 OpenNMS:
apt-get update -y apt-get install opennms -y在安装过程中会出现以下错误:
Failed to install iplike into the template1 or opennms databases. See /tmp/install_iplike.log for details. To skip this step and install manually, set the environment variable SKIP_IPLIKE_INSTALL before installing this package. To install iplike into your database, use the /usr/sbin/install_iplike.sh script. See `install_iplike.sh -h` for more details.要解决此错误,您需要在 PostgreSQL 中为 OpenNMS 创建数据库和用户。
在 PostgreSQL 中创建数据库
在 OpenNMS 安装过程中自动安装的 PostgreSQL 服务器。首先,使用以下命令启动 PostgreSQL 服务:
systemctl start postgresql接下来,使用以下命令连接到 PostgreSQL 实例:
su - postgres连接后,为 OpenNMS 创建一个用户并使用以下命令设置密码:
createuser opennms psql -c "ALTER USER opennms WITH PASSWORD opennms;"接下来,为 OpenNMS 创建一个数据库并为 postgres 用户设置密码:
createdb -O opennms opennms psql -c "ALTER USER postgres WITH PASSWORD securepassword;"接下来,使用以下命令退出 PostgreSQL shell:
exit完成后,您可以继续下一步。
配置 OpenNMS
接下来,您将需要编辑 OpenNMS 数据源文件并定义您的数据库凭据:
nano /usr/share/opennms/etc/opennms-datasources.xml定义您的数据库凭据,如下所示:
<jdbc-data-source name="opennms" database-name="opennms" class-name="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/opennms" user-name="opennms" password="opennms" /> <jdbc-data-source name="opennms-admin" database-name="template1" class-name="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/template1" user-name="postgres" password="securepassword" /></datasource-configuration>完成后保存并关闭文件,然后运行以下命令来检测 Java 环境:
sudo -u opennms /usr/share/opennms/bin/runjava -s您将获得以下输出:
runjava: Looking for an appropriate JVM...runjava: Checking for an appropriate JVM in JAVA_HOME...runjava: Skipping... JAVA_HOME not set.runjava: Checking JVM in the PATH: "/etc/alternatives/java"...runjava: Did not find an appropriate JVM in the PATH: "/etc/alternatives/java"runjava: Searching for a good JVM...runjava: Found a good JVM in "/usr/lib/jvm/java-11-openjdk-amd64/bin/java".runjava: Value of "/usr/lib/jvm/java-11-openjdk-amd64/bin/java" stored in configuration file.接下来,运行以下命令完成 OpenNMS 设置:
sudo -u opennms /usr/share/opennms/bin/install -dis您将获得以下输出:
Finished in 0 secondsProcessing RemotePollerServiceConfigMigratorOffline: Remove deprecated RemotePoller service entry from service-configuration.xml, see NMS-12684- Running pre-execution phase Creating backup of /usr/share/opennms/etc/service-configuration.xml Zipping /usr/share/opennms/etc/service-configuration.xml- Running execution phase Current configuration: 32 services. A service entry named OpenNMS:Name=PerspectivePoller already exists. Final configuration: 32 services.- Saving the execution state- Running post-execution phase Removing backup /usr/share/opennms/etc/service-configuration.xml.zipFinished in 0 secondsUpgrade completed successfully!启动 OpenNMS 服务
设置 OpenNMS 后,启动 OpenNMS 服务并使用以下命令使其在系统重新启动时启动:
systemctl start opennmssystemctl enable opennms您可以使用以下命令验证 OpenNMS 状态:
systemctl status opennms您将获得以下输出:
? opennms.service - OpenNMS server Loaded: loaded (/lib/systemd/system/opennms.service; disabled; vendor preset: enabled) Active: active (running) since Sun 2021-11-28 08:10:51 UTC; 16s ago Process: 22990 ExecStart=/usr/share/opennms/bin/opennms -s start (code=exited, status=0/SUCCESS) Main PID: 24106 (java) Tasks: 68 (limit: 4679) Memory: 559.2M CPU: 48.083s CGroup: /system.slice/opennms.service ??24105 bash /usr/share/opennms/bin/opennms -s start ??24106 /usr/lib/jvm/java-11-openjdk-amd64/bin/java --add-modules=java.base,java.compiler,java.datatransfer,java.desktop,java.in>Nov 28 08:11:02 debian11 opennms[24106]: [DEBUG] System property opennms.library.jicmp set to /usr/lib/jni/libjicmp.so. Attempting to loa>Nov 28 08:11:02 debian11 opennms[24106]: [INFO] Successfully loaded jicmp library.Nov 28 08:11:02 debian11 opennms[24106]: [DEBUG] System property opennms.library.jicmp6 set to /usr/lib/jni/libjicmp6.so. Attempting to l>Nov 28 08:11:02 debian11 opennms[24106]: [INFO] Successfully loaded jicmp6 library.Nov 28 08:11:02 debian11 opennms[24106]: [DEBUG] System property opennms.library.jicmp set to /usr/lib/jni/libjicmp.so. Attempting to loa>Nov 28 08:11:02 debian11 opennms[24106]: [INFO] Successfully loaded jicmp library.Nov 28 08:11:02 debian11 opennms[24106]: [DEBUG] System property opennms.library.jicmp6 set to /usr/lib/jni/libjicmp6.so. Attempting to l>Nov 28 08:11:02 debian11 opennms[24106]: [INFO] Successfully loaded jicmp6 library.Nov 28 08:11:07 debian11 opennms[24106]: Nov 28, 2021 8:11:07 AM org.hibernate.validator.internal.util.Version Nov 28 08:11:07 debian11 opennms[24106]: INFO: HV: Hibernate Validator 4.3.2.Final此时,OpenNMS 启动并监听 8980 端口。您可以使用以下命令进行检查:
ss-antpl | grep 8980您将获得以下输出:
LISTEN 0 50 *:8980 *:* users:(("java",pid=24106,fd=1046))将 Nginx 配置为 OpenNMS 的反向代理
接下来,建议安装和配置 Nginx 作为 OpenNMS 的反向代理。首先,使用以下命令安装 Nginx 服务器:
apt-get install nginx -y安装 Nginx 后,创建 Nginx 虚拟主机配置文件:
nano /etc/nginx/conf.d/opennms.conf添加以下配置:
server { listen 80; server_name opennms.example.com; access_log /var/log/nginx/opennms.access.log; error_log /var/log/nginx/opennms.error.log; location / { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-OpenNMS-Server-URL ; proxy_pass :8980; }}保存并关闭文件,然后验证 Nginx 是否存在任何语法配置错误:
nginx -t您将获得以下输出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful接下来,重新启动 Nginx 服务以应用更改:
systemctl restart nginx要检查 Nginx 运行状态,请运行以下命令:
systemctl status nginx您应该看到以下输出:
? nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2021-11-28 08:17:14 UTC; 6s ago Docs: man:nginx(8) Process: 25964 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 25965 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 25967 (nginx) Tasks: 3 (limit: 4679) Memory: 3.2M CPU: 53ms CGroup: /system.slice/nginx.service ??25967 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ??25968 nginx: worker process ??25969 nginx: worker processNov 28 08:17:14 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...Nov 28 08:17:14 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.访问 OpenNMS 仪表板
现在,打开您的 Web 浏览器并使用 URL 访问 OpenNMS Web 界面。您应该会看到 OpenNMS 登录页面:
以管理员身份提供默认用户名和密码,然后单击登录按钮。您应该在以下屏幕上看到 OpenNMS 仪表板:
现在,单击管理员 > 更改密码以更改默认管理员密码,如下所示:
更改您的默认密码,然后单击提交按钮。您应该看到以下屏幕:
结论
恭喜!你已经成功地在 Debian 11 服务器上安装了带有 Nginx 的 OpenNMS 作为反向代理。您现在可以将远程设备添加到 OpenNMS 并开始从 Web 浏览器监控它们。如果您有任何问题,请随时问我。