Rabu, 18 November 2020

DATA CENTER-netbox/ipam

 

How to Install NetBox on Ubuntu 18.04 LTS

How to Install NetBox on Ubuntu 18.04 LTS is the heading of our article today. NetBox is an open source IPAM / DCIM web application used for managing and documenting computer networks and managing IP addresses. It was Initially conceived by the network engineering team at DigitalOcean.

Netbox encompasses the following aspects of network management:

  • IP address management (IPAM) – IP networks and addresses, VRFs, and VLANs
  • Equipment racks – Organized by group and site
  • Devices – Types of devices and where they are installed
  • Connections – Network, console, and power connections among devices
  • Virtualization – Virtual machines and clusters
  • Data circuits – Long-haul communications circuits and providers
  • Secrets – Encrypted storage of sensitive credentials

If you’re interested in deploying Netbox on CentOS 7, check:

.td_uid_2_5d9071ba471e8_rand.td-a-rec-img{text-align:left}.td_uid_2_5d9071ba471e8_rand.td-a-rec-img img{margin:0 auto 0 0}

How to Install NetBox on CentOS 7 with Apache and Supervisord

Install NetBox on Ubuntu 18.04 LTS

This section will discuss the actual steps you need to follow to have NetBox installed on your Ubuntu 18.04 LTS server. Follow them in order of the appearance, though you can skip a part if you have the software being installed already configiured.

Step 1: Install required dependencies

Start by installing all dependency applications required to run NetBox on Ubuntu 18.04 LTS.

sudo apt-get install -y git gcc nginx supervisor python3 python3-dev python3-pip python3-setuptools build-essential libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev zlib1g-dev

Step 2: Install and configure PostgreSQL database server

NetBox uses PostgreSQL database server to store its data. So install and configure it on Ubuntu 18.04 using our previous guide below:

Install PostgreSQL 11 on Ubuntu 18.04 / Ubuntu 16.04

The Create a database and user for NetBox.

$ sudo -u postgres psql

CREATE DATABASE netbox;
CREATE USER netbox WITH PASSWORD 'StrongPassword';
GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
q

Confirm that you can login to database as netbox user.

# psql -U netbox -h localhost -W
Password:
psql (11.1 (Ubuntu 11.1-1.pgdg18.04+1))
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
netbox=>

Step 3: Install and configure Netbox

Change to /opt/ directory

cd /opt/
git clone -b master https://github.com/digitalocean/netbox.git

Create a configuration file

cd netbox/netbox/netbox/
sudo cp configuration.example.py configuration.py

Edit the configuration file and set allowed host and database login details

# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
ALLOWED_HOSTS = ['192.168.121.31']

# PostgreSQL database configuration.
DATABASE = {
    'NAME': 'netbox',                           # Database name
    'USER': 'netbox',                           # PostgreSQL username
    'PASSWORD': 'StrongPassword',               # PostgreSQL password
    'HOST': 'localhost',                        # Database server
    'PORT': '',                                 # Database port (leave blank for default)
}

Replace 192.168.121.31 with your Netbox server IP address.

Generate Django SECRET Key:

cd /opt/netbox/netbox
sudo ./generate_secret_key.py

Then set the key on the file /opt/netbox/netbox/netbox/configuration.py

Example:

SECRET_KEY = '30m&[email protected]=^l8wqtjw2$!3j%=f2!zh_sey+13jg%3$'

Install Netbox dependencies

sudo pip3 install -r /opt/netbox/requirements.txt

Migrate database data:

cd /opt/netbox/netbox/
sudo python3 manage.py migrate

Sample output for database migration.

Applying circuits.0014_circuittermination_description... OK
  Applying dcim.0067_device_type_remove_qualifiers... OK
  Applying dcim.0068_rack_new_fields... OK
  Applying tenancy.0004_tags... OK
  Applying tenancy.0005_change_logging... OK
  Applying extras.0001_initial_squashed_0010_customfield_filter_logic... OK
  Applying extras.0011_django2... OK
  Applying extras.0012_webhooks... OK
  Applying extras.0013_objectchange... OK
  Applying extras.0014_configcontexts... OK
  Applying extras.0015_remove_useraction... OK
  Applying extras.0016_exporttemplate_add_cable... OK
  Applying ipam.0021_vrf_ordering... OK
  Applying ipam.0022_tags... OK
  Applying ipam.0023_change_logging... OK
  Applying secrets.0001_initial_squashed_0003_unicode_literals... OK
  Applying secrets.0004_tags... OK
  Applying secrets.0005_change_logging... OK
  Applying sessions.0001_initial... OK
  Applying users.0001_api_tokens_squashed_0002_unicode_literals... OK
  Applying users.0003_token_permissions... OK
  Applying virtualization.0002_virtualmachine_add_status_squashed_0004_virtualmachine_add_role... OK
  Applying virtualization.0005_django2... OK
  Applying virtualization.0006_tags... OK
  Applying virtualization.0007_change_logging... OK
  Applying virtualization.0008_virtualmachine_local_context_data... OK

