웹사이트 검색

Ubuntu 20.04 LTS에 NetBox 네트워크 문서 및 관리 도구를 설치하는 방법


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • Ubuntu 20.04(Focal Fossa)
  • Ubuntu 18.04(Bionic Beaver)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. PostgreSQL 데이터베이스 설치 및 구성
  4. NetBox 설치 및 구성
  5. Gunicorn 설치 및 구성
  6. Supervisor 설치 및 구성
  7. NetBox용 Nginx 구성
  8. Netbox 웹 인터페이스 액세스
  9. 결론

Netbox는 강력한 무료 IP 주소(IPAM) 및 데이터 센터 인프라 관리(DCIM) 도구입니다. 네트워크, VM, 인벤토리 등에 대한 정보를 저장하는 데 사용됩니다. 원래 DigitalOcean의 네트워크 엔지니어링 팀에서 개발했습니다. 이 도구는 Django Python 프레임워크로 작성되었으며 PostgreSQL 데이터베이스에 의존합니다. 그것의 목표는 네트워크 운영을 위한 도메인 특정 소스로 기능하는 것입니다.

이 튜토리얼에서는 Ubuntu 20.04에서 역방향 프록시로 Nginx와 함께 Netbox를 설치하는 방법을 설명합니다.

전제 조건

  • Ubuntu 20.04를 실행하는 서버.\n
  • 서버에 루트 암호가 구성되어 있습니다.\n

시작하기

시작하기 전에 Netbox에 필요한 몇 가지 종속 항목을 설치해야 합니다. 다음 명령을 실행하여 모두 설치할 수 있습니다.

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

모든 패키지가 설치되면 다음 단계로 진행할 수 있습니다.

PostgreSQL 데이터베이스 설치 및 구성

Netbox는 데이터 저장을 위해 PostgreSQL 데이터베이스를 사용합니다. 다음 명령으로 설치할 수 있습니다.

apt-get install postgresql postgresql-contrib -y

PostgreSQL이 설치되면 다음 명령을 사용하여 PostgreSQL에 로그인합니다.

su - postgres
:~$ psql

다음 출력이 표시되어야 합니다.

psql (12.2 (Ubuntu 12.2-4))
Type "help" for help.

다음으로 다음 명령을 사용하여 Netbox용 데이터베이스와 사용자를 생성합니다.

postgres=# CREATE DATABASE netbox;
postgres=# CREATE USER netbox WITH PASSWORD 'password';

그런 다음 다음 명령을 사용하여 Netbox 데이터베이스에 대한 모든 권한을 부여합니다.

postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;

그런 다음 다음 명령을 사용하여 PostgreSQL 셸을 종료합니다.

postgres=# exit
:~$ exit

NetBox 설치 및 구성

먼저 디렉터리를 /opt로 변경하고 다음 명령을 사용하여 Git Hub 리포지토리에서 최신 버전의 Netbox를 다운로드합니다.

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

다음으로 다음 명령을 사용하여 Python 바이너리의 심볼릭 링크를 만듭니다.

ln -s /usr/bin/python3 /usr/bin/python

다음으로 디렉토리를 /opt/netbox/netbox/로 변경하고 다음 명령을 실행하여 Django SECRET 키를 생성합니다.

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

