Monday, April 22, 2024
HomeHow toInstall and Configure OpenNMS on Alma Linux 8

Install and Configure OpenNMS on Alma Linux 8

OpenNMS is a free and open-source network monitoring and management platform written in Java. It is self-hosted and developed by a community of users, developers, and the OpenNMS Group. OpenNMS allows you to monitor everything on your local and remote networks including, performance, traffic monitoring, provisioning, services Monitoring, event managing, chart support, and more. OpenNMS uses SNPM and JMX to gather the information of remote hosts.

This post will show you how to install OpenNMS with Nginx on Alma Linux 8.

Prerequisites

  • A server running Alma Linux 8.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Install Java JDK

OpenNMS is a java-based application. So Java JDK must be installed on your server. You can install it by running the following command:

dnf install java-11-openjdk -y

Once the Java is installed, you can verify the Java installation using the command given below:

java --version

You will get the following output:

openjdk 11.0.13 2021-10-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)

Install OpenNMS on Alma Linux 8

By default, OpenNMS is not included in the Alma Linux default repo. So you will need to add the OpenNMS official repo to your system.

You can add the OpenNMS repo and GPG key by running the following command:

dnf install https://yum.opennms.org/repofiles/opennms-repo-stable-rhel8.noarch.rpm
rpm --import https://yum.opennms.org/OPENNMS-GPG-KEY

Next, install the OpenNMS by running the following command:

dnf install opennms -y

This will also install the PostgreSQL server to your server.

Next, change the directory to the OpenNMS and initialize the PostgreSQL database with the following command:

cd /opt/opennms
postgresql-setup initdb

Finally, start and enable the PostgreSQL service with the following command:

systemctl start postgresql
systemctl enable postgresql

You can now check the status of the PostgreSQL with the following command:

systemctl status postgresql

You will get the following output:

? postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-15 13:34:47 UTC; 5s ago
  Process: 7305 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
 Main PID: 7307 (postmaster)
    Tasks: 8 (limit: 11411)
   Memory: 15.9M
   CGroup: /system.slice/postgresql.service
           ??7307 /usr/bin/postmaster -D /var/lib/pgsql/data
           ??7309 postgres: logger process   
           ??7311 postgres: checkpointer process   
           ??7312 postgres: writer process   
           ??7313 postgres: wal writer process   
           ??7314 postgres: autovacuum launcher process   
           ??7315 postgres: stats collector process   
           ??7316 postgres: bgworker: logical replication launcher   

Jan 15 13:34:47 almalinux8 systemd[1]: Starting PostgreSQL database server...
Jan 15 13:34:47 almalinux8 postmaster[7307]: 2022-01-15 13:34:47.618 UTC [7307] LOG:  listening on IPv6 address "::1", port 5432
Jan 15 13:34:47 almalinux8 postmaster[7307]: 2022-01-15 13:34:47.618 UTC [7307] LOG:  listening on IPv4 address "127.0.0.1", port 5432

Configure PostgreSQL for OpenNMS

Next, you will need to create a database and user for OpenNMS.

First, log in to PostgreSQL with the following command:

su - postgres -c "psql -U postgres"

Next, change the Postgres password with the following command:

alter user postgres with password 'mypassword';

Next, create a database and user for OpenNMS with the following command:

createuser -P opennms
createdb -O opennms opennms

Next, exit from the PostgreSQL shell with the following command:

\q

Next, edit the PostgreSQL configuration file with the following command:

nano /var/lib/pgsql/data/pg_hba.conf

Find the following lines:

host    all             all             127.0.0.1/32            ident
host    all             all             ::1/128                 ident

And, replaced them with the following lines:

host           all            all           127.0.0.1/32           md5
host           all            all           ::1/128                   md5

Finally, reload the PostgreSQL service to apply the configuration changes:

systemctl reload postgresql

Configure OpenNMS

Next, you will need to edit the OpenNMS data source configuration file and define your database:

nano /opt/opennms/etc/opennms-datasources.xml

Change the following lines that match your database credentials:

<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="mypassword" />

Save and close the file then run the following command to detect the Java path:

/opt/opennms/bin/runjava -s

You will get the following output:

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-11.0.13.0.8-4.el8_5.x86_64/bin/java".
runjava: Value of "/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64/bin/java" stored in configuration file.

