Ubuntu 24.04 에서 RTX5080 드라이버 설치하기

리눅스/OS 일반|2025. 4. 11. 12:42
반응형

Ubuntu 24.04 에서 여러 AMD, NVIDIA 제품을 설치해 보았지만, RTX5080 은 설치 방식이 조금 달라서 내용을 기록해 둡니다.

 

 

1. nouveau 드라이버 차단

 

nouveau 드라이버를 블랙리스트에 추가합니다.

# cat <<EOF | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modeset=0
EOF

 

initramfs 이미지를 업데이트하여 블랙리스트 설정을 반영합니다.

# update-initramfs -u

 

시스템을 재시작 합니다.

# reboot

 

 

2. NVIDIA Driver 설치

 

리포지토리를 추가합니다.
# add-apt-repository ppa:graphics-drivers/ppa

# apt update
 
설치 가능한 드라이버 버전을 확인합니다.
# ubuntu-drivers devices
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
== /sys/devices/pci0000:97/0000:97:01.0/0000:98:00.0 ==
modalias : pci:v000010DEd00002C02sv00001458sd00004196bc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-570-open - third-party non-free recommended
driver   : nvidia-driver-570 - third-party non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

여기에서 위와 같이 recommended(추천) 라고 되어진 버전을 설치하면 됩니다.

(nvidia-driver-570 버전이 추천인데, 아래 nvidia-smi 명령이 안된다면 nvidia-driver-570-open 을 설치하세요)

# apt -y install nvidia-driver-570-open

 

설치 후 시스템을 재부팅 하면 관련 명령 사용이 가능해 집니다.

# reboot

 

아래 명령으로 드라이버가 잘 설치된 것을 확인할 수 있습니다.

# nvidia-smi

 

 

3. CUDA 설치

 

설치 방법을 따라 설치를 하면 됩니다. (Install Type 을 runfile 로 선택하면 설치가 간단해 집니다)

# wget https://developer.download.nvidia.com/compute/cuda/12.8.1/local_installers/cuda_12.8.1_570.124.06_linux.run

# sh cuda_12.8.1_570.124.06_linux.run

 

처음 설치 화면이 뜨기까지 시간이 어느정도 소요됩니다.

설치 과정은 Continue 선택 > accept 입력 > (미리 설치했으므로) 'Driver' 제외 및 나머지 기본값으로 Install 입니다.

파일 사이즈가 크기 때문에 여기에서도 시간이 다소 소요됩니다.

 

CUDA 설치가 완료되면, ~/.bashrc 파일에 경로를 추가하여 CUDA 바이너리에 접근할 수 있도록 합니다.

# echo 'export PATH=/usr/local/cuda-12.8/bin:$PATH' >> ~/.bashrc

# echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

# source ~/.bashrc

 

설치된 CUDA 버전을 확인합니다.

# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Fri_Feb_21_20:23:50_PST_2025
Cuda compilation tools, release 12.8, V12.8.93
Build cuda_12.8.r12.8/compiler.35583870_0

 

반응형

댓글()

RockyLinux 9 에서 root 원격접속 허용하기

리눅스/OS 일반|2025. 3. 14. 09:29
반응형

일반계정이 아닌 root 로 바로 접근을 허용하려는 경우 아래와 같은 SSH 설정 옵션으로 셋팅 후 데몬을 재시작 해 줍니다.


# vi /etc/ssh/sshd_config

...
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
...

 

# systemctl restart sshd

 

반응형

댓글()

Ubuntu 24.04 APT 저장소 및 키 초기화 하기

리눅스/OS 일반|2025. 2. 19. 10:31
반응형

모든 추가 저장소 삭제
# rm -f /etc/apt/sources.list.d/*.list

모든 GPG 키 삭제
# rm -f /etc/apt/keyrings/*.gpg

기본 APT 저장소 복구 (Ubuntu 24.04 Noble 기준)
# tee /etc/apt/sources.list <<EOF
deb http://archive.ubuntu.com/ubuntu noble main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu noble-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu noble-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu noble-security main restricted universe multiverse
EOF

APT 캐시 및 설정 초기화
# apt clean
# apt autoclean
# apt -y autoremove --purge
r# m -rf /var/lib/apt/lists/*

저장소 업데이트 및 확인
# apt -y update && apt -y upgrade

 

반응형

댓글()

빈글

리눅스/OS 일반|2024. 11. 1. 18:48
반응형
반응형

댓글()

ffmpeg 명령어로 포맷 변환 예제 (mkv to mp4, mp4 to mp3)

리눅스/OS 일반|2024. 11. 1. 18:47
반응형

ffmpeg 명령으로 할 수 있는것은 다양하지만, 필자의 필요에 의해서 아래 내용만 기록해 둡니다. 

 

 

1. mkv to mp4

 

# ffmpeg -i example.mkv -c:v copy -c:a copy example.mp4

 

입력 파일 : example.mkv

출력 파일 : example.mp4

 

위 옵션 사용시 비디오 및 오디오 스트림이 원본 품질로 유지됩니다.

이 방식은 매우 빠르고 효율적이며, 데이터 손실이 없습니다.

 

 

2. mp4 to mp3

 

영상에서 오디오만 추출이 가능합니다.

 

# ffmpeg -i input.mp4 -q:a 0 -map a output.mp3

 

-i input.mp4 : 입력 MP4 파일

-q:a 0 : 오디오 품질을 최상으로 설정 (-q:a 0 대신에 -b:a 128k 와 같이 비트레이트 지정 가능)

-map a : 오디오 스트림만 추출

output.mp3 : 출력 MP3 파일 이름

 

특정 시간대의 오디오만 추출하려면 -ss (시작 시간) 와 -t (지속 시간) 를 추가합니다.

 

# ffmpeg -ss 00:01:00 -i input.mp4 -to 00:00:30 -q:a 0 -map a output.mp3

 

-ss 00:01:00 : 추출 시작 시간 (1분 0초)

-t 00:00:30 : 추출 지속 시간 (0분 30초)

-q:a 0 : 오디오 품질을 최상으로 설정 (-q:a 0 대신에 -b:a 128k 와 같이 비트레이트 지정 가능)

빠른 처리를 위해 -ss 옵션을 입력 파일 앞에 배치 하였습니다.

  이 경우, ffmpeg는 해당 시간대부터 직접 처리하므로 더욱 빠릅니다.

- mp4 말고 오디오파일 mp3 에서 부분 추출도 가능합니다.

 

반응형

댓글()

Ubuntu 24.04 GNOME 46 Orchis 테마 적용하기

리눅스/OS 일반|2024. 9. 26. 13:53
반응형

- 로컬PC 일반 계정에서 적용이 잘 되는것 확인하였습니다.

 

파일 배포 URL

https://www.pling.com/p/2176652/

plymouth-theme.zip
0.46MB
neofetch-config.zip
0.00MB
GTK-Themes.zip
2.56MB
cava-config.zip
0.00MB
conky-config.zip
0.41MB
cursors-theme.zip
4.57MB
fonts1.zip
14.32MB
fonts2.zip
12.89MB

(fonts1.zip 과 font2.zip 는 fonts.zip 을 나누어 올린것임)

gnome-extensions.zip
1.76MB
ubuntu-desktop-settings.zip
0.01MB
fishomp-config.zip
0.12MB
wallpapers.zip
0.37MB
icon-themes.zip
19.35MB

 

 

세팅 방법 동영상 강좌

https://www.youtube.com/watch?v=5nJdzjoiygc&t=3s

 

 

Documents 에 나오는 명령어 입니다.

컨테이너 XRDP 접근하여 ubuntu 계정으로 로그인하고 진행하였습니다.

 

OS 환경 업데이트

$ sudo apt update && sudo apt dist-upgrade -y

 

어플 및 의존성 패키지 설치

$ sudo apt install curl \

rsync \

git \

gdebi \

nautilus-admin \

nautilus-extension-gnome-terminal \

sassc \

gnome-tweaks \

gnome-shell-extension-manager -y

 

리소스 파일 다운로드 (12개 파일 - fonts.zip 은 한개로 침)

$ cd Downloads

$ sudo apt -y install wget

$ wget http://sysdocu.kr/orchis/filelist.txt

$ wget -i filelist.txt

$ cd ..

 

GNOME 확장 설치

$ unzip -o $HOME/Downloads/gnome-extensions.zip -d $HOME/.local/share/gnome-shell/

 

GTK 테마 설치

$ mkdir -p $HOME/.themes
$ unzip -o $HOME/Downloads/GTK-Themes.zip -d $HOME/.themes

$ mkdir -p $HOME/.config/gtk-4.0
$ ln -sf $HOME/.themes/Orchis-Dark/gtk-4.0/{assets,gtk.css,gtk-dark.css} $HOME/.config/gtk-4.0/

 

아이콘, 커서 테마 설치

$ mkdir -p $HOME/.local/share/icons
$ unzip -o $HOME/Downloads/icon-themes.zip -d $HOME/.local/share/icons

$ mkdir -p $HOME/.icons
$ unzip -o $HOME/Downloads/cursors-theme.zip -d $HOME/.icons

 

폰트, 바탕화면 설치

$ unzip -o $HOME/Downloads/fonts.zip -d $HOME/.local/share/

$ sudo unzip -o $HOME/Downloads/wallpapers.zip -d /usr/share/backgrounds/

 

Conky 위젯 설치 및 설정

$ sudo apt install conky-all jq curl playerctl -y
$ unzip -o $HOME/Downloads/conky-config.zip -d $HOME/.config

Cava, 터미널, 오디오, 가상화, NeoFetch 설치

$ sudo apt install cava -y

$ unzip -o $HOME/Downloads/cava-config.zip -d $HOME/.config

$ sudo apt install neofetch -y

$ unzip -o $HOME/Downloads/neofetch-config.zip -d $HOME/.config

 

Fish 쉘, Oh My Posh 설치

$ sudo apt install fish -y

$ chsh -s /usr/bin/fish
Password: (ubuntu 계정 패스워드 입력)

$ sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh

