Created
November 15, 2017 15:42
-
-
Save maldonadojuan/153775f869663021526965dfe3430364 to your computer and use it in GitHub Desktop.
NetBoxInstallonUbuntu1604
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###NetBox Install### | |
#update repos | |
sudo apt-get update | |
#install postgresql | |
sudo apt-get install -y postgresql libpq-dev | |
#go into sql with user postgres | |
sudo -u postgres psql | |
psql (9.4.5) | |
Type "help" for help. | |
postgres=# | |
CREATE DATABASE netbox; | |
#output: CREATE DATABASE | |
postgres=# | |
CREATE USER netbox WITH PASSWORD 'yourSQLpasswordHere'; | |
#output: CREATE ROLE | |
postgres=# | |
GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox; | |
#output: GRANT | |
#quit out of sql CLI | |
postgres=# | |
\q | |
#install python dependencies | |
sudo apt-get install -y python3 python3-dev python3-setuptools build-essential libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev zlib1g-dev | |
#install pip | |
sudo easy_install3 pip | |
#make the install directory and go to it | |
sudo mkdir -p /opt/netbox/ && cd /opt/netbox/ | |
#install git | |
sudo apt-get install -y git | |
#clone the master repo for netbox | |
sudo git clone -b master https://github.com/digitalocean/netbox.git . | |
#verify version of pip v9.0.1 or higher | |
pip3 -V | |
#install the program from the requirements | |
sudo pip3 install -r requirements.txt | |
#move into netbox config directory | |
cd netbox/netbox/ | |
#make a copy of config.example.py | |
sudo cp configuration.example.py configuration.py | |
#Open configuration.py with your preferred editor and set the following variables: | |
sudo vim /opt/netbox/netbox/netbox/configuration.py | |
#ALLOWED_HOSTS | |
ALLOWED_HOSTS = ['netbox.example.com', '192.168.10.10'] | |
#DATABASE | |
DATABASE = { | |
'NAME': 'netbox', # Database name | |
'USER': 'netbox', # PostgreSQL username | |
'PASSWORD': 'yourSQLpasswordHere', # PostgreSQL password | |
'HOST': 'localhost', # Database server | |
'PORT': '', # Database port (leave blank for default) | |
} | |
#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. | |
python3 /opt/netbox/netbox/generate_secret_key.py | |
#copy the output of the key generation command above and paste it in the configuration.py file in the secret section | |
sudo vim /opt/netbox/netbox/netbox/configuration.py | |
#move to this dir | |
cd /opt/netbox/netbox/ | |
#run this command to install the schema | |
python3 manage.py migrate | |
#create netbox su | |
python3 manage.py createsuperuser | |
# output: Username: admin | |
# output: Email address: admin@contoso.com | |
# output: Password: webuserPasswordHere | |
# output: Password (again): webuserPasswordHere | |
# output: Superuser created successfully. | |
#collect static files | |
sudo python3 manage.py collectstatic --no-input | |
yes | |
#test the application by starting a dev instance | |
python3 manage.py runserver 0.0.0.0:8000 --insecure | |
# output: Performing system checks... | |
# output: | |
# output: System check identified no issues (0 silenced). | |
# output: June 17, 2016 - 16:17:36 | |
# output: Django version 1.9.7, using settings 'netbox.settings' | |
# output: Starting development server at http://0.0.0.0:8000/ | |
# output: Quit the server with CONTROL-C. | |
#install nginx | |
sudo apt-get install -y nginx | |
#create and edit the config file with below info | |
sudo vim /etc/nginx/sites-available/netbox | |
#save the following config to /etc/nginx/sites-available/netbox | |
######################################################################################## | |
server { | |
listen 80; | |
server_name netbox.example.com; | |
client_max_body_size 25m; | |
location /static/ { | |
alias /opt/netbox/netbox/static/; | |
} | |
location / { | |
proxy_pass http://127.0.0.1:8001; | |
proxy_set_header X-Forwarded-Host $server_name; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; | |
} | |
} | |
######################################################################################## | |
#delete default config and create a symlink in sites-enabled | |
cd /etc/nginx/sites-enabled/ | |
sudo rm default | |
sudo ln -s /etc/nginx/sites-available/netbox | |
#restart the service to use new config | |
sudo service nginx restart | |
#install gunicorn | |
sudo pip3 install gunicorn | |
#create file and save the below config | |
sudo vim /opt/netbox/gunicorn_config.py | |
#save the config as /opt/netbox/gunicorn_config.py | |
######################################################################################## | |
command = '/usr/bin/gunicorn' | |
pythonpath = '/opt/netbox/netbox' | |
bind = '127.0.0.1:8001' | |
workers = 3 | |
user = 'www-data' | |
######################################################################################## | |
#install supervisor | |
sudo apt-get install -y supervisor | |
#create file and save the below config | |
sudo vim /etc/supervisor/conf.d/netbox.conf | |
#save the config as /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 | |
######################################################################################## | |
#restart the supervisor service | |
sudo service supervisor restart | |
#change the permissions of the image directory | |
#audit this. this change will get it working but might be too loose. | |
sudo chmod 777 -R image-attachments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment