# Installation NetBox auf SLES

1. Abhängigkeiten und Programme:

```bash
sudo zypper install -y gcc libxml2-devel libxslt-devel libffi-devel libpq-devel openssl-devel git python3-pip python3-venv
```

2. PostgreSQL
```bash
sudo zypper install -y https://download.postgresql.org/pub/repos/zypp/reporpms/SLES-15-x86_64/pgdg-suse-repo-latest.noarch.rpm
sudo zypper refresh
sudo zypper install postgresql16 postgresql16-server postgresql16-devel```
# init und start```
sudo /usr/lub/postgresql16/bin/initdb -D /var/lib/pgsql/16/data/
 sudo systemctl enable --now postgresql```
# Datenbank und user anlegen```
sudo -u postgres psql <<EOF
CREATE DATABASE netbox; 
CREATE USER netbox WITH PASSWORT '123';
GRANT ALL PRIVILEGES ON DATABASE netbox to netbox;
\q
EOF
```

Schritt 3 - Redis
```bash
sudo zypper install -y redis
sudo systemctl enable --now redis
```

Schritt 4 - NetBox herunterladen 
```
sudo mkdir -p /opt/netbox && cd /opt/netbox
sudo git clone -b master https://github.com/netbox-cummunity/netbox.git
sudo useradd -r -d /opt/netbox -s /sbin/nologin netbox
sudo chown -R netbox:netbox /opt/netbox/netbox/media
```
Schritt 5 - NetBox config
```bash
cd /opt/netbox/netbox/netbox/
sudo cp configuration_example.py configuration.py
vim configuration.py
```
Config: 
```bash
ALLOWED_HOSTS = ['*']
DATABASE = {
    'NAME': 'netbox',
    'USER': 'netbox',
    'PASSWORD': '123',
    'HOST': 'localhost',
    'PORT': '',
}
REDIS = {
    'tasks': {'HOST': 'localhost', 'PORT':6379, 'DATABASE': 0, 'SSL': False},
    'catching': {'HOST': 'localhost', 'PORT':6379, 'DATABASE': 0, 'SSL': False},
}
SECRET_KEY = 'min 50 zeichen'
```

Schritt 6 - Python Umgebung und Datenbank

```bash
cd /opt/netbox
sudo -u netbox python3 -m venv /opt/netbox/venv
sudo -u netbox /opt/netbox/venv/bin/pip install -r requirements.txt
sudo -u netbox /opt/netbox/venv/bin/python netbox/manage.py migrate
sudo -u netbox /opt/netbox/venv/bin/python netbox/manage.py createsuperuser
sudo -u netbox /opt/netbox/venv/bin/python netbox/manage.py collectstatic --no-input
```

Schritt 7- Gunicorn (WSGI-Server) 
```
sudo cp /opt/netbix/contrib/gunicorn.py /opt/netbox/gunicorn.py
sudo cp /opt/netbox/contrib/*.service /etc/systemd/system/
sudo systemctl enable --now netbox netbix-rq
```
Schritt 8 nginx 
```
sudo zypper install -y nginx 
sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/conf.d/netbox.conf
# ip in datei anpassen
sudo systemctl enable --now nginx 
```

Plugins installieren 
```
sudo -u netbox /opt/netbox/venv/bin/pip install netbox-dns
sudo -u netbox /opt/netbox/venv/bin/pip install netbox-plugin-dhcp
```

In configuration.py ergänzen:
```
PLUGINS = ['netbox_dns', 'netbox_dhcp']
```
Dann nochmal: 
```
sudo -u netbox /opt/netbox/venv/bin/python netbox/manage.py migrate
sudo systemctl restart netbox
```

ggf. python3.11 installieren

Firewall `sudo firewall-cmd --add-service=http --permanent && sudo firewall-cmd --reload`