RHEL BasedRocky Linux

How To Install NetBox on Rocky Linux 9

Install NetBox on Rocky Linux 9

In this tutorial, we will show you how to install NetBox on Rocky Linux 9. For those of you who didn’t know, NetBox is an open-source web application for managing and documenting computer networks. It is written in Python and uses the Django web framework. It provides a centralized view of network infrastructure, including IP addresses, devices, virtual machines, and connections between them. NetBox also includes built-in functionality for managing data centers, including racks, devices, and virtual machines.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of NetBox IRM on Rocky Linux. 9.

Prerequisites

  • A server running one of the following operating systems:  Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for NetBox.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install NetBox on Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update
sudo dnf install dnf-utils
sudo dnf install gcc libxml2-devel libxslt-devel libffi-devel libpq-devel openssl-devel redhat-rpm-config git

Step 2. Installing PostgreSQL.

By default, PostgreSQL is not available on Rocky Linux 9 base repository. Now run the following command below to add the PostgreSQL stable repository to your system:

sudo dnf install http://apt.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Next, run the following command to install the latest stable version of PostgreSQL to your server:

sudo dnf check-update
sudo dnf install postgresql14-server postgresql14-docs

Once the installation is done, start the PostgreSQL service and enable it to automatically start on reboot all in one go with:

sudo systemctl enable postgresql-14 --now
sudo systemctl status postgresql-14

Now log in to the PostgreSQL shell via the below command:

sudo -u postgres psql

Then, set up a new password for the default PostgreSQL user ‘postgres‘:

ALTER USER postgres WITH PASSWORD 'Your-Strong-PostgreSQL-Passwd';

After that, create a new database ‘netboxdb‘ with the user ‘netbox‘ that will be used for NetBox installation:

CREATE DATABASE netboxdb;
CREATE USER netbox WITH ENCRYPTED PASSWORD 'NetBoxRocks';
GRANT ALL PRIVILEGES ON DATABASE netboxdb TO netbox;

Finally, run the following command to log in to the PostgreSQL shell via the new user ‘netbox‘ to the new database ‘netboxdb‘:

sudo -u postgres psql --username netbox --password --host localhost netboxdb

Next, run the below query to verify your current connection:

\conninfo

For additional resources on installing PostgreSQL, read the post below:

Step 3. Installing Redis.

By default, Redis is available on Rocky Linux 9 base repository. Now run the following command below to install the latest stable version of Redis to your system:

sudo dnf install redis

Next, start the Redis service and enable it to automatically start on boot by running the following command below:

sudo systemctl enable --now redis
sudo systemctl start redis
sudo systemctl status redis

You can verify the Redis installation by running the following commands:

redis-server --version

Redis stores its configuration file at /etc/redis/redis.conf. This file can be edited as desired.

sudo nano /etc/redis/redis.conf

Uncomment the parameter ‘require pass‘ and input the new password for your Redis server:

requirepass RedisPasswordNetBox

Save and close the file, then restart the Redis server using the following command:

sudo systemctl restart redis

For additional resources on installing Redis, read the post below:

Step 4. Installing Netbox IRM on Rocky Linux 9.

First, create a new system user ‘netbox‘ with the default home directory ‘/opt/netbox‘:

sudo useradd -r -d /opt/netbox -s /usr/sbin/nologin netbox

Next, download the latest version of the NetBox source code via the git command:

mkdir -p /opt/netbox; cd /opt/netbox
sudo git clone -b master --depth 1 https://github.com/netbox-community/netbox.git

Move your working directory to /opt/netbox/netbox/netbox‘:

sudo chown -R netbox:netbox /opt/netbox
cd /opt/netbox/netbox/netbox

Next, run the below command to copy the default NetBox configuration to ‘configuration.py‘:

sudo -u netbox cp configuration_example.py configuration.py
sudo -u netbox python3 ../generate_secret_key.py

Then, open the NetBox config file ‘configuration.py‘ using the favorite text editor:

sudo -u netbox nano configuration.py

Add the following parameter:

# domain and IP address
ALLOWED_HOSTS = ['your-domain.com', '192.168.77.21']

# database configuration
DATABASE = {
    'NAME': 'netboxdb',             # Database name
    'USER': 'netbox',               # PostgreSQL username
    'PASSWORD': 'NetBoxRocks',      # PostgreSQL password
    'HOST': 'localhost',            # Database server
    'PORT': '',                     # Database port (leave blank for default)
    'CONN_MAX_AGE': 300,            # Max database connection age (seconds)
}

# Redis cache configuration
REDIS = {
    'tasks': {
        'HOST': 'localhost',         # Redis server
        'PORT': 6379,                # Redis port
        'PASSWORD': 'RedisPasswordNetBox',           # Redis password (optional)
        'DATABASE': 0,               # Database ID
        'SSL': False,                # Use SSL (optional)
    },
    'caching': {
        'HOST': 'localhost',
        'PORT': 6379,
        'PASSWORD': 'RedisPasswordNetBox',
        'DATABASE': 1,            # Unique ID for the second database
        'SSL': False,
    }
}

# Secret key
SECRET_KEY = '-BMW#USk(!-6hAEF-8Ng0detz6ex&+j0Kbe46bi=*jsF9T888*'

Save and close the file, then run the below script ‘/opt/netbox/upgrade.sh to start the NetBox IRM installation:

sudo -u netbox /opt/netbox/upgrade.sh

Step 5. Configure NetBox IRM.

First, run the below command to activate the Python virtual environment for your NetBox installation:

source /opt/netbox/venv/bin/activate

After that, move the working directory to ‘/opt/netbox/netbox‘ and run the Django script ‘manage.py‘ to create a new NetBox admin user:

cd /opt/netbox/netbox
python3 manage.py createsuperuser

Next, we set up cron that will be run on a daily basis. The script ‘netbox-housekeeping.sh‘ is used to clean up your NetBox environment, this will remove expired tasks, old sessions, or any expired records:

sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping

Now set up NetBox to run with Gunicorn:

sudo -u netbox cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
sudo -u netbox nano /opt/netbox/gunicorn.py

Change the ‘bind‘ parameter with the following line:

bind = '127.0.0.1:8000'

Save and close the file, then copy the default systemd services for NetBox to the ‘/etc/systemd/system‘ directory. This will copy the service file ‘netbox‘ and ‘netbox-rq‘ that will be used to manage NetBox:

sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/

Finally, run the systemctl a command utility to reload the systemd manager and apply new changes to your system:

sudo systemctl daemon-reload
sudo systemctl start netbox netbox-rq
sudo systemctl enable netbox netbox-rq

Step 6. Configure Firewall.

If you are using firewalld, allow the ports through the firewall:

sudo firewall-cmd --permanent --add-port={80,443,8000}/tcp
sudo firewall-cmd --reload

You can verify by listing the current firewall settings:

sudo firewall-cmd --permanent --list-all

Step 7. Accessing NetBox Web Interface.

Once successfully installed, open your web browser and access the NetBox WebUI using the URL http://.your-IP-address:8000. You should see the following page:

Install NetBox on Rocky Linux 9

Congratulations! You have successfully installed NetBox. Thanks for using this tutorial for installing NetBox IRM on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official NetBox website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button