안녕하세요 HiDAN 입니다!
이번 포스팅에서는 네트워크 인프라 및 자산 관리를 위한 오픈소스 솔루션 NetBox를 Docker를 활용해 구축하는 방법에 대해 알아보겠습니다.
NetBox는 데이터센터 및 네트워크의 관리 및 자동화에 사용할 수 있는 솔루션인데요.
잘 활용하신다면 업무를 효율적으로 할 수 있을 것 같아 한번 소개해 보도록 하겠습니다. 🖥️🌐
Netbox 설치하기
먼저 github의 NetBox 프로젝트를 가져옵니다.
user@ubuntu:~$ git clone -b release https://github.com/netbox-community/netbox-docker.git
Cloning into 'netbox-docker'...
remote: Enumerating objects: 4974, done.
remote: Counting objects: 100% (203/203), done.
remote: Compressing objects: 100% (102/102), done.
remote: Total 4974 (delta 156), reused 101 (delta 101), pack-reused 4771 (from 5)
Receiving objects: 100% (4974/4974), 1.27 MiB | 21.98 MiB/s, done.
Resolving deltas: 100% (2829/2829), done.
netbox-docker 디렉터리로 이동한 뒤, docker-compose.override.yml 파일을 작성해주세요.
user@ubuntu:~$ cd netbox-docker/
user@ubuntu:~/netbox-docker$ tee docker-compose.override.yml <<EOF
services:
netbox:
ports:
- 8000:8080
EOF
다음으로 docker compose 컨테이너에 필요한 이미지를 다운로드 합니다.
user@ubuntu:~/netbox-docker$ docker compose pull
[+] Pulling 37/37
✔ redis-cache Skipped - Image is already being pulled by redis 0.0s
✔ netbox-worker Skipped - Image is already being pulled by netbox 0.0s
✔ netbox-housekeeping Skipped - Image is already being pulled by netbox 0.0s
✔ redis Pulled 7.4s
✔ f18232174bc9 Pull complete 1.3s
✔ a2425531abfa Pull complete 1.5s
✔ db313a71be85 Pull complete 1.9s
✔ 07299a7518cb Pull complete 2.6s
✔ 6de4eed58048 Pull complete 2.8s
✔ 4f4fb700ef54 Pull complete 31.7s
✔ 44c748e4cf23 Pull complete 3.5s
✔ netbox Pulled 38.1s
✔ 5a7813e071bf Pull complete 8.1s
✔ 24a5f5a26ae0 Pull complete 11.5s
✔ 3a9173975334 Pull complete 11.7s
✔ a326a288f6bf Pull complete 12.4s
✔ 2f6640981c2a Pull complete 30.1s
✔ 9f8c86fcc54b Pull complete 31.2s
✔ 8141cd69f4f1 Pull complete 31.3s
✔ 13c92659365b Pull complete 31.3s
✔ 107a85fa7a37 Pull complete 31.3s
✔ f16819656a5a Pull complete 31.3s
✔ ef5b51864f4d Pull complete 31.3s
✔ fa58c4b360d4 Pull complete 31.3s
✔ febce0288ee4 Pull complete 31.3s
✔ ea49c28f49cc Pull complete 31.3s
✔ 6f877b3f5827 Pull complete 34.2s
✔ postgres Pulled 14.6s
✔ af39b319459f Pull complete 2.9s
✔ 3672837a4aa0 Pull complete 3.3s
✔ c4c273df3120 Pull complete 3.6s
✔ ebd2ffd21273 Pull complete 9.6s
✔ 93790624b6d5 Pull complete 9.8s
✔ 885bc81f5c35 Pull complete 10.0s
✔ 024fa65904c3 Pull complete 10.2s
✔ 4c12e1e35211 Pull complete 10.4s
✔ 0af2e3156b03 Pull complete
다음으로 docker compose 컨테이너를 생성 및 실행해보았지만, 아래와 같이 에러가 발생하네요😂
user@ubuntu:~/netbox-docker$ docker compose up
[+] Running 13/13
✔ Network netbox-docker_default Created 0.2s
✔ Volume "netbox-docker_netbox-postgres-data" Created 0.0s
✔ Volume "netbox-docker_netbox-redis-data" Created 0.0s
✔ Volume "netbox-docker_netbox-redis-cache-data" Created 0.1s
✔ Volume "netbox-docker_netbox-media-files" Created 0.1s
✔ Volume "netbox-docker_netbox-reports-files" Created 0.0s
✔ Volume "netbox-docker_netbox-scripts-files" Created 0.0s
✔ Container netbox-docker-redis-cache-1 Created 0.7s
✔ Container netbox-docker-postgres-1 Created 0.7s
✔ Container netbox-docker-redis-1 Created 0.7s
✔ Container netbox-docker-netbox-1 Created 0.6s
✔ Container netbox-docker-netbox-housekeeping-1 Created 0.7s
✔ Container netbox-docker-netbox-worker-1 Created 0.7s
Attaching to netbox-1, netbox-housekeeping-1, netbox-worker-1, postgres-1, redis-1, redis-cache-1
...(중략)...
Gracefully stopping... (press Ctrl+C again to force)
dependency failed to start: container netbox-docker-netbox-1 is unhealthy
알아보니 최초 컨테이너 실행 시, 컨테이너 마이그레이션 소요 시간으로 인해 헬스 체크 에러가 발생하는 거라고 합니다.
따라서 docekr-compose.override.yml 파일에 healthcheck 옵션을 추가해주셔야 합니다.
healthcheck:
start_period: 5m # Default 90s
수정하고 다시 docker-compose up -d를 실행하시면 정상 적으로 컨테이너가 실행 됩니다.
user@ubuntu:~/netbox-docker$ docker compose up -d
[+] Running 6/6
✔ Container netbox-docker-redis-1 Started 2.0s
✔ Container netbox-docker-postgres-1 Started 1.9s
✔ Container netbox-docker-redis-cache-1 Started 2.0s
✔ Container netbox-docker-netbox-1 Healthy 44.9s
✔ Container netbox-docker-netbox-housekeeping-1 Started 45.2s
✔ Container netbox-docker-netbox-worker-1 Started 45.2s
이제 브라우저를 열고, 자신의 http://서버IP:Port로 접속하시면 NetBox 화면을 볼 수 있습니다.
다음으로 admin 사용자를 생성하기 위해 다음 명령어를 입력해주세요.
패스워드는 12 characters 이상을 권장하는데, 저는 테스트용 컨테이너로 그냥 진행했습니다😁
user@ubuntu:~/netbox-docker$ docker compose exec netbox /opt/netbox/netbox/manage.py createsuperuser
🧬 loaded config '/etc/netbox/config/configuration.py'
🧬 loaded config '/etc/netbox/config/extra.py'
🧬 loaded config '/etc/netbox/config/logging.py'
🧬 loaded config '/etc/netbox/config/plugins.py'
Username: user_name
Email address: email@example.com
Password: user_password
Password (again): user_password
This password is too short. It must contain at least 12 characters.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
이제 로그인 화면에서 생성한 계정으로 로그인하시면 NetBox 메인화면을 볼 수 있습니다.
결론
여기까지 Docker로 NetBox를 설치하는 방법에 대해 알아보았습니다. 🎉
이제 NetBox를 이용해보시고 네트워크 인프라 관리를 체계적으로 관리해보세요.
감사합니다! 😊