1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

270 lines
9.4 KiB
Markdown
Raw Normal View History

2020-03-05 17:23:56 -05:00
# NetBox Installation
This section of the documentation discusses installing and configuring the NetBox application. Begin by installing all system packages required by NetBox and its dependencies:
2017-10-12 13:38:23 -04:00
2020-02-26 11:40:31 -05:00
## Install System Packages
2020-03-05 17:23:56 -05:00
### Ubuntu
2016-07-08 16:00:53 -04:00
2016-11-30 12:10:46 -05:00
```no-highlight
# apt-get install -y python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev
```
2020-03-05 17:23:56 -05:00
### CentOS
```no-highlight
2020-02-26 11:40:31 -05:00
# yum install -y gcc python36 python36-devel python36-setuptools libxml2-devel libxslt-devel libffi-devel openssl-devel redhat-rpm-config
# easy_install-3.6 pip
```
2016-07-08 16:00:53 -04:00
2020-02-26 11:40:31 -05:00
## Download NetBox
2016-07-08 16:00:53 -04:00
You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub.
2020-02-26 11:40:31 -05:00
### Option A: Download a Release
2016-07-08 16:00:53 -04:00
Download the [latest stable release](https://github.com/netbox-community/netbox/releases) from GitHub as a tarball or ZIP archive and extract it to your desired path. In this example, we'll use `/opt/netbox`.
2016-07-08 16:00:53 -04:00
```no-highlight
# wget https://github.com/netbox-community/netbox/archive/vX.Y.Z.tar.gz
2016-07-08 16:00:53 -04:00
# tar -xzf vX.Y.Z.tar.gz -C /opt
# cd /opt/
# ln -s netbox-X.Y.Z/ netbox
# cd /opt/netbox/
```
2020-02-26 11:40:31 -05:00
### Option B: Clone the Git Repository
2016-07-08 16:00:53 -04:00
Create the base directory for the NetBox installation. For this guide, we'll use `/opt/netbox`.
```no-highlight
2016-11-30 12:01:45 -05:00
# mkdir -p /opt/netbox/ && cd /opt/netbox/
2016-07-08 16:00:53 -04:00
```
If `git` is not already installed, install it:
2020-02-26 11:40:31 -05:00
#### Ubuntu
```no-highlight
# apt-get install -y git
```
2020-02-26 11:40:31 -05:00
#### CentOS
```no-highlight
# yum install -y git
2016-07-08 16:00:53 -04:00
```
Next, clone the **master** branch of the NetBox GitHub repository into the current directory:
```no-highlight
# git clone -b master https://github.com/netbox-community/netbox.git .
2016-07-08 16:00:53 -04:00
Cloning into '.'...
remote: Counting objects: 1994, done.
remote: Compressing objects: 100% (150/150), done.
remote: Total 1994 (delta 80), reused 0 (delta 0), pack-reused 1842
Receiving objects: 100% (1994/1994), 472.36 KiB | 0 bytes/s, done.
Resolving deltas: 100% (1495/1495), done.
Checking connectivity... done.
```
## Create the NetBox User
Create a system user account named `netbox`. We'll configure the WSGI and HTTP services to run under this account. We'll also assign this user ownership of the media directory. This ensures that NetBox will be able to save local files.
!!! note
CentOS users may need to create the `netbox` group first.
```
# adduser --system --group netbox
# chown --recursive netbox /opt/netbox/netbox/media/
```
## Set Up Python Environment
2016-07-08 16:00:53 -04:00
We'll use a Python [virtual environment](https://docs.python.org/3.6/tutorial/venv.html) to ensure NetBox's required packages don't conflict with anything in the base system. This will create a directory named `venv` in our NetBox root.
2016-07-08 16:00:53 -04:00
```no-highlight
# python3 -m venv /opt/netbox/venv
```
Next, activate the virtual environment and install the required Python packages. You should see your console prompt change to indicate the active environment. (Activating the virtual environment updates your command shell to use the local copy of Python that we just installed for NetBox instead of the system's Python interpreter.)
```no-highlight
# source venv/bin/activate
(venv) # pip3 install -r requirements.txt
```
2020-03-05 17:23:56 -05:00
### NAPALM Automation (Optional)
NetBox supports integration with the [NAPALM automation](https://napalm-automation.net/) library. NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. Installation of NAPALM is optional. To enable it, install the `napalm` package:
```no-highlight
(venv) # pip3 install napalm
```
To ensure NAPALM is automatically re-installed during future upgrades, create a file named `local_requirements.txt` in the NetBox root directory (alongside `requirements.txt`) and list the `napalm` package:
```no-highlight
# echo napalm >> local_requirements.txt
```
2020-03-05 17:23:56 -05:00
### Remote File Storage (Optional)
2019-12-11 11:01:08 -05:00
By default, NetBox will use the local filesystem to storage uploaded files. To use a remote filesystem, install the [`django-storages`](https://django-storages.readthedocs.io/en/stable/) library and configure your [desired backend](../../configuration/optional-settings/#storage_backend) in `configuration.py`.
```no-highlight
(venv) # pip3 install django-storages
2019-12-11 11:01:08 -05:00
```
Don't forget to add the `django-storages` package to `local_requirements.txt` to ensure it gets re-installed during future upgrades:
```no-highlight
# echo django-storages >> local_requirements.txt
```
2020-02-26 11:40:31 -05:00
## Configuration
2016-07-08 16:00:53 -04:00
Move into the NetBox configuration directory and make a copy of `configuration.example.py` named `configuration.py`.
```no-highlight
(venv) # cd netbox/netbox/
(venv) # cp configuration.example.py configuration.py
2016-07-08 16:00:53 -04:00
```
Open `configuration.py` with your preferred editor and set the following variables:
* `ALLOWED_HOSTS`
* `DATABASE`
* `REDIS`
* `SECRET_KEY`
2016-07-08 16:00:53 -04:00
2020-02-26 11:40:31 -05:00
### ALLOWED_HOSTS
2016-07-08 16:00:53 -04:00
This is a list of the valid hostnames by which this server can be reached. You must specify at least one name or IP address.
Example:
2016-11-30 12:01:45 -05:00
```python
2016-07-08 16:00:53 -04:00
ALLOWED_HOSTS = ['netbox.example.com', '192.0.2.123']
```
2020-02-26 11:40:31 -05:00
### DATABASE
2016-07-08 16:00:53 -04:00
2019-09-28 00:41:09 -04:00
This parameter holds the database configuration details. You must define the username and password used when you configured PostgreSQL. If the service is running on a remote host, replace `localhost` with its address. See the [configuration documentation](../../configuration/required-settings/#database) for more detail on individual parameters.
2016-07-08 16:00:53 -04:00
Example:
2016-11-30 12:01:45 -05:00
```python
2016-07-08 16:00:53 -04:00
DATABASE = {
'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
2016-07-08 16:00:53 -04:00
}
```
2020-02-26 11:40:31 -05:00
### REDIS
2019-09-28 00:41:09 -04:00
Redis is a in-memory key-value store required as part of the NetBox installation. It is used for features such as webhooks and caching. Redis typically requires minimal configuration; the values below should suffice for most installations. See the [configuration documentation](../../configuration/required-settings/#redis) for more detail on individual parameters.
```python
REDIS = {
'webhooks': {
'HOST': 'redis.example.com',
'PORT': 1234,
'PASSWORD': 'foobar',
'DATABASE': 0,
'DEFAULT_TIMEOUT': 300,
'SSL': False,
},
'caching': {
'HOST': 'localhost',
'PORT': 6379,
'PASSWORD': '',
'DATABASE': 1,
'DEFAULT_TIMEOUT': 300,
'SSL': False,
}
}
```
2020-02-26 11:40:31 -05:00
### SECRET_KEY
Generate a random secret key of at least 50 alphanumeric characters. This key must be unique to this installation and must not be shared outside the local system.
You may use the script located at `netbox/generate_secret_key.py` to generate a suitable key.
!!! note
In the case of a highly available installation with multiple web servers, `SECRET_KEY` must be identical among all servers in order to maintain a persistent user session state.
2020-02-26 11:40:31 -05:00
## Run Database Migrations
2016-07-08 16:00:53 -04:00
2017-10-12 13:38:23 -04:00
Before NetBox can run, we need to install the database schema. This is done by running `python3 manage.py migrate` from the `netbox` directory (`/opt/netbox/netbox/` in our example):
2016-07-08 16:00:53 -04:00
```no-highlight
(venv) # cd /opt/netbox/netbox/
(venv) # python3 manage.py migrate
2016-07-08 16:00:53 -04:00
Operations to perform:
Apply all migrations: dcim, sessions, admin, ipam, utilities, auth, circuits, contenttypes, extras, secrets, users
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
...
```
If this step results in a PostgreSQL authentication error, ensure that the username and password created in the database match what has been specified in `configuration.py`
2020-02-26 11:40:31 -05:00
## Create a Super User
2016-07-08 16:00:53 -04:00
NetBox does not come with any predefined user accounts. You'll need to create a super user to be able to log into NetBox:
```no-highlight
(venv) # python3 manage.py createsuperuser
2016-07-08 16:00:53 -04:00
Username: admin
Email address: admin@example.com
Password:
Password (again):
2016-07-08 16:00:53 -04:00
Superuser created successfully.
```
2020-02-26 11:40:31 -05:00
## Collect Static Files
2016-07-08 16:00:53 -04:00
```no-highlight
(venv) # python3 manage.py collectstatic --no-input
2016-07-08 16:00:53 -04:00
2019-12-12 14:07:06 -05:00
959 static files copied to '/opt/netbox/netbox/static'.
2016-07-08 16:00:53 -04:00
```
2020-02-26 11:40:31 -05:00
## Test the Application
2016-07-08 16:00:53 -04:00
At this point, NetBox should be able to run. We can verify this by starting a development instance:
```no-highlight
(venv) # python3 manage.py runserver 0.0.0.0:8000 --insecure
2016-07-08 16:00:53 -04:00
Performing system checks...
System check identified no issues (0 silenced).
November 28, 2018 - 09:33:45
Django version 2.0.9, using settings 'netbox.settings'
2016-07-08 16:00:53 -04:00
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
```
Next, connect to the name or IP of the server (as defined in `ALLOWED_HOSTS`) on port 8000; for example, <http://127.0.0.1:8000/>. You should be greeted with the NetBox home page. Note that this built-in web service is for development and testing purposes only. **It is not suited for production use.**
2016-07-08 16:00:53 -04:00
!!! warning
If the test service does not run, or you cannot reach the NetBox home page, something has gone wrong. Do not proceed with the rest of this guide until the installation has been corrected.
2019-12-12 14:07:06 -05:00
Note that the initial UI will be locked down for non-authenticated users.
![NetBox UI as seen by a non-authenticated user](../media/installation/netbox_ui_guest.png)
After logging in as the superuser you created earlier, all areas of the UI will be available.
![NetBox UI as seen by an administrator](../media/installation/netbox_ui_admin.png)