$ sudo chmod +x /usr/local/bin/oh-my-posh 
$ unzip -o $HOME/Downloads/fishomp-config.zip -d $HOME
$ chmod u+rw ~/.poshthemes/*.json

 

Flatpak, Appimage 지원 활성화

$ sudo apt install gnome-software gnome-software-plugin-flatpak flatpak libfuse2 -y

$ flatpak remote-add --if-not-exists flathub http://flathub.org/repo/flathub.flatpakrepo

(화면 팝업으로 패스워드 입력)

$ sudo flatpak install flathub io.bassi.Amberol -y    // 여기에서 원래는 sudo 가 없지만, LXC 에서는 권한이 없어 추가해보았음

 

(위가 잘 안되면 반복 하거나 메모리 증설해볼 것. 나는 어떻게 넘어감...)

 

$ sudo flatpak override --filesystem=$HOME/.themes
$ sudo flatpak override --filesystem=$HOME/.local/share/icons
$ sudo flatpak override --filesystem=xdg-config/gtk-4.0

 

GNOME 앱 설치

$ sudo apt install gnome-weather \

gnome-maps \

gnome-audio \

gnome-calendar \

gnome-clocks \

gnome-connections \

gnome-console \

gnome-contacts \

gnome-music \

vlc \

gnome-shell-pomodoro -y

 

Plymouth 테마 설치 및 변경

$ sudo apt install plymouth -y
$ sudo unzip -o $HOME/Downloads/plymouth-theme.zip -d /usr/share/plymouth/themes
$ sudo update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/hexagon_dots/hexagon_dots.plymouth 100

$ sudo update-alternatives --config default.plymouth

(여기에서  /usr/share/plymouth/themes/hexagon_dots/hexagon_dots.plymouth   100       manual mode 행으로 된것을 찾아 앞 번호를 입력하면 됨)
$ sudo update-initramfs -u    // LXC 에서 명령어가 없다면 명령어부터 설치 sudo apt install initramfs-tools

 

GNOME 쉘 세팅 적용

$ unzip -o $HOME/Downloads/ubuntu-desktop-settings.zip -d $HOME/Downloads/
$ dconf load / < $HOME/Downloads/ubuntu-desktop-settings.conf

 

데스크톱이라면  이때 배경이 바뀌는게 보임.

LXC 는 ubuntu 계정으로 다시 로그인해야 보일지도? 메뉴를 눌러 로그아웃을 못하는 경우 호스트에서 컨테이너를 stop, start 해보자. 잘 안되네... 배경은 적용된 것 같기도 하고.. 근데 날씨 API 를 등록해야 하니, 이런건 컨테이너에서 사용 못하겠다.

 

SNAP 앱과 서비스 삭제

$ cp -afv $HOME/snap $HOME/Downloads/
$ sudo snap remove --purge firefox
$ sudo snap remove --purge snap-store
$ sudo snap remove --purge gnome-42-2204
$ sudo snap remove --purge gtk-common-themes
$ sudo snap remove --purge snapd-desktop-integration
$ sudo snap remove --purge firmware-updater
$ sudo snap remove --purge core22
$ sudo snap remove --purge bare
$ sudo snap remove --purge snapd
$ sudo apt autoremove --remove snapd -y

$ sudo rm -rf /var/cache/snapd/

$ echo "Package: snapd
Pin: release a=*
Pin-Priority: -10" | sudo tee /etc/apt/preferences.d/nosnap.pref

$ sudo apt update

 

파이어폭스 웹브라우저 설치

$ sudo add-apt-repository -y ppa:mozillateam/ppa && sudo apt update

$ echo 'APT::Key::Assert-Pubkey-Algo "";' | sudo tee /etc/apt/apt.conf.d/99weakkey-warning

$ sudo apt update

$ sudo apt install -y -t 'o=LP-PPA-mozillateam' firefox

$ echo "Unattended-Upgrade::Allowed-Origins:: \"LP-PPA-mozillateam:$distro_codename\";" | sudo tee /etc/apt/apt.conf.d/51unattended-upgrades-firefox

$ echo 'Package: firefox*
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 501' | sudo tee /etc/apt/preferences.d/mozillateamppa

$ sudo apt update

 

파이어폭스 테마 설치

$ cd $HOME/Downloads

$ git clone https://github.com/vinceliuice/WhiteSur-firefox-theme.git

$ cd WhiteSur-firefox-theme/

$ sudo ./install.sh -m    // 데스크톱은 모르겠는데 LXC 에서는 sudo 를 붙여주어야 했음. 매뉴얼에서는 안붙임.

 

끝.

 

바탕화면 날씨정보 지역 ID 및 API 발급 (로그인 필요)

$ vi ~/.config/conky/Alfirk-MOD/scripts/weather-v2.0.sh

수정 후 스크립트 실행하면 적용됨

https://openweathermap.org

 

 

반응형

댓글()

Ubuntu 24.04 Desktop 에서 Samsung SL-J3560FW 프린터 잡기

리눅스/OS 일반|2024. 9. 25. 09:31
반응형

프린터 설정에서 프린터를 추가할때 Samsung SL-J3560FW 모델과 동일한 드라이버가 출력되지 않고, 삼성 홈페이지에서 조차 리눅스용 드라이버를 제공하지 않습니다.

이러한 환경에서 아래 드라이버를 선택하여 설치하였더니 잘 되는 것으로 확인 했습니다.

 

- 설정 > 프린터 > [프린터 추가] > 하단 검색창에 프린터 IP 입력

 

조금 기다리면 아래 세가지 항목이 선택항목으로 출력됩니다.

-  JetDirect

- LPD

- SL-J3560FW

 

여기에서 올바른 모델명을 선택하여 진행하면 인쇄시 글씨가 깨져 출력되므로,

JetDirect 를 선택, [추가] 하고 아래 모델명을 찾아 설치합니다.

- 제조사 : Hewlett-Packard

- 드라이버 : HP Business Inkjet 110, hpcups 3.23.12

 

반응형

댓글()

간단한 리눅스 백업 스크립트 적용하기

리눅스/OS 일반|2024. 9. 19. 08:58
반응형

백업본을 저장할 디렉토리를 생성합니다.

# mkdir /backup

 

백업 스크립트를 생성합니다.

필요에 따라 아래 내용을 수정하여 사용하면 됩니다.

# vi /root/backup.sh

#!/bin/bash

# 오래된 파일 및 디렉토리 삭제
find "/backup/" -type f -mtime +5 -exec rm -f {} \;
find "/backup/" -type d -mtime +5 -exec rm -rf {} \;

# 오늘자 백업 디렉토리 생성
today=$(date +%Y%m%d)
mkdir -p /backup/${today}

# 홈페이지 소스 및 DB 백업
cd /home/sysdocu/
tar cvzf /backup/${today}/public_html.tar.gz public_html
mysqldump -uroot -p12345678 --all-databases > /backup/${today}/all.sql

# 시스템 기본 설정 파일 백업
cd /backup/${today}
cp -arp /etc/iptables/rules.v4 .
cp -arp /etc/crontab .
cp -arp /root/backup.sh .

 

# chmod 700 /root/backup.sh

 

백업 스크립트를 매일 04시에 실행되도록 스케쥴러에 등록합니다.

# echo "0 4 * * * root sh /root/backup.sh" >> /etc/crontab

 

반응형

댓글()

Ubuntu 24.04 에 Prometheus + Grafana 설치하기 (GPU 포함)

리눅스/OS 일반|2024. 9. 5. 11:43
반응형

Prometheus 는 시스템 모니터링 도구로, 서버나 애플리케이션의 성능 데이터를 수집하고 경고를 설정해 문제 발생 시 알림을 주는 역할을 합니다.
Grafana 는 Prometheus 가 수집한 데이터를 시각화해 대시보드로 보여주는 도구로, 다양한 차트와 그래프로 데이터를 쉽게 분석할 수 있게 도와줍니다.
두 도구는 주로 함께 사용되어 실시간 모니터링과 시각화를 제공합니다.

Ubuntu 24.04 서버에 두개의 도구를 설치하고 사용하는 방법에 대해 설명합니다.

 

 

1. 프로메테우스 설치 및 설정

 

프로메테우스 사용자 계정을 생성합니다.

# useradd --no-create-home --shell /bin/false prometheus

 

구성 파일과 라이브러리를 저장할 디렉토리를 생성합니다.

# mkdir /etc/prometheus

# mkdir /var/lib/prometheus

# chown prometheus:prometheus /var/lib/prometheus

 

프로메테우스 바이너리 파일을 다운로드 합니다.

# wget https://github.com/prometheus/prometheus/releases/download/v2.54.1/prometheus-2.54.1.linux-amd64.tar.gz

# tar xvzf prometheus-2.54.1.linux-amd64.tar.gz

# cd prometheus-2.54.1.linux-amd64

# mv console* /etc/prometheus

# mv prometheus.yml /etc/prometheus

# chown -R prometheus:prometheus /etc/prometheus

# mv prometheus /usr/local/bin/

# chown prometheus:prometheus /usr/local/bin/prometheus

 

프로메테우스 시스템 파일을 생성합니다.

# vi /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

 

변경 사항을 적용합니다.

# systemctl daemon-reload

 

프로메테우스 부팅 가동 설정과 데몬을 실행합니다.

# systemctl enable --now prometheus

 

다음 주소와 같이 웹브라우저에서 접속이 되는지 확인합니다.

http://grafana.sysdocu.kr:9090

 

 

2. Node Exporter 설치

 

# wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz

# tar xvzf node_exporter-1.8.2.linux-amd64.tar.gz

# mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin/

 

Node Exporter 계정을 생성합니다.

# useradd -rs /bin/false node_exporter

 

Node Exporter 시스템 파일을 생성합니다.

# vi /etc/systemd/system/node_exporter.service

[Unit]
Description=Node Exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

 

변경 사항을 적용합니다.

# systemctl daemon-reload

 

Node Exporter 부팅 가동 설정과 데몬을 실행합니다.

# systemctl enable --now node_exporter

 

 

3. 프로메테우스 설정

 

프로메테우스에 Node Exporter 설정을 합니다.

# vi /etc/prometheus/prometheus.yml

...

scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      - targets: ["localhost:9100"]
    basic_auth:
      username: 'promadmin'
      password: '12345678'

 

데몬을 재시작하여 설정을 적용합니다.

# systemctl restart prometheus

 

 

4. Grafana 설치

 

다음 명령어로 Grafana GPG 키를 추가합니다.

# wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

 

그라파나 저장소를 추가하고 설치를 진행합니다.

# add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

# apt -y update

# apt -y install grafana

 

부팅 실행 설정과 동시에 가동해줍니다.

# systemctl enable --now grafana-server

 

이제 웹브라우저에서 그라파나 대시보드에 접속할 수 있습니다.

주소는 아래와 같고, 기본 관리자 계정은 admin / admin 입니다.

로그인시 비밀번호 변경을 권장하고 있으므로, 바로 변경하여 보안을 강화하세요.

http://grafana.sysdocu.kr:3000

 

 

5. 프로메테우스와 그라파나 연결

 

다음은 프로메테우스 데이터 소스를 가져와 대시보드로 출력하는 과정입니다.

그라파나 대시보드에 로그인하여 아래 메뉴를 따라 이동합니다.

- Home > Connections > Data sources

열린 페이지에서 계속 진행

[ Add data source ] 클릭 > [ Prometheus ] 클릭

- Prometheus server URL : http://grafana.sysdocu.kr:9090

- Authentication methods : Basic authentication (선택), User, Password 입력 (prometheus.yml 에서 입력한 promadmin / 12345678)

- TLS settings : Skip TLS certificate validation (체크)

 

페이지 맨 하단의 [Save & test] 버튼을 눌러 이상이 없어야 합니다.

 

아래 메뉴를 따라 이동하여 대시보드 모니터링 스타일을 설정합니다.

- Dashboard > 열린 페이지에서 우측 상단 [New] 를 누르면 Import 가 보입니다. 이를 클릭합니다.

가운데 Grafana.com 의 대시보드 ID 를 넣을 수 있습니다. '15172' 를 입력하고 로드 합니다.

맨 아래 메뉴 'Select a Prometheus data source' 에서 'Prometheus' 선택 후 [Import] 를 누릅니다.

 

마지막으로, 아래 메뉴를 따라 선택하면 선택한 스타일의 대시보드에 데이터 소스값이 출력됩니다.

- Dashboards > (리스트에서) Node Exporter for Prometheus Dashboard based on 11074 > 'Resource Details: [grafana.sysdocu.kr]' 을 눌러 아래로 펼칩니다.

 

* 대시보드 레이아웃 제공 : https://grafana.com/grafana/dashboards/

 

 

※ GPU 서버 메트릭 수집

[참고] https://medium.com/@smda1215/nvidia-gpu-metrics-performance-monitor-in-grafana-prometheus-3a4bc7198cf9

 

NVIDIA GPU 서버를 모니터링 할 경우 아래와 같이 셋팅 합니다.

 

1) NVIDIA 드라이버 및 CUDA 설치

 

현재 시스템에서 사용 가능한 NVIDIA 드라이버 버전을 확인합니다.

# apt -y update

# apt -y install ubuntu-drivers-common alsa-utils

# ubuntu-drivers devices
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
== /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0 ==
modalias : pci:v000010DEd00001E82sv000010DEsd000012B0bc03sc00i00
vendor   : NVIDIA Corporation
model    : TU104 [GeForce RTX 2080]
driver   : nvidia-driver-470 - distro non-free
driver   : nvidia-driver-550 - distro non-free recommended
driver   : nvidia-driver-535 - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-535-open - distro non-free
driver   : nvidia-driver-535-server - distro non-free
driver   : nvidia-driver-535-server-open - distro non-free
driver   : nvidia-driver-550-open - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

 

여기에서는 출력된 목록에서 추천 표시된 버전으로 설치해 보겠습니다.

# apt -y install nvidia-driver-550

 

설치가 되었으면 리부팅을 합니다.

# reboot

 

설치를 확인합니다.

(우측 상단 CUDA 버전 확인 필요)

# nvidia-smi

 

이어서 CUDA 를 설치합니다.

아래 URL 에서 미리 체크한 CUDA 버전을 선택하면 설치 방법이 안내 됩니다.

참고로, 마지막 선택 (Install Type) 에서 runfile 을 선택하면 설치가 간단해 집니다.

https://developer.nvidia.com/cuda-toolkit-archive

 

설치 방법을 따라 설치를 하면 됩니다. (Install Type 을 runfile 로 선택하면 설치가 간단해 집니다)

Ubuntu 24.04 버전은 최근에 출시되어 그런지 버전이 나와있지않아 22.04 버전으로 선택하여 설치하였습니다.

# wget https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_550.54.15_linux.run

# sh cuda_12.4.1_550.54.15_linux.run

 

처음 설치 화면이 뜨기까지 시간이 걸릴 수 있으며, 설치 과정은 Continue 선택 > accept 입력 > (미리 설치했으므로) 'Driver' 제외 및 나머지 기본값으로 Install 입니다.

파일 사이즈가 크기 때문에 여기에서도 시간이 다소 소요됩니다.

 

CUDA 설치가 완료되면, ~/.bashrc 파일에 경로를 추가하여 CUDA 바이너리에 접근할 수 있도록 합니다.

# echo 'export PATH=/usr/local/cuda-12.4/bin:$PATH' >> ~/.bashrc

# echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

# source ~/.bashrc

 

설치된 CUDA 버전을 확인합니다.

# nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

 

2) NVIDIA GPU Exporter 설치

 

# wget https://github.com/utkuozdemir/nvidia_gpu_exporter/releases/download/v1.2.1/nvidia-gpu-exporter_1.2.1_linux_amd64.deb

# dpkg -i nvidia-gpu-exporter_1.2.1_linux_amd64.deb

 

OS 가 다른 경우, 또는 다른 버전의 패키지를 설치할 경우 배포 사이트를 방문해 보세요.

https://github.com/utkuozdemir/nvidia_gpu_exporter/releases

 

설치된 명령어가 확인됩니다.

# ll /usr/bin/nvidia_gpu_exporter 
-rwxr-xr-x 1 root root 10367128 Jun 28 21:45 /usr/bin/nvidia_gpu_exporter*

 

서비스 파일을 아래와 같이 생성합니다.

NVIDIA GPU Exporter 서비스의 기본 포트는 9835 입니다.

# vi /etc/systemd/system/nvidia_gpu_exporter.service

[Unit]
Description=Nvidia GPU Exporter
After=network-online.target

[Service]
Type=simple

User=nvidia_gpu_exporter
Group=nvidia_gpu_exporter

ExecStart=/usr/bin/nvidia_gpu_exporter

SyslogIdentifier=nvidia_gpu_exporter

Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target

 

변경 사항을 적용, 부팅 가동 설정 및 데몬 시작을 합니다.

# systemctl daemon-reload

# systemctl enable --now nvidia_gpu_exporter.service

 

웹브라우저를 통해 서비스가 잘 동작하는지 확인합니다.

http://grafana.sysdocu.kr:9835/metrics

 

3) 프로메테우스 설정

 

Nvidia GPU 매트릭을 출력할 준비가 되었습니다.

그라파나 대시보드에서 메트릭을 수집할 수 있도록 프로메테우스 설정을 변경 합니다.

# vi /etc/prometheus/prometheus.yml

...

scrape_configs:
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9835']
    basic_auth:
      username: 'promadmin'
      password: '12345678'

 

변경된 설정을 적용하기 위해 데몬을 재시작 합니다.

# systemctl restart prometheus

 

4) 그라파나 대시보드 설정

 

그라파나에서 소스데이터와 대시보드를 추가합니다.

그라파나 대시보드에 로그인하여 아래 메뉴를 따라 이동합니다.

- Home > Connections > Data sources

열린 페이지에서 계속 진행

[ Add data source ] 클릭 > [ Prometheus ] 클릭

- Prometheus server URL : http://grafana.sysdocu.kr:9090

- Authentication methods : Basic authentication (선택), User, Password 입력 (prometheus.yml 에서 입력한 promadmin / 12345678)

- TLS settings : Skip TLS certificate validation (체크)

 

페이지 맨 하단의 [Save & test] 버튼을 눌러 이상이 없어야 합니다.

 

아래 메뉴를 따라 이동하여 대시보드 모니터링 스타일을 설정합니다.

- Dashboard > 열린 페이지에서 우측 상단 [New] 를 누르면 Import 가 보입니다. 이를 클릭합니다.

가운데 Grafana.com 의 대시보드 ID 를 넣을 수 있습니다. '14574' 를 입력하고 로드 합니다.

맨 아래 메뉴 'Select a Prometheus data source' 에서 'Prometheus' 선택 후 [Import] 를 누릅니다.

 

마지막으로, 아래 메뉴를 따라 선택하면 선택한 스타일의 대시보드에 데이터 소스값이 출력됩니다.

- Dashboards > (리스트에서) Nvidia GPU Metrics 를 누르면 대시보드가 출력됩니다.

 

* NVIDIA 를 기준으로 하였지만, Tesla 도 되는듯 합니다.

 

반응형

댓글()

RockyLinux 9 에 Prometheus + Grafana 설치하기 (GPU 포함)

리눅스/OS 일반|2024. 9. 3. 16:08
반응형

Prometheus 는 시스템 모니터링 도구로, 서버나 애플리케이션의 성능 데이터를 수집하고 경고를 설정해 문제 발생 시 알림을 주는 역할을 합니다.
Grafana 는 Prometheus 가 수집한 데이터를 시각화해 대시보드로 보여주는 도구로, 다양한 차트와 그래프로 데이터를 쉽게 분석할 수 있게 도와줍니다.
두 도구는 주로 함께 사용되어 실시간 모니터링과 시각화를 제공합니다.

RockyLinux 9 서버에 두개의 도구를 설치하고 사용하는 방법에 대해 설명합니다.

 

 

1. Grafana 설치

 

그라파나 리포지토리를 설정하기 전에 아래 명령을 실행하여 기본 암호화 정책 백엔드를 'SHA1' 로 설정하고 서버를 재부팅하여 변경 사항을 적용합니다.

# update-crypto-policies --set DEFAULT:SHA1

# reboot

 

부팅이 완료되면 리포지토리를 추가합니다.

# vi /etc/yum.repos.d/grafana.repo

[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

 

그라파나를 설치합니다.

# dnf -y install grafana

 

설치가 완료되면 변경된 systemd 상태를 다시 불러옵니다.

# systemctl daemon-reload

 

부팅 실행 설정과 동시에 가동해줍니다.

# dnf -y install chkconfig

# systemctl enable --now grafana-server

 

 

2. Grafana 설정

 

# cp -arp /etc/grafana/grafana.ini /etc/grafana/grafana.ini.ori

# vi /etc/grafana/grafana.ini

[server]

# 바인딩 할 IP 주소
http_addr = 127.0.0.1

# 사용할 http 포트
http_port = 3000

# 브라우저에서 grafana 에 접근할 도메인 이름
domain = grafana.sysdocu.kr

 

그라파나 데몬을 재시작하여 적용합니다.

# systemctl restart grafana-server

 

 

3. Nginx 설치

 

Nginx 웹 서버를 설치하고 Grafana 서버의 역 프록시로 구성합니다.

# dnf -y install nginx

 

그라파나 도메인 설정을 추가합니다.

설정 내용중에 SSL 인증서와 키는 미리 생성해놓은 Let's Encrypt SSL 을 이용하였으며, 인증서 발급 과정은 생략하였으니 다음 URL 을 확인하여 진행하시기 바랍니다.

- Let's Encrypt SSL 인증서 생성 :  https://sysdocu.tistory.com/1710

 

# vi /etc/nginx/conf.d/grafana.conf

# Grafana Live WebSocket 연결을 프록시하는 데 필요
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
    listen      80;
    server_name grafana.sysdocu.kr;
    rewrite     ^   https://$server_name$request_uri? permanent;
}

server {
  listen      443 ssl http2;
  server_name grafana.sysdocu.kr;

  root /usr/share/nginx/html;
  index index.html index.htm;

  ssl_certificate /etc/nginx/ssl/grafana.sysdocu.kr/fullchain1.pem;
  ssl_certificate_key /etc/nginx/ssl/grafana.sysdocu.kr/privkey1.pem;

  access_log /var/log/nginx/grafana-access.log;
  error_log /var/log/nginx/grafana-error.log;

  location / {
    proxy_set_header Host $http_host;
    proxy_pass http://localhost:3000/;
  }

  # Grafana Live WebSocket 연결 프록시
  location /api/live {
    rewrite  ^/(.*)  /$1 break;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $http_host;
    proxy_pass http://localhost:3000/;
  }
}

 

설정에 이상이 없는지 확인합니다.

# nginx -t

 

이상이 없으면 부팅 실행 설정과 동시에 가동해줍니다.

# systemctl enable --now nginx

 

* 참고

방화벽이나 SELinux 활성화시 nginx 구동이 되지 않으므로, 아래와 같이 처리 후 진행하면 됩니다.

# systemctl stop firewalld

# setenforce 0

 

이제 웹브라우저에서 그라파나 대시보드에 접속할 수 있습니다.

주소는 아래와 같고, 기본 관리자 계정은 admin / admin 입니다.

로그인시 비밀번호 변경을 권장하고 있으므로, 바로 변경하여 보안을 강화하세요.

https://grafana.sysdocu.kr

 

 

4. Prometheus & Node Exporter 설치

 

Prometheus 는 시계열 데이터를 수집하고 저장하는 시스템으로, 주요 기능은 모니터링과 알림 기능을 제공하는 것입니다.

Node Exporter는 Prometheus와 함께 사용되는 도구로 CPU 사용률, 메모리 사용량, 디스크 I/O, 네트워크 통계 등과 같은 메트릭 정보를 수집합니다.

 

설치를 위해 아래 내용으로 리포지토리를 추가합니다.

# vi /etc/yum.repos.d/prometheus.repo

[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
       https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300

 

Prometheus 와 Node Exporter 를 설치합니다.

# dnf -y install prometheus2 node_exporter

 

부팅 가동 설정과 동시에 데몬을 가동합니다.

# systemctl enable --now prometheus

# systemctl enable --now node_exporter

 

프로메테우스는 기본적으로 비밀번호 인증 없이 제공되어 보안상 취약합니다.

그러므로 다음과 같이 basic_auth 를 설정하여 보안을 강화 합니다.

HTTPS 까지 설정하고 싶은 경우 본 매뉴얼 최상단 [출처] 를 확인하세요.

# dnf -y install httpd-tools

# htpasswd -nB promadmin

New password: (신규 패스워드 입력)
Re-type new password: (신규 패스워드 재입력)
promadmin:$2y$05$jq0lO73ur6QiAHyT8SWODuUSS6MgWDqApaXNcRqrL45HsQWra7hoy

 

위에 출력된 값을 활용하여 새로운 프로메테우스 구성 파일을 만듭니다.

# vi /etc/prometheus/web.yml

basic_auth_users:
  promadmin: $2y$05$jq0lO73ur6QiAHyT8SWODuUSS6MgWDqApaXNcRqrL45HsQWra7hoy

 

그다음 아래 파일을 열고 맨 뒤에 --web.config.file=/etc/prometheus/web.yml 옵션을 추가해 줍니다.

# vi /etc/default/prometheus

PROMETHEUS_OPTS='--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --web.config.file=/etc/prometheus/web.yml'

 

프로메테우스 설정 파일을 열고 scrape_configs 섹션만 아래와 같이 수정합니다.

설정에 SSL 사용이 가능한데, 사용방법은 본 매뉴얼 최상단 [출처] 에서 확인해 주세요.

# cp -arp /etc/prometheus/prometheus.yml /etc/prometheus/prometheus.yml.ori

# vi /etc/prometheus/prometheus.yml

...

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
    basic_auth:
      username: 'promadmin'
      password: '12345678'
  - job_name: "node_exporter"
    static_configs:
      - targets: ["localhost:9100"]

 

변경된 설정을 적용하기 위해 데몬을 재시작 합니다.

# systemctl restart prometheus
# systemctl restart node_exporter

 

웹브라우저에서 다음 주소를 이용해 시각화 된 메트릭 정보를 확인 할 수 있습니다.

계정은 위에서 htpasswd 명령으로 생성한 것을 이용합니다.

http://grafana.sysdocu.kr:9090

 

 

5. 프로메테우스와 그라파나 연결

 

이제 최종적으로 하려는 작업은, 프로메테우스에서 수집된 메트릭 데이터 (데이터 소스) 를 그라파나로 출력하는 것입니다.

그라파나 대시보드에 로그인하여 아래 메뉴를 따라 이동합니다.

- Home > Connections > Data sources

열린 페이지에서 계속 진행

[ Add data source ] 클릭 > [ Prometheus ] 클릭

- Prometheus server URL : http://grafana.sysdocu.kr:9090

- Authentication methods : Basic authentication (선택), User, Password 입력 (prometheus.yml 에서 입력한 promadmin / 12345678)

- TLS settings : Skip TLS certificate validation (체크)

 

페이지 맨 하단의 [Save & test] 버튼을 눌러 이상이 없어야 합니다.

 

아래 메뉴를 따라 이동하여 대시보드 모니터링 스타일을 설정합니다.

- Dashboard > 열린 페이지에서 우측 상단 [New] 를 누르면 Import 가 보입니다. 이를 클릭합니다.

가운데 Grafana.com 의 대시보드 ID 를 넣을 수 있습니다. '15172' 를 입력하고 로드 합니다.

맨 아래 메뉴 'Select a Prometheus data source' 에서 'Prometheus' 선택 후 [Import] 를 누릅니다.

 

마지막으로, 아래 메뉴를 따라 선택하면 선택한 스타일의 대시보드에 데이터 소스값이 출력됩니다.

- Dashboards > (리스트에서) Node Exporter for Prometheus Dashboard based on 11074 > 'Resource Details: [grafana.sysdocu.kr]' 을 눌러 아래로 펼칩니다.

 

* 대시보드 레이아웃 제공 : https://grafana.com/grafana/dashboards/

 

 

※ GPU 서버 메트릭 수집

[참고] https://medium.com/@smda1215/nvidia-gpu-metrics-performance-monitor-in-grafana-prometheus-3a4bc7198cf9

 

NVIDIA GPU 서버를 모니터링 할 경우 아래와 같이 셋팅 합니다.

 

1) NVIDIA 드라이버 및 CUDA 설치

 

# dnf install -y epel-release
# dnf install -y gcc kernel-devel kernel-headers dkms make
# dnf config-manager --add-repo=http://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64/cuda-rhel9.repo
# dnf install -y nvidia-driver nvidia-settings nvidia-driver-libs
# dnf install -y cuda

 

설치를 확인합니다.

# nvidia-smi

 

2) NVIDIA GPU Exporter 설치

 

# rpm -ivh https://github.com/utkuozdemir/nvidia_gpu_exporter/releases/download/v1.2.1/nvidia-gpu-exporter_1.2.1_linux_amd64.rpm

 

OS 가 다른 경우, 또는 다른 버전의 패키지를 설치할 경우 배포 사이트를 방문해 보세요.

https://github.com/utkuozdemir/nvidia_gpu_exporter/releases

 

설치된 명령어가 확인됩니다.

# ll /usr/bin/nvidia_gpu_exporter 
-rwxr-xr-x. 1 root root 10367128  6월 28 17:45 /usr/bin/nvidia_gpu_exporter

 

사용자와 그룹을 다음과 같이 생성합니다.

패키지 설치시 자동으로 생성되는 경우가 있습니다.

# useradd -m -s /bin/false nvidia_gpu_exporter

 

서비스 파일을 아래와 같이 생성합니다.

NVIDIA GPU Exporter 서비스의 기본 포트는 9835 입니다.

# vi /etc/systemd/system/nvidia_gpu_exporter.service

[Unit]
Description=Nvidia GPU Exporter
After=network-online.target

[Service]
Type=simple

User=nvidia_gpu_exporter
Group=nvidia_gpu_exporter

ExecStart=/usr/bin/nvidia_gpu_exporter

SyslogIdentifier=nvidia_gpu_exporter

Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target

 

서비스를 시작하고 상태를 확인합니다.
# systemctl start nvidia_gpu_exporter.service
# systemctl enable nvidia_gpu_exporter.service
# systemctl status nvidia_gpu_exporter.service

 

웹브라우저를 통해 서비스가 잘 동작하는지 확인합니다.

http://grafana.sysdocu.kr:9835/metrics

 

3) 프로메테우스 설정

 

Nvidia GPU 매트릭을 출력할 준비가 되었습니다.

그라파나 대시보드에서 메트릭을 수집할 수 있도록 프로메테우스 설정을 변경 합니다.

# vi /etc/prometheus/prometheus.yml

...

scrape_configs:
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9835']
    basic_auth:
      username: 'promadmin'
      password: '12345678'

 

변경된 설정을 적용하기 위해 데몬을 재시작 합니다.

# systemctl restart prometheus

 

4) 그라파나 대시보드 설정

 

그라파나에서 소스데이터와 대시보드를 추가합니다.

그라파나 대시보드에 로그인하여 아래 메뉴를 따라 이동합니다.

- Home > Connections > Data sources

열린 페이지에서 계속 진행

[ Add data source ] 클릭 > [ Prometheus ] 클릭

- Prometheus server URL : http://grafana.sysdocu.kr:9090

- Authentication methods : Basic authentication (선택), User, Password 입력 (prometheus.yml 에서 입력한 promadmin / 12345678)

- TLS settings : Skip TLS certificate validation (체크)

 

페이지 맨 하단의 [Save & test] 버튼을 눌러 이상이 없어야 합니다.

 

아래 메뉴를 따라 이동하여 대시보드 모니터링 스타일을 설정합니다.

- Dashboard > 열린 페이지에서 우측 상단 [New] 를 누르면 Import 가 보입니다. 이를 클릭합니다.

가운데 Grafana.com 의 대시보드 ID 를 넣을 수 있습니다. '14574' 를 입력하고 로드 합니다.

맨 아래 메뉴 'Select a Prometheus data source' 에서 'Prometheus' 선택 후 [Import] 를 누릅니다.

 

마지막으로, 아래 메뉴를 따라 선택하면 선택한 스타일의 대시보드에 데이터 소스값이 출력됩니다.

- Dashboards > (리스트에서) Nvidia GPU Metrics 를 누르면 대시보드가 출력됩니다.

 

* NVIDIA 를 기준으로 하였지만, Tesla 도 되는듯 합니다.

 

반응형

댓글()

Proxmox VM 에서 NVIDIA GPU 장치 사용하기 (CUDA, cuDNN, TensorFlow 설치 포함)

리눅스/OS 일반|2024. 7. 16. 16:10
반응형

여기에서는 Proxmox VE 8.2.4 환경에서 테스트 하였으며, VM OS 는 Ubuntu 24.04 입니다.

 


1. Proxmox VE 호스트 서버에서 설정

 

grub 파일을 수정하고 업데이트 합니다.

아래에서 AMD CPU 는 amd_iommu=on 으로, INTEL CPU 는 intel_iommu=on 으로 입력하고 나머지는 동일하게 설정해 줍니다.

# vi /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on amd_iommu=pt pcie_acs_override=downstream,multifunction nofb video=efifb:off vga=off"

 

수정한 내용을 적용합니다.

# update-grub

 

VFIO (Virtual Function I/O) 관련 커널 모듈을 /etc/modules 파일에 추가하여 시스템이 부팅될 때마다 해당 모듈

이 자동으로 로드되도록 설정합니다.

# echo "vfio" >> /etc/modules

# echo "vfio_iommu_type1" >> /etc/modules

# echo "vfio_pci" >> /etc/modules

# echo "vfio_virqfd" >> /etc/modules

 

Proxmox VE 호스트 서버에서 GPU 를 인식하지 않도록 blacklist 에 등록합니다.

echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf

echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf

echo "blacklist radeon" >> /etc/modprobe.d/blacklist.conf

 

VFIO 정보를 등록해 줍니다.

먼저 NVIDIA 관련 장치 정보를 출력합니다.

# lspci -nn | grep -i nvidia
65:00.0 VGA compatible controller [0300]: NVIDIA Corporation TU104 [GeForce RTX 2080] [10de:1e82] (rev a1)
65:00.1 Audio device [0403]: NVIDIA Corporation TU104 HD Audio Controller [10de:10f8] (rev a1)
65:00.2 USB controller [0c03]: NVIDIA Corporation TU104 USB 3.1 Host Controller [10de:1ad8] (rev a1)
65:00.3 Serial bus controller [0c80]: NVIDIA Corporation TU104 USB Type-C UCSI Controller [10de:1ad9] (rev a1)

 

위 출력 결과를 이용해 설정 파일을 만듭니다.

여기에서는 VM 이 사용할 예정이므로 USB 는 제외하고 GPU 와 Audio Controller 만 추가하겠습니다.

# echo "options vfio-pci ids=10de:1e82,10de:10f8 disable_vga=1" > /etc/modprobe.d/vfio.conf

 

initramfs 를 업데이트하고 재부팅 합니다.

# update-initramfs -u

update-initramfs: Generating /boot/initrd.img-6.8.4-2-pve

Running hook script 'zz-proxmox-boot'..

Re-executing '/etc/kernel/postinst.d/zz-proxmox-boot' in new private mount namespace..

No /etc/kernel/proxmox-boot-uuids found, skipping ESP sync.

 

# reboot

 


2. VM 에서 설정

 

1) PCI 드라이버 추가

Proxmox VE 웹 UI 에서 VM 설정을 진행합니다.

- 메뉴 : 하드웨어 > 추가 > 'PCI 디바이스' 를 선택합니다.

0000:65:00.0 / 1 / NVIDIA Corporation / TU104 [GeForce TRX 2080] 

이런 형태의 장치입니다. 선택하고 추가한 후에 VM 을 시작합니다.

 

부팅이 되었으면 로그인하여 장치가 보이는 것을 확인합니다.

# lspci |grep -i nvidia
00:10.0 VGA compatible controller: NVIDIA Corporation TU104 [GeForce RTX 2080] (rev a1)

 

2) NVIDIA 드라이버 설치

현재 시스템에서 사용 가능한 NVIDIA 드라이버 버전을 확인합니다.

# apt -y update

# apt -y install ubuntu-drivers-common alsa-utils

# ubuntu-drivers devices

udevadm hwdb is deprecated. Use systemd-hwdb instead.

udevadm hwdb is deprecated. Use systemd-hwdb instead.

udevadm hwdb is deprecated. Use systemd-hwdb instead.

udevadm hwdb is deprecated. Use systemd-hwdb instead.

udevadm hwdb is deprecated. Use systemd-hwdb instead.

udevadm hwdb is deprecated. Use systemd-hwdb instead.

== /sys/devices/pci0000:00/0000:00:10.0 ==

modalias : pci:v000010DEd00001E82sv000010DEsd000012B0bc03sc00i00

vendor   : NVIDIA Corporation

model    : TU104 [GeForce RTX 2080]

driver   : nvidia-driver-535-open - distro non-free

driver   : nvidia-driver-470-server - distro non-free

driver   : nvidia-driver-535 - distro non-free recommended

driver   : nvidia-driver-535-server-open - distro non-free

driver   : nvidia-driver-470 - distro non-free

driver   : nvidia-driver-535-server - distro non-free

driver   : xserver-xorg-video-nouveau - distro free builtin

 

여기에서는 출력된 목록에서 추천 표시된 버전으로 설치해 보겠습니다.

# apt -y install nvidia-driver-535

설치가 되었으면 리부팅을 합니다.
# reboot

부팅 후 아래 명령으로 설치 여부와 NVIDIA 드라이버 버전에 맞는 CUDA 버전을 확인합니다.

(표시된 CUDA 버전은 설치되어 있는 버전이 아니고, 드라이버에 맞는 추천 버전이란 뜻입니다)

# nvidia-smi
Wed Jul 17 07:56:39 2024       
+---------------------------------------------------------------------------------------+
NVIDIA-SMI 535.183.01             Driver Version: 535.183.01   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 2080        Off | 00000000:00:10.0 Off |                  N/A |
| 28%   52C    P8              19W / 215W |      1MiB /  8192MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

 

NVIDIA 커널 모듈도 로드가 잘 되었는지 확인합니다.

# lsmod | grep nvidia
nvidia_uvm           1789952  0
nvidia_drm             90112  0
nvidia_modeset       1314816  1 nvidia_drm
video                  73728  1 nvidia_modeset
nvidia              56827904  2 nvidia_uvm,nvidia_modeset

 

이제 위에서 확인된 CUDA 12.2 를 설치할 차례 입니다.

 

3) CUDA Toolkit 설치

NVIDIA 의 CUDA Toolkit 을 설치합니다.

CUDA Toolkit 에는 TensorFlow 가 GPU 에서 실행되는 데 필요한 모든 라이브러리가 포함되어 있습니다.

아래는 검색을 통해 찾은 URL 인데, 12.2 버전과 드라이버 535 버전이 맞으므로 다운로드를 하였습니다.

# wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run

# chmod +x cuda_12.2.2_535.104.05_linux.run

# ./cuda_12.2.2_535.104.05_linux.run

 

처음 설치 화면이 뜨기까지 시간이 걸릴 수 있으며, 설치 과정은 Continue 선택 > accept 입력 > (미리 설치했으므로) 'Driver' 제외 및 나머지 기본값으로 Install 입니다.

파일 사이즈가 크기 때문에 여기에서도 시간이 다소 소요됩니다.

 

CUDA 설치가 완료되면, ~/.bashrc 파일에 경로를 추가하여 CUDA 바이너리에 접근할 수 있도록 합니다.

# echo 'export PATH=/usr/local/cuda-12.2/bin:$PATH' >> ~/.bashrc

# echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

# source ~/.bashrc

 

설치된 CUDA 버전을 확인합니다.

# nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Aug_15_22:02:13_PDT_2023
Cuda compilation tools, release 12.2, V12.2.140
Build cuda_12.2.r12.2/compiler.33191640_0

 

4) cuDNN 설치

cuDNN 은 NVIDIA 의 GPU 가속 라이브러리로, TensorFlow 와 같은 딥러닝 프레임워크의 성능을 높이는 데 사용됩니다.

- 로그인하여 버전별 다운로드 가능 : https://developer.nvidia.com/rdp/cudnn-archive

- 구버전은 로그인 없이 다운로드 가능 : https://developer.download.nvidia.com/compute/redist/cudnn/

작업 PC 에서 파일을 다운로드 받아 서버에 업로드 하고 설치를 이어갑니다.

# dpkg -i cudnn-local-repo-ubuntu2204-8.9.7.29_1.0-1_amd64.deb

 

설치가 되고 출력 내용에 키를 설치하라고 나옵니다. 명령을 따라 실행합니다.

# sudo cp /var/cudnn-local-repo-ubuntu2204-8.9.7.29/cudnn-local-08A7D361-keyring.gpg /usr/share/keyrings/

# apt -y update
# apt -y install libcudnn8=8.9.7.29-1+cuda12.2
# apt -y install libcudnn8-samples=8.9.7.29-1+cuda12.2

 

설치된 버전을 확인합니다.

# cat /usr/include/cudnn_version.h |grep CUDNN_MAJOR -A 2

#define CUDNN_MAJOR 8

#define CUDNN_MINOR 9

#define CUDNN_PATCHLEVEL 7

 

5) Anaconda 설치

Anaconda 는 데이터 과학 및 머신 러닝을 위한 종합적인 Python 배포판으로, TensorFlow 와 같은 패키지를 손쉽게 설치하고 관리할 수 있습니다.
# wget https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh
# chmod +x Anaconda3-2024.06-1-Linux-x86_64.sh 
# ./Anaconda3-2024.06-1-Linux-x86_64.sh 

설치 과정에서 ENTER 누르고 > accept 입력 > yes 입력 > yes 입력하면 설치됩니다.
추가된 명령을 사용하기 위해 환경설정을 다시 로드 합니다.
# source /root/.bashrc

버전을 확인합니다.
(base) root@test:~# python --version
Python 3.12.4

(base) root@test:~# conda --version
conda 24.5.0

sysdocu 라는 가상 환경을 생성합니다.

(base) root@test:~# conda create -n sysdocu

 

가상 환경 목록을 확인합니다.

(base) root@test:~# conda env list

 

생성된 가상 환경을 활성화 합니다.

(base) root@test:~# conda activate sysdocu

 

참고로 비활성화 하는 명령은 다음과 같습니다. (필요시 사용)

(sysdocu) root@test:~# conda deactivate

 

6) TensorFlow 설치

Anaconda 가상 환경에서 TensorFlow 설치를 이어갑니다.

(sysdocu) root@test:~# conda install tensorflow

 

현재 가상 환경에 설치된 패키지 목록을 확인합니다.

(sysdocu) root@test:~# conda list

 

 

3. 동작 테스트

 

코드를 실행할때 INFO 정보가 출력되는데, 결과와 같이 출력되어 보기에 좋지 않습니다.

우선, 기본적으로 오류가 아닐경우 출력하지 않도록 설정해 줍니다.

(0 = 모든 로그, 1 = 정보 로그, 2 = 경고 로그, 3 = 오류 로그)

(sysdocu) root@test:~#  export TF_CPP_MIN_LOG_LEVEL=3

 

1) 버전 출력 테스트

가상 환경 내에 TensorFlow 설치가 완료되면, 가상 환경 내에서 Python 을 실행하고, 아래 명령을 순차적으로 입력하면 버전이 출력되는데, 이와 같이 TensorFlow 가 정상적으로 설치 되었는지 확인 할 수 있습니다.

(sysdocu) root@test:~# python

>>> import tensorflow as tf

print(tf.__version__)

2.12.0

 

2) 행렬 곱셈 테스트

이번에는 파일을 만들어서 실행해 보겠습니다.
(sysdocu) root@test:~# vi test.py

import tensorflow as tf

# 두 개의 상수 행렬 정의
matrix1 = tf.constant([[3, 3]])
matrix2 = tf.constant([[2], [2]])

# 행렬 곱셈 수행
product = tf.matmul(matrix1, matrix2)

# 결과 출력
print("Matrix 1:")
print(matrix1.numpy())
print("Matrix 2:")
print(matrix2.numpy())
print("Product:")
print(product.numpy())

 

(sysdocu) root@test:~# python test.py

Matrix 1:
[[3 3]]
Matrix 2:
[[2]
 [2]]
Product:
[[12]]

 

3) XOR 게이트 학습 테스트

아래 예제 파일을 만들어서 실행해 봅니다.

이 예제는 TensorFlow 를 사용하여 신경망을 구축하고 학습시키는 과정을 포함하고 있습니다.
(sysdocu) root@test:~# vi test2.py

import tensorflow as tf
import numpy as np

# XOR 데이터셋 정의
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
y = np.array([[0], [1], [1], [0]], dtype=np.float32)

# 신경망 모델 정의
model = tf.keras.Sequential([
    tf.keras.layers.Dense(2, input_dim=2, activation='sigmoid'),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

# 모델 컴파일
model.compile(loss='mean_squared_error',
              optimizer=tf.keras.optimizers.SGD(learning_rate=0.1),
              metrics=['binary_accuracy'])

# 모델 학습
model.fit(X, y, epochs=1000, verbose=0)

# 결과 예측
predictions = model.predict(X)
print("Predictions:")
print(predictions)

 

(sysdocu) root@test:~# python test2.py
1/1 [==============================] - 0s 128ms/step
Predictions:
[[0.50881463]
 [0.48036876]
 [0.5206941 ]
 [0.49291846]]

 

이렇게 결과가 잘 출력 된 것으로 보아 TensorFlow 가 잘 설치되었음을 알 수 있습니다.

 

반응형

댓글()