Create admin user:

$ sudo python3 manage.py createsuperuser

Username (leave blank to use 'root'): admin
Email address: [email protected]
Password: <Enter Password>
Password (again): <Re-enter Password>
Superuser created successfully.

Move static files

$ cd /opt/netbox/netbox
$ sudo python3 manage.py collectstatic
280 static files copied to '/opt/netbox/netbox/static'.

Load initial data

$ sudo python3 manage.py loaddata initial_data
Installed 53 object(s) from 5 fixture(s)

Install and Configure gunicorn

Install gunicorn using pip3:

$ sudo pip3 install gunicorn
Collecting gunicorn
Downloading https://files.pythonhosted.org/packages/8c/da/b8dd8deb741bff556db53902d4706774c8e1e67265f69528c14c003644e6/gunicorn-19.9.0-py2.py3-none-any.whl (112kB) 100% |████████████████████████████████| 122kB 737kB/s
Installing collected packages: gunicorn
Successfully installed gunicorn-19.9.0

Configure gunicorn for Netbox

cat<<EOF | sudo tee /opt/netbox/gunicorn_config.py
command = '/usr/local/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = '192.168.121.31:8085'
workers = 3
user = 'www-data'
EOF

Create a supervisord configuration file

cat <<EOF | sudo tee /etc/supervisor/conf.d/netbox.conf
[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = www-data
EOF

Restart and enable supervisord service to start on boot.

sudo systemctl restart supervisor.service
sudo systemctl enable supervisor.service

Status should show running with netbox output.

$ systemctl status  supervisor
supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-01-13 06:28:55 PST; 4s ago
Docs: http://supervisord.org
Process: 28799 ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown (code=exited, status=0/SUCCESS)
Main PID: 28830 (supervisord)
Tasks: 5 (limit: 1110)
CGroup: /system.slice/supervisor.service
|-28830 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
|-28850 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
|-28855 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
|-28857 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
`-28859 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
Jan 13 06:28:55 ubuntu-01 systemd[1]: Started Supervisor process control system for UNIX.
Jan 13 06:28:55 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:55,572 CRIT Supervisor running as root (no user in config file)
Jan 13 06:28:55 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:55,572 INFO Included extra file "/etc/supervisor/conf.d/netbox.conf" during parsing
Jan 13 06:28:55 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:55,580 INFO RPC interface 'supervisor' initialized
Jan 13 06:28:55 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:55,580 CRIT Server 'unix_http_server' running without any HTTP authentication checking
Jan 13 06:28:55 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:55,580 INFO supervisord started with pid 28830
Jan 13 06:28:56 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:56,583 INFO spawned: 'netbox' with pid 28850
Jan 13 06:28:57 ubuntu-01 supervisord[28830]: 2019-01-13 06:28:57,871 INFO success: netbox entered RUNNING state, process has stayed up for > than 1 se

Configure Nginx Web Server

Let’s configure Nginx web server to help us access Netbox via Domain name rather than specifying an IP address and a port.

Create new Nginx configuration file for Netbox.

sudo vim /etc/nginx/conf.d/netbox.conf

With below data.

server {
    listen 80;
    server_name netbox.example.com;
    client_max_body_size 25m;

    location /static/ {
        alias /opt/netbox/netbox/static/;
    }

    location / {
        proxy_pass http://192.168.121.31:8001;
    }
}

Check Nginx configuration syntax and restart its service

$ sudo  nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If OK, restart Nginx service

sudo systemctl restart nginx

Access Netbox Web UI

Open your default web browser and open Netbox server hostname. To make changes, login with admin user created earlier.

Enjoy using Netbox to document your network infrastructure.

You can also check:

Install and Configure phpIPAM on Ubuntu 18.04

How to install RackTables on Ubuntu 18.04 / Ubuntu 16.04 LTS

.td-a-rec-img{text-align:left}.td-a-rec-img img{margin:0 auto 0 0}

Tidak ada komentar:

Posting Komentar