Option A One Command Install
curl -fsSL https://raw.githubusercontent.com/mhdhaidarah/Netbox/main/install-netbox.sh | sudo bash
curl -fsSL https://raw.githubusercontent.com/mhdhaidarah/Netbox/main/backup-netbox.sh | sudo bash
curl -fsSL https://raw.githubusercontent.com/mhdhaidarah/Netbox/main/restore-netbox.sh | sudo bash
curl -fsSL https://raw.githubusercontent.com/mhdhaidarah/Netbox/main/restore-netbox.sh | sudo bash -s -- "/file/directory/name.tar.gz"
sudo apt update
sudo apt install -y PostgreSQL
Create Database with user
CREATE DATABASE netbox;
CREATE USER netbox WITH PASSWORD 'J5brHrAXFLQSif0K';
ALTER DATABASE netbox OWNER TO netbox;
\q
psql --username netbox --password --host localhost netbox
sudo apt install -y redis-server
sudo apt install -y python3 python3-pip python3-venv python3-dev \
build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev \
libssl-dev zlib1g-dev
sudo mkdir -p /opt/netbox/
cd /opt/netbox/
sudo apt install -y git
sudo git clone https://github.com/netbox-community/netbox.git .
sudo adduser --system --group netbox
sudo chown --recursive netbox /opt/netbox/netbox/media/
sudo chown --recursive netbox /opt/netbox/netbox/reports/
sudo chown --recursive netbox /opt/netbox/netbox/scripts/
cd /opt/netbox/netbox/netbox/
sudo cp configuration_example.py configuration.py
python3 ../generate_secret_key.py
sudo nano /opt/netbox/netbox/netbox/configuration.py
Final file configuration.py
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql', # Database engine
'NAME': 'netbox', # Database name
'USER': 'netbox', # PostgreSQL username
'PASSWORD': 'J5brHrAXFLQSif0K', # PostgreSQL password
'HOST': 'localhost', # Database server
'PORT': '', # Database port (leave blank for default)
'CONN_MAX_AGE': 300, # Max database connection age
}
}
# DO NOT USE THIS EXAMPLE PEPPER IN PRODUCTION
SECRET_KEY = 'lbHcPYHGVI@6(l*9)aQTm1T-VdYvhVL@EMc0N#p902UrVJnpOZ'
API_TOKEN_PEPPERS = {
# DO NOT USE THIS EXAMPLE PEPPER IN PRODUCTION
1: 'lbHcPYHGVI@6(l*9)aQTm1T-VdYvhVL@EMc0N#p902UrVJnpOZ',
}
PLUGINS = [
"netbox_qrcode",
"netbox_reorder_rack",
"netbox_topology_views",
]
#Save and Exit
Final Step to Install Netbox
sudo /opt/netbox/upgrade.sh
source /opt/netbox/venv/bin/activate
cd /opt/netbox/netbox
python3 manage.py createsuperuser
Access using http://<server_ip>:8000
python3 manage.py runserver 0.0.0.0:8000 --insecure
Convert To Service Using Nginx
sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now netbox netbox-rq
systemctl status netbox.service
sudo su
source /opt/netbox/venv/bin/activate
pip3 install pyuwsgi
sudo sh -c "echo 'pyuwsgi' >> /opt/netbox/local_requirements.txt"
sudo cp /opt/netbox/contrib/uwsgi.ini /opt/netbox/uwsgi.ini
sudo cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now netbox netbox-rq
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
-keyout /etc/ssl/private/netbox.key \
-out /etc/ssl/certs/netbox.crt \
-subj "/CN=<IP ADDRESS>" \
-addext "subjectAltName = IP:<IP ADDRESS>"
sudo apt install -y nginx
sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netbox
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox
sudo systemctl restart nginx
sudo apt update && sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential libssl-dev libffi-dev libsqlite3-dev wget curl git
git clone https://github.com/netbox-community/Device-Type-Library-Import.git
cd Device-Type-Library-Import
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
Now Setup URL to the NetBox Server & Token the token can be generated from GUI Users and select V1
NETBOX_URL=https://192.168.0.100:8000
NETBOX_TOKEN=LE0GCreKBP0v3jbXauWLVqbmzKtH3BnhI1Z184TV
REPO_URL=https://github.com/netbox-community/devicetype-library.git
REPO_BRANCH=master
IGNORE_SSL_ERRORS=True
#REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt # you should enable this if you are running on a linux sys>
#SLUGS=c9300-48u isr4431 isr4331
Install Device Library Importer
git clone https://github.com/netbox-community/devicetype-library.git ~/Device-Type-Library-Import/repo
Select Vendors or download all
./nb-dt-import.py --vendors mikrotik,ubiquiti
source /opt/netbox/venv/bin/activate
pip install netbox-napalm-plugin
pip3 install netbox-topology-views
pip install netbox-qrcode
pip install netbox-reorder-rack
sudo nano /opt/netbox/netbox/netbox/configuration.py
PLUGINS = [
'netbox_napalm_plugin','netbox_topology_views','netbox_qrcode','netbox_reorder_rack'
]
PLUGINS_CONFIG = {
'netbox_napalm_plugin': {
'NAPALM_USERNAME': 'xxx',
'NAPALM_PASSWORD': 'yyy',
},
}
cd /opt/netbox/netbox/
python3 manage.py migrate
python3 manage.py migrate netbox_topology_views
python3 manage.py collectstatic --no-input
echo netbox-topology-views >> /opt/netbox/local_requirements.txt
echo netbox-reorder-rack >> local_requirements.txt
sudo systemctl restart netbox