반응형
우분투 22.04에서 NetBox를 설치하고 설정하는 방법
NetBox application stack
1. 시스템 패키지 설치
sudo apt update
sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential \
libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev git
Python 설치 확인
python3 -V
2. SSL 인증서 생성
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/netbox.key \
-out /etc/ssl/certs/netbox.crt
Country Name (2 letter code) [AU]:KR
State or Province Name (full name) [Some-State]:Seoul
Locality Name (eg, city) []:Jongno-gu
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Byeon-gun's Igloo Blog
Organizational Unit Name (eg, section) []:Infrastructure Team
Common Name (e.g. server FQDN or YOUR name) []:netbox.scbyun.com
Email Address []:admin@scbyun.com
3. NGINX 설치
curl -s https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt install -y nginx
NGINX 버전 확인
$ nginx -v
nginx version: nginx/1.26.2
NGINX 구성
sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/conf.d/netbox.conf
sudo rm /etc/nginx/conf.d/default.conf
sudo systemctl restart nginx
4. PostgreSQL 설치 및 데이터베이스 설정
sudo apt install -y postgresql
$ psql -V
psql (PostgreSQL) 14.13 (Ubuntu 14.13-0ubuntu0.22.04.1)
sudo -u postgres psql
-- 1. 데이터베이스 생성
CREATE DATABASE db_netbox;
-- 2. 사용자 생성 및 암호 설정
CREATE USER id_netbox WITH ENCRYPTED PASSWORD 'pw_netbox';
-- 3. 사용자 설정: 클라이언트 인코딩, 트랜잭션 격리 수준 및 시간대
ALTER ROLE id_netbox SET client_encoding TO 'utf8';
ALTER ROLE id_netbox SET default_transaction_isolation TO 'read committed';
ALTER ROLE id_netbox SET timezone TO 'Asia/Seoul';
-- 4. 데이터베이스 권한 부여
GRANT ALL PRIVILEGES ON DATABASE db_netbox TO id_netbox;
\q
5. Redis 서버 설치
sudo apt install -y redis-server
$ redis-cli -v
redis-cli 6.0.16
6. NetBox 설치
GitHub 저장소에서 NetBox 다운로드
sudo mkdir -p /opt/netbox/
cd /opt/netbox/
sudo git clone -b master --depth 1 https://github.com/netbox-community/netbox.git .
NetBox 시스템 사용자 생성 및 권한
sudo adduser --system --group netbox
sudo chown --recursive netbox /opt/netbox/netbox/media/
sudo chown --recursive netbox /opt/netbox/netbox/reports/
sudo chown --recursive netbox /opt/netbox/netbox/scripts/
7. NetBox 설정 구성
cd /opt/netbox/netbox/netbox/
sudo cp configuration_example.py configuration.py
Django를 위한 SECRET_KEY 생성
sudo python3 /opt/netbox/netbox/generate_secret_key.py
)zep@c0#2-tv(4iAqWy5&jjFt(apXYt2yXMO91vaPqaRFc2XOE
configuration.py 편집
vim /opt/netbox/netbox/netbox/configuration.py
ALLOWED_HOSTS = ['netbox.scbyun.com']
DATABASE = {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_netbox',
'USER': 'id_netbox',
'PASSWORD': 'pw_netbox',
'HOST': 'localhost',
'PORT': '',
'CONN_MAX_AGE': 300,
}
REDIS = {
'tasks': {
'HOST': 'localhost',
'PORT': 6379,
'USERNAME': '',
'PASSWORD': '',
'DATABASE': 0,
'SSL': False,
},
'caching': {
'HOST': 'localhost',
'PORT': 6379,
'USERNAME': '',
'PASSWORD': '',
'DATABASE': 1,
'SSL': False,
}
}
SECRET_KEY = ')zep@c0#2-tv(4iAqWy5&jjFt(apXYt2yXMO91vaPqaRFc2XOE'
더보기
---
sudo sed -i "s/^SECRET_KEY.*/SECRET_KEY = '$SECRET_KEY'/" configuration.py
sudo sed -i "s/^ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['netbox.scbyun.com']/" configuration.py
sudo sed -i "s/'NAME': 'netbox'/'NAME': 'db_netbox'/" configuration.py
sudo sed -i "s/'USER': 'netbox'/'USER': 'id_netbox'/" configuration.py
sudo sed -i "s/'PASSWORD': ''/'PASSWORD': 'pw_netbox'/" configuration.py
sudo sed -i "s/'HOST': ''/'HOST': 'localhost'/" configuration.py
sudo sed -i "s/'HOST': 'redis'/'HOST': 'localhost'/" configuration.py
---
sudo sh -c "echo 'django-storages' >> /opt/netbox/local_requirements.txt"
8. NetBox 설치 스크립트
NetBox 업그레이드 스크립트를 실행합니다.
sudo /opt/netbox/upgrade.sh
...
Completed.
Removing expired user sessions (python3 netbox/manage.py clearsessions)...
--------------------------------------------------------------------
WARNING: No existing virtual environment was detected. A new one has
been created. Update your systemd service files to reflect the new
Python and gunicorn executables. (If this is a new installation,
this warning can be ignored.)
netbox.service ExecStart:
/opt/netbox/venv/bin/gunicorn
netbox-rq.service ExecStart:
/opt/netbox/venv/bin/python
After modifying these files, reload the systemctl daemon:
> systemctl daemon-reload
--------------------------------------------------------------------
Upgrade complete! Don't forget to restart the NetBox services:
> sudo systemctl restart netbox netbox-rq
NetBox에 대한 superuser 생성
source /opt/netbox/venv/bin/activate
cd /opt/netbox/netbox
python3 manage.py createsuperuser
Username: admin
Email address: admin@localhost
Password:
Password (again):
Superuser created successfully.
Daily Cron에 housekeeping 추가
sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping
9. NetBox 애플리케이션 테스트
source /opt/netbox/venv/bin/activate
cd /opt/netbox/netbox
python3 manage.py runserver 0.0.0.0:8000 --insecure
Performing system checks...
System check identified no issues (0 silenced).
November 01, 2024 - 13:31:09
Django version 5.0.9, using settings 'netbox.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
deactivate
http://192.168.10.111:8000/
10. NetBox에 대한 Gunicorn 구성
Configuration
sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
systemd Setup
sudo cp /opt/netbox/contrib/netbox.service /etc/systemd/system/
sudo cp /opt/netbox/contrib/netbox-rq.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now netbox netbox-rq
sudo systemctl restart netbox netbox-rq
systemctl status netbox.service
nginx netbox netbox-rq 서비스 재시작
sudo systemctl restart nginx netbox netbox-rq
참고URL
- netboxlabs documentation : installation
728x90
반응형
'리눅스' 카테고리의 다른 글
우분투에서 MongoDB Community Edition을 설치하는 방법 (0) | 2024.11.07 |
---|---|
우분투에서 MySQL 8을 APT로 설치하고 설정하는 방법 (1) | 2024.11.06 |
우분투에서 Promtail을 설치하고 설정하는 방법 (0) | 2024.11.01 |
우분투에서 apt 패키지 매니저를 사용하여 최신 버전의 Grafana와 Loki를 설치하는 방법 (0) | 2024.10.31 |
Zabbix에서 그래프에 한글이 깨지는 문제를 해결하는 방법 (2) | 2024.10.31 |