Tools: 로컬 LLM 셋업 가이드 (v36) - Analysis
로컬 LLM 셋업 가이드 (v36)
1. 개요 및 사전 준비
사전 요구사항:
2. 프레임워크 비교
3. 추천 설정: llama.cpp + Ollama
llama.cpp 설치:
Ollama 설치:
4. 모델 선택 가이드
5. 양자화 유형 설명
6. API 설정
llama.cpp API 서버 실행:
Ollama API 사용:
7. Systemd 서비스 설정
8. 모니터링 및 성능 조정
성능 측정:
메모리 사용량 모니터링:
9. 실제 사용 예제
1. 개발 환경에서의 빠른 테스트:
2. API 통합:
3. 고급 성능 설정:
10. 추천 최적화 팁
11. 문제 해결
일반적인 오류: 로컬 LLM(대형 언어 모델)은 데이터 프라이버시, 비용 절감, 실시간 처리가 필요한 개발자들에게 이상적인 선택입니다. 이 가이드는 최소한의 리소스로도 동작하는 로컬 LLM 셋업을 제공합니다. llama.cpp로 실행 가능한 최적화된 모델 + Ollama로 간단한 API 관리 이 가이드를 따라하면 20분 안에 로컬 LLM 환경을 구축하고, API를 통해 사용할 수 있습니다. 다양한 모델과 성능 조정 방법을 익혀두면 실제 프로젝트에 바로 적용할 수 있습니다. 📥 Get the full guide on Gumroad: https://gumroad.com/l/auto ($7) Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuseCommandCopy$ -weight: 500;">git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
-weight: 500;">git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
-weight: 500;">git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
-weight: 500;">curl -fsSL https://ollama.com/-weight: 500;">install.sh | sh
-weight: 500;">curl -fsSL https://ollama.com/-weight: 500;">install.sh | sh
-weight: 500;">curl -fsSL https://ollama.com/-weight: 500;">install.sh | sh
# 모델 다운로드
mkdir -p models
-weight: 500;">wget https://huggingface.co/TheBloke/Qwen-1.5B-Chat-GGUF/resolve/main/qwen-1.5b-chat.Q4_K_M.gguf -P models/ # 서버 실행
./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
# 모델 다운로드
mkdir -p models
-weight: 500;">wget https://huggingface.co/TheBloke/Qwen-1.5B-Chat-GGUF/resolve/main/qwen-1.5b-chat.Q4_K_M.gguf -P models/ # 서버 실행
./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
# 모델 다운로드
mkdir -p models
-weight: 500;">wget https://huggingface.co/TheBloke/Qwen-1.5B-Chat-GGUF/resolve/main/qwen-1.5b-chat.Q4_K_M.gguf -P models/ # 서버 실행
./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
# 모델 푸시
ollama push qwen:1.5b # API 호출
-weight: 500;">curl http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{ "model": "qwen:1.5b", "prompt": "Hello, how are you?", "stream": false }'
# 모델 푸시
ollama push qwen:1.5b # API 호출
-weight: 500;">curl http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{ "model": "qwen:1.5b", "prompt": "Hello, how are you?", "stream": false }'
# 모델 푸시
ollama push qwen:1.5b # API 호출
-weight: 500;">curl http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{ "model": "qwen:1.5b", "prompt": "Hello, how are you?", "stream": false }'
-weight: 600;">sudo nano /etc/systemd/system/llama.-weight: 500;">service
-weight: 600;">sudo nano /etc/systemd/system/llama.-weight: 500;">service
-weight: 600;">sudo nano /etc/systemd/system/llama.-weight: 500;">service
[Unit]
Description=Local LLM Server
After=network.target [Service]
Type=simple
User=your_user
WorkingDirectory=/home/your_user/llama.cpp
ExecStart=/home/your_user/llama.cpp/server -m /home/your_user/models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target
[Unit]
Description=Local LLM Server
After=network.target [Service]
Type=simple
User=your_user
WorkingDirectory=/home/your_user/llama.cpp
ExecStart=/home/your_user/llama.cpp/server -m /home/your_user/models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target
[Unit]
Description=Local LLM Server
After=network.target [Service]
Type=simple
User=your_user
WorkingDirectory=/home/your_user/llama.cpp
ExecStart=/home/your_user/llama.cpp/server -m /home/your_user/models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target
-weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start llama.-weight: 500;">service
# 추론 시간 측정
time -weight: 500;">curl -X POST http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Hello world", "n_predict":50}'
# 추론 시간 측정
time -weight: 500;">curl -X POST http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Hello world", "n_predict":50}'
# 추론 시간 측정
time -weight: 500;">curl -X POST http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Hello world", "n_predict":50}'
# 실시간 CPU/MEM 사용량
htop # 로그 확인
journalctl -u llama.-weight: 500;">service -f
# 실시간 CPU/MEM 사용량
htop # 로그 확인
journalctl -u llama.-weight: 500;">service -f
# 실시간 CPU/MEM 사용량
htop # 로그 확인
journalctl -u llama.-weight: 500;">service -f
# 100MB 모델로 간단한 테스트
ollama run qwen:1.5b
# 100MB 모델로 간단한 테스트
ollama run qwen:1.5b
# 100MB 모델로 간단한 테스트
ollama run qwen:1.5b
import requests def call_local_llm(prompt): response = requests.post('http://localhost:8080/completion', json={'prompt': prompt, 'n_predict': 100}) return response.json()['content'] # 사용 예제
result = call_local_llm("Python으로 간단한 웹 서버를 만들어줘")
print(result)
import requests def call_local_llm(prompt): response = requests.post('http://localhost:8080/completion', json={'prompt': prompt, 'n_predict': 100}) return response.json()['content'] # 사용 예제
result = call_local_llm("Python으로 간단한 웹 서버를 만들어줘")
print(result)
import requests def call_local_llm(prompt): response = requests.post('http://localhost:8080/completion', json={'prompt': prompt, 'n_predict': 100}) return response.json()['content'] # 사용 예제
result = call_local_llm("Python으로 간단한 웹 서버를 만들어줘")
print(result)
# CPU 코어 제한
taskset -c 0-3 ./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080 # 메모리 최적화
export CUDA_LAUNCH_BLOCKING=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
# CPU 코어 제한
taskset -c 0-3 ./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080 # 메모리 최적화
export CUDA_LAUNCH_BLOCKING=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
# CPU 코어 제한
taskset -c 0-3 ./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080 # 메모리 최적화
export CUDA_LAUNCH_BLOCKING=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
# 메모리 부족
error: failed to allocate memory # 해결: 메모리 제한 해제
ulimit -v unlimited # 포트 충돌
bind: Address already in use # 해결: 포트 변경
./server --port 8081
# 메모리 부족
error: failed to allocate memory # 해결: 메모리 제한 해제
ulimit -v unlimited # 포트 충돌
bind: Address already in use # 해결: 포트 변경
./server --port 8081
# 메모리 부족
error: failed to allocate memory # 해결: 메모리 제한 해제
ulimit -v unlimited # 포트 충돌
bind: Address already in use # 해결: 포트 변경
./server --port 8081 - OS: Ubuntu 20.04 이상
- GPU: NVIDIA GTX 1060 이상 (CUDA 11.8 필요)
- RAM: 최소 16GB (24GB 이상 권장)
- 저장공간: 최소 50GB (모델별로 2-10GB 필요) - 모델 선택: 정확도가 중요한 작업은 Q5_K_M 이상 사용
- GPU 메모리: 16GB RAM 기준 8GB 모델 추천
- API 설정: 8080 포트로 기본 설정 유지
- 로그 관리: Systemd 로그 자동 회전 설정
$ -weight: 500;">git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
-weight: 500;">git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
-weight: 500;">git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
-weight: 500;">curl -fsSL https://ollama.com/-weight: 500;">install.sh | sh
-weight: 500;">curl -fsSL https://ollama.com/-weight: 500;">install.sh | sh
-weight: 500;">curl -fsSL https://ollama.com/-weight: 500;">install.sh | sh
# 모델 다운로드
mkdir -p models
-weight: 500;">wget https://huggingface.co/TheBloke/Qwen-1.5B-Chat-GGUF/resolve/main/qwen-1.5b-chat.Q4_K_M.gguf -P models/ # 서버 실행
./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
# 모델 다운로드
mkdir -p models
-weight: 500;">wget https://huggingface.co/TheBloke/Qwen-1.5B-Chat-GGUF/resolve/main/qwen-1.5b-chat.Q4_K_M.gguf -P models/ # 서버 실행
./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
# 모델 다운로드
mkdir -p models
-weight: 500;">wget https://huggingface.co/TheBloke/Qwen-1.5B-Chat-GGUF/resolve/main/qwen-1.5b-chat.Q4_K_M.gguf -P models/ # 서버 실행
./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
# 모델 푸시
ollama push qwen:1.5b # API 호출
-weight: 500;">curl http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{ "model": "qwen:1.5b", "prompt": "Hello, how are you?", "stream": false }'
# 모델 푸시
ollama push qwen:1.5b # API 호출
-weight: 500;">curl http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{ "model": "qwen:1.5b", "prompt": "Hello, how are you?", "stream": false }'
# 모델 푸시
ollama push qwen:1.5b # API 호출
-weight: 500;">curl http://localhost:11434/api/generate \ -H "Content-Type: application/json" \ -d '{ "model": "qwen:1.5b", "prompt": "Hello, how are you?", "stream": false }'
-weight: 600;">sudo nano /etc/systemd/system/llama.-weight: 500;">service
-weight: 600;">sudo nano /etc/systemd/system/llama.-weight: 500;">service
-weight: 600;">sudo nano /etc/systemd/system/llama.-weight: 500;">service
[Unit]
Description=Local LLM Server
After=network.target [Service]
Type=simple
User=your_user
WorkingDirectory=/home/your_user/llama.cpp
ExecStart=/home/your_user/llama.cpp/server -m /home/your_user/models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target
[Unit]
Description=Local LLM Server
After=network.target [Service]
Type=simple
User=your_user
WorkingDirectory=/home/your_user/llama.cpp
ExecStart=/home/your_user/llama.cpp/server -m /home/your_user/models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target
[Unit]
Description=Local LLM Server
After=network.target [Service]
Type=simple
User=your_user
WorkingDirectory=/home/your_user/llama.cpp
ExecStart=/home/your_user/llama.cpp/server -m /home/your_user/models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target
-weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl daemon-reload
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable llama.-weight: 500;">service
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start llama.-weight: 500;">service
# 추론 시간 측정
time -weight: 500;">curl -X POST http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Hello world", "n_predict":50}'
# 추론 시간 측정
time -weight: 500;">curl -X POST http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Hello world", "n_predict":50}'
# 추론 시간 측정
time -weight: 500;">curl -X POST http://localhost:8080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Hello world", "n_predict":50}'
# 실시간 CPU/MEM 사용량
htop # 로그 확인
journalctl -u llama.-weight: 500;">service -f
# 실시간 CPU/MEM 사용량
htop # 로그 확인
journalctl -u llama.-weight: 500;">service -f
# 실시간 CPU/MEM 사용량
htop # 로그 확인
journalctl -u llama.-weight: 500;">service -f
# 100MB 모델로 간단한 테스트
ollama run qwen:1.5b
# 100MB 모델로 간단한 테스트
ollama run qwen:1.5b
# 100MB 모델로 간단한 테스트
ollama run qwen:1.5b
import requests def call_local_llm(prompt): response = requests.post('http://localhost:8080/completion', json={'prompt': prompt, 'n_predict': 100}) return response.json()['content'] # 사용 예제
result = call_local_llm("Python으로 간단한 웹 서버를 만들어줘")
print(result)
import requests def call_local_llm(prompt): response = requests.post('http://localhost:8080/completion', json={'prompt': prompt, 'n_predict': 100}) return response.json()['content'] # 사용 예제
result = call_local_llm("Python으로 간단한 웹 서버를 만들어줘")
print(result)
import requests def call_local_llm(prompt): response = requests.post('http://localhost:8080/completion', json={'prompt': prompt, 'n_predict': 100}) return response.json()['content'] # 사용 예제
result = call_local_llm("Python으로 간단한 웹 서버를 만들어줘")
print(result)
# CPU 코어 제한
taskset -c 0-3 ./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080 # 메모리 최적화
export CUDA_LAUNCH_BLOCKING=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
# CPU 코어 제한
taskset -c 0-3 ./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080 # 메모리 최적화
export CUDA_LAUNCH_BLOCKING=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
# CPU 코어 제한
taskset -c 0-3 ./server -m models/qwen-1.5b-chat.Q4_K_M.gguf -c 2048 --port 8080 # 메모리 최적화
export CUDA_LAUNCH_BLOCKING=1
export CUDA_DEVICE_MAX_CONNECTIONS=1
# 메모리 부족
error: failed to allocate memory # 해결: 메모리 제한 해제
ulimit -v unlimited # 포트 충돌
bind: Address already in use # 해결: 포트 변경
./server --port 8081
# 메모리 부족
error: failed to allocate memory # 해결: 메모리 제한 해제
ulimit -v unlimited # 포트 충돌
bind: Address already in use # 해결: 포트 변경
./server --port 8081
# 메모리 부족
error: failed to allocate memory # 해결: 메모리 제한 해제
ulimit -v unlimited # 포트 충돌
bind: Address already in use # 해결: 포트 변경
./server --port 8081 - OS: Ubuntu 20.04 이상
- GPU: NVIDIA GTX 1060 이상 (CUDA 11.8 필요)
- RAM: 최소 16GB (24GB 이상 권장)
- 저장공간: 최소 50GB (모델별로 2-10GB 필요) - 모델 선택: 정확도가 중요한 작업은 Q5_K_M 이상 사용
- GPU 메모리: 16GB RAM 기준 8GB 모델 추천
- API 설정: 8080 포트로 기본 설정 유지
- 로그 관리: Systemd 로그 자동 회전 설정