Next, run the following command to initialize the database and detect system libraries:

/opt/opennms/bin/install -dis

You will get the following output:

- Running pre-execution phase
  Creating backup of /opt/opennms/etc/service-configuration.xml
    Zipping /opt/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 /opt/opennms/etc/service-configuration.xml.zip

Finished in 0 seconds
Upgrade completed successfully!

Finally, start and enable the OpenNMS service with the following command:

systemctl start opennms
systemctl enable opennms

You can check the status of the OpenNMS with the following command:

systemctl status opennms

You will get the following output:

? opennms.service - OpenNMS server
   Loaded: loaded (/usr/lib/systemd/system/opennms.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-15 13:39:33 UTC; 6s ago
  Process: 8638 ExecStart=/etc/init.d/opennms -s start (code=exited, status=0/SUCCESS)
 Main PID: 9722 (java)
    Tasks: 36 (limit: 11411)
   Memory: 181.2M
   CGroup: /system.slice/opennms.service
           ??9721 bash /etc/init.d/opennms -s start
           ??9722 /usr/lib/jvm/java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64/bin/java --add-modules=java.base,java.compiler,java.datatransfer,ja>

Jan 15 13:39:22 almalinux8 systemd[1]: Starting OpenNMS server...
Jan 15 13:39:32 almalinux8 systemd[1]: opennms.service: Can't open PID file /opt/opennms/logs/opennms.pid (yet?) after start: No such file or>
Jan 15 13:39:33 almalinux8 systemd[1]: opennms.service: Supervising process 9722 which is not our child. We'll most likely not notice when it>
Jan 15 13:39:33 almalinux8 systemd[1]: Started OpenNMS server.

At this point, OpenNMS is started and listens on port 8980. You can check it with the following command:

ss -antpl | grep 8980

You will get the following output:

LISTEN 0      50                      *:8980             *:*    users:(("java",pid=9722,fd=1031))   

Once you are finished, you can proceed to the next step.

Configure Nginx as a Reverse Proxy for OpenNMS

Next, you will need to install Nginx and configure it as a reverse proxy for OpenNMS. To do so, install the Nginx server with the following command:

dnf install nginx -y

Once the Nginxx is installed, create an Nginx virtual host configuration file:

nano /etc/nginx/conf.d/opennms.conf

Add the following lines:

upstream opennms {
  server 127.0.0.1:8980;
}

server {
    listen 80;
    server_name opennms.example.com;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        proxy_pass http://opennms/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }
}

Save and close the file then verify the Nginx configuration with the following command:

nginx -t

You will get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, start and enable the Nginx service to start at system reboot:

systemctl start nginx
systemctl enable nginx

You can now check the status of the Nginx with the following command:

systemctl status nginx

You will get the following output:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-15 13:44:05 UTC; 6s ago
  Process: 13489 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 13488 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 13486 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 13491 (nginx)
    Tasks: 2 (limit: 11411)
   Memory: 3.7M
   CGroup: /system.slice/nginx.service
           ??13491 nginx: master process /usr/sbin/nginx
           ??13492 nginx: worker process

Jan 15 13:44:05 almalinux8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 15 13:44:05 almalinux8 nginx[13488]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 15 13:44:05 almalinux8 nginx[13488]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 15 13:44:05 almalinux8 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jan 15 13:44:05 almalinux8 systemd[1]: Started The nginx HTTP and reverse proxy server.

Configure Firewall

Next, you will need to allow port 80 through the firewall. You can allow it by running the following command:

firewall-cmd --add-service=http --permanent

Next, reload the firewall to apply the changes:

firewall-cmd --reload

Once you are finished, you can proceed to the next step.

Access OpenNMS Web Interface

Now, open your web browser and access the OpenNMS web interface using the URL http://opennms.example.com. You will get the OpenNMS login screen:

Provide the default admin username and password as admin/admin and click on the Login button. You will get the OpenNMS dashboard on the following screen:

Now, click on the admin => Change Password button to change the default password as shown below:

Change your default password and click on the Submit button. You will get the following screen:

Conclusion

Congratulations! you have successfully installed OpenNMS with Nginx on Alma Linux 8. You can now add the remote hosts from the OpenNMS dashboard and start monitoring them from the central location. Feel free to ask me if you have any questions.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here


spot_img

Most Popular