다음과 같은 결과가 표시되어야 합니다.

)eTDpo(k^f4Sm9bariUnK0syCPMGEIjW6XV_8l5xhB7z

다음으로 디렉토리를 netbox로 변경하고 예제 구성 파일의 이름을 바꿉니다.

cd netbox
mv configuration.example.py configuration.py

다음으로 Netbox 구성 파일을 편집하고 데이터베이스, 비밀 키 및 허용된 호스트를 정의합니다.

nano configuration.py

다음과 같이 변경합니다.

ALLOWED_HOSTS = ['your-server-ip']

# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters:
#   https://docs.djangoproject.com/en/stable/ref/settings/#databases
DATABASE = {
    'NAME': 'netbox',         # Database name
    'USER': 'netbox',               # PostgreSQL username
    'PASSWORD': 'password',           # PostgreSQL password
    'HOST': 'localhost',      # Database server
    'PORT': '',               # Database port (leave blank for default)
    'CONN_MAX_AGE': 300,      # Max database connection age
}

SECRET_KEY = ')eTDpo(k^f4Sm9bariUnK0syCPMGEIjW6XV_8l5xhB7z'

파일을 저장하고 닫은 후 다음 명령을 사용하여 모든 Python 종속성을 설치합니다.

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

그런 다음 다음 명령을 사용하여 데이터베이스를 마이그레이션합니다.

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

다음으로 다음 명령을 사용하여 Netbox 관리 사용자를 만듭니다.

python3 manage.py createsuperuser

아래와 같이 사용자 이름과 비밀번호를 입력하라는 메시지가 표시됩니다.

Username (leave blank to use 'root'): netboxadmin
Email address: 
Password: 
Password (again): 
Superuser created successfully.

다음으로 다음 명령을 사용하여 정적 파일을 수집합니다.

python3 manage.py collectstatic

다음 출력이 표시되어야 합니다.

976 static files copied to '/opt/netbox/netbox/static'.

Gunicorn 설치 및 구성

Netbox는 Django 기반 애플리케이션입니다. 따라서 시스템에 Gunicorn을 설치해야 합니다. 다음 명령을 실행하여 설치할 수 있습니다.

pip3 install gunicorn

Gunicorn을 설치한 후 다음 명령을 사용하여 Netbox용 새 Gunicorn 구성 파일을 만듭니다.

nano /opt/netbox/gunicorn_config.py

다음 줄을 추가합니다.

command = '/usr/local/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = 'your-server-ip:8001'
workers = 3
user = 'www-data'

완료되면 파일을 저장하고 닫습니다.

감독자 설치 및 구성

Supervisor는 NetBox 서비스를 모니터링하고 제어할 수 있는 클라이언트/서버 시스템입니다. 다음 명령을 사용하여 Netbox용 새 Supervisor 구성 파일을 생성할 수 있습니다.

nano /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

완료되면 파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 Supervisor 서비스를 다시 시작합니다.

systemctl restart supervisor

다음 명령을 사용하여 Supervisor 서비스의 상태를 확인할 수도 있습니다.

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 Sat 2020-05-30 05:49:08 UTC; 14s ago
       Docs: http://supervisord.org
   Main PID: 550606 (supervisord)
      Tasks: 5 (limit: 4691)
     Memory: 184.3M
     CGroup: /system.slice/supervisor.service
             ??550606 /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
             ??550626 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550628 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550629 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550630 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi

May 30 05:49:08 ubunt4 systemd[1]: Started Supervisor process control system for UNIX.
May 30 05:49:08 ubunt4 supervisord[550606]: 2020-05-30 05:49:08,664 CRIT Supervisor is running as root.  Privileges were not dropped becau>
May 30 05:49:08 ubunt4 supervisord[550606]: 2020-05-30 05:49:08,664 INFO Included extra file "/etc/supervisor/conf.d/netbox.conf" during p>
May 30 05:49:08 ubunt4 supervisord[550606]: 2020-05-30 05:49:08,671 INFO RPC interface 'supervisor' initialized
May 30 05:49:08 ubunt4 supervisord[550606]: 2020-05-30 05:49:08,671 CRIT Server 'unix_http_server' running without any HTTP authentication>
May 30 05:49:08 ubunt4 supervisord[550606]: 2020-05-30 05:49:08,672 INFO supervisord started with pid 550606
May 30 05:49:09 ubunt4 supervisord[550606]: 2020-05-30 05:49:09,676 INFO spawned: 'netbox' with pid 550626
May 30 05:49:11 ubunt4 supervisord[550606]: 2020-05-30 05:49:11,060 INFO success: netbox entered RUNNING state, process has stayed up for

NetBox용 Nginx 구성

Nginx를 역방향 프록시로 구성하여 포트 80에서 Netbox에 액세스하는 것이 좋습니다. 다음 명령을 사용하여 새 Nginx 가상 호스트 구성을 만들 수 있습니다.

nano /etc/nginx/sites-available/netbox.conf

다음 줄을 추가합니다.

server {
    listen 80;
    server_name your-server-ip;
    client_max_body_size 25m;

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

    location / {
        proxy_pass http://your-server-ip:8001;
    }
}

파일을 저장하고 닫습니다. 그런 다음 /etc/nginx/sites-enabled/ 디렉토리에 대한 심볼릭 링크를 만듭니다.

ln -s /etc/nginx/sites-available/netbox.conf /etc/nginx/sites-enabled/

다음으로 다음 명령을 사용하여 구문 오류가 있는지 Nginx를 확인합니다.

nginx -t

모든 것이 정상이면 다음과 같은 결과가 표시됩니다.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

마지막으로 Nginx 서비스를 다시 시작하여 변경 사항을 구현합니다.

systemctl restart nginx

다음 명령을 사용하여 Nginx를 확인할 수도 있습니다.

systemctl status nginx

다음과 같은 결과가 표시되어야 합니다.

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-30 22:28:13 EST; 4min 14s ago
  Process: 984 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 982 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 980 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 985 (nginx)
    Tasks: 3 (limit: 25028)
   Memory: 5.5M
   CGroup: /system.slice/nginx.service
           ??985 nginx: master process /usr/sbin/nginx
           ??986 nginx: worker process
           ??987 nginx: worker process

May 30 21:28:12 ubunt4 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 30 21:28:12 ubunt4 nginx[982]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 30 21:28:12 ubunt4 nginx[982]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 30 21:28:13 ubunt4 systemd[1]: Started The nginx HTTP and reverse proxy server.

이 시점에서 Nginx 웹 서버는 포트 80에서 Netbox를 제공하도록 구성되었습니다. 이제 계속해서 Netbox 웹 인터페이스에 액세스할 수 있습니다.

Netbox 웹 인터페이스에 액세스

웹 브라우저를 열고 URL http://your-server-ip를 방문하십시오. 다음 페이지로 리디렉션됩니다.

로그인 버튼을 클릭합니다. 다음 화면에 Netbox 로그인 페이지가 표시되어야 합니다.

Netbox 관리자 사용자 이름과 비밀번호를 제공하고 로그인 버튼을 클릭합니다. 다음 페이지에 Netbox 기본 대시보드가 표시되어야 합니다.

결론

이 가이드에서는 Nginx를 사용하여 Ubuntu 20.04에 Netbox를 설치하는 방법을 배웠습니다. 이제 네트워크 인프라 문서화를 시작할 수 있습니다. 자세한 내용은 Netbox 공식 문서를 참조하세요. 궁금한 사항이 있으면 언제든지 문의해 주세요.