===== NetBox on Amazon Linux AMI =====
{{tag>Linux Netbox AWS}}
This is my attempt to install NetBox in an AWS EC2 instance on AWS Linux.\\
https://netbox.readthedocs.io/en/latest/
====1====
$ sudo yum install openssl-devel gcc git postgresql92 postgresql92-server libpqxx-devel python27-psycopg2 python27 python27-devel python27-pip libxml2-devel libxslt-devel libffi-devel graphviz
$ sudo mkdir /var/www/netbox
$ sudo chmod USERNAME:USERNAME /home/www/netbox
$ cd /var/www/netbox
$ git clone -b master https://github.com/digitalocean/netbox.git .
====2====
$ sudo dd if=/dev/zero of=/var/swap.1 bs=1M count=2048
$ sudo mkswap /var/swap.1
$ sudo chmod 600 /var/swap.1
$ sudo swapon /var/swap.1
$ sudo echo "/var/swap.1 swap swap defaults 0 0" >> /etc/fstab
$ sudo pip install -r /var/www/netbox/requirements.txt
====3====
$ sudo service postgresql92 initdb
$ sudo service postgresql92 start
$ sudo -u postgres psql
psql (9.2.15)
Type "help" for help.
postgres=# CREATE DATABASE netbox;
CREATE DATABASE
postgres=# CREATE USER netbox WITH PASSWORD 'DBPASSWORD';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
GRANT
postgres=# \q
$ sudo vim /var/lib/pgsql92/data/pg_hba.conf
> local all all md5
> host all all 127.0.0.1/32 md5
$ sudo service postgresql92 restart
$ psql -U netbox -W
Password for user netbox:
psql (9.2.15)
Type "help" for help.
netbox=> \q
$
====4====
$ cd /var/www/netbox/netbox/netbox
$ cp configuration.example.py configuration.py
$ ../generate_secret_key.py
abcde12345abcde12345abcde12345abcde12345abcde12345
$ vim configuration.py
> ALLOWED_HOSTS = ['127.0.0.1', '192.168.20.10', '50.40.30.20', 'netbox.domain.com']
> DATABASE = {
> 'NAME': 'netbox', # Database name
> 'USER': 'netbox', # PostgreSQL username
> 'PASSWORD': 'DBPASSWORD', # PostgreSQL password
> 'HOST': 'localhost', # Database server
> 'PORT': '', # Database port (leave blank for default)
> SECRET_KEY = 'abcde12345abcde12345abcde12345abcde12345abcde12345'
}
$ sudo su -
# pip install -U pynotify
# exit
$ cd /var/www/netbox/netbox
$./manage.py migrate
====5====
$ ./manage.py createsuperuser
Username (leave blank to use 'admin'):
Email address: admin@domain.com
Password:
Password (again):
Superuser created successfully.
====6====
$ ./manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
/var/www/netbox/netbox/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying '/var/www/netbox/netbox/project-static/css/base.css'
.
.
.
Copying '/usr/local/lib/python2.7/site-packages/rest_framework_swagger/static/rest_framework_swagger/images/throbber.gif'
212 static files copied to '/var/www/netbox/netbox/static'.
$ ./manage.py runserver 0.0.0.0:8000 --insecure
Performing system checks...
System check identified no issues (0 silenced).
July 11, 2016 - 22:09:39
Django version 1.9.7, using settings 'netbox.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[11/Jul/2016 22:12:57] "GET / HTTP/1.1" 200 14741
.
.
.
[11/Jul/2016 22:12:58] "GET /favicon.ico HTTP/1.1" 404 85
^C
$
====7====
$ sudo vim /etc/httpd/conf/httpd.conf
> NameVirtualHost *:80
> NameVirtualHost *:443
$ sudo vim /etc/httpd/conf.d/netbox.conf
>
> ProxyPreserveHost On
>
> ServerName netbox.nerdydrunk.com
>
> Alias /static /var/www/netbox/netbox/static
>
>
> Options Indexes FollowSymLinks MultiViews
> AllowOverride None
> Require all granted
>
>
>
> ProxyPass !
>
>
> ProxyPass / http://127.0.0.1:8001/
> ProxyPassReverse / http://127.0.0.1:8001/
>
$ sudo service httpd restart
====8====
I am currently having issues getting gunicorn and supervisord working correctly.
$ vim /var/www/netbox/gunicorn_config.py
> command = '/usr/bin/gunicorn'
> pythonpath = '/var/www/netbox/netbox'
> bind = '127.0.0.1:8001'
> workers = 3
> user = 'apache'
$ sudo vim /etc/supervisord.conf
> [program:netbox]
> command = gunicorn -c /var/www/netbox/gunicorn_config.py netbox.wsgi
> directory = /var/netbox/netbox/netbox/
> user = apache
$ sudo su -
# pip install supervisor
# exit
$ sudo service supervisord start