Ollama

Eugenius1st·2026년 10월 6일

Ollama

목록 보기
1/2
post-thumbnail

OLLAMA 설치하기 (Docker 방식)

로컬 환경을 깔끔하게 유지하고 관리하기 위해 Docker를 이용한 설치를 권장합니다. 터미널(CMD/Terminal)에서 아래 명령어를 입력하세요.

📌 Docker 설치 명령어

# Ollama 컨테이너 실행 (데이터 보존을 위한 볼륨 설정 및 포트 매핑)
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
  • v ollama:/root/.ollama: 다운로드한 모델 파일을 컨테이너가 삭제되어도 유지합니다.
  • p 11434:11434: 외부(Spring Boot 등)에서 Ollama 서비스에 접속할 수 있도록 포트를 엽니다.

OLLAMA 서비스 시작 및 모델 실행

설치가 완료되었다면, 이번 학습의 핵심인 Qwen2.5 모델을 직접 내려받고 실행해 보겠습니다.

1️⃣ Ollama 모델 실행
Docker 컨테이너 내부에서 Ollama 명령어를 실행하여 모델을 구동합니다.

# qwen3:4b 모델 다운로드 및 대화형 인터페이스 실행
docker exec -it ollama ollama run qwen2.5:3b

2️⃣ 정상 동작 확인
명령어를 입력하면 모델 다운로드가 시작되며, 완료 후 >>> 프롬프트가 나타납니다.

  • "안녕? 너는 누구니?"라고 질문하여 한국어 응답이 정상적으로 오는지 확인하세요.
  • 종료하고 싶을 때는 /bye를 입력하거나 Ctrl + D를 누르면 됩니다. 서버 상태 확인 :
    # 콘솔 & 브라우저 실행
    curl http://localhost:11434
    
    # 출력:
    # Ollama is running
💡

4b는 파라미터 규모를 의미하며, 일반적인 노트북 환경에서 가장 빠르고 효율적으로 돌아가는 크기입니다. 이제 로컬 엔진이 준비되었으니, 다음 단계인 Spring AI 연동으로 넘어갈 준비가 되었습니다!

3. Qwen3 모델 시작하기

Qwen3는 Alibaba Cloud에서 선보이는 차세대 오픈소스 LLM으로, 이전 세대보다 더욱 정교해진 한국어 이해도와 추론 능력을 갖추고 있습니다. 특히 4b(40억 파라미터) 모델은 일반적인 개발용 노트북에서도 끊김 없이 돌아가는 '가성비 끝판왕' 모델입니다.

  • 제작사: Alibaba Cloud
  • 주요 특징:
    • 🇰🇷 한국어 특화: 다국어 데이터셋 중 한국어 비중이 높아 자연스러운 문체 구현.
    • ⚡ 최적화된 속도: 4b 모델은 CPU 환경에서도 초당 수십 단어를 생성할 정도로 가볍습니다.
    • 🆓 완전 무료: 상업적 프로젝트에 제약 없이 적용 가능한 라이선스.
    • 🛠️ 코딩 특화: Java, Python 등 주요 프로그래밍 언어의 코드 생성 능력이 대폭 향상되었습니다.

모델 크기 및 사양 가이드 (4b 중심)

Ollama에서 제공하는 Qwen2.5의 체급별 요구사항입니다. 현재 실습의 메인 모델인 4b를 확인해 보세요.

Qwen3 모델 실행 실습

1️⃣ 설치된 모델 목록 확인

먼저 내 컴퓨터에 qwen2.5:3b 모델이 잘 설치되었는지 확인합니다.

docker exec -it ollama ollama list

# 출력 예시
# NAME              ID              SIZE      MODIFIED
# qwen2.5:3b        f6a123bc456d    2.3 GB    1 minute ago
💡

docker exec -it ollama는 "ollama라는 이름의 컨테이너 안에서 다음 명령어를 실행하라"는 뜻입니다.

2️⃣ 대화형 모드(CLI) 실행 및 테스트

이제 직접 모델을 구동하여 성능을 확인해 봅시다.

docker exec -it ollama ollama run qwen2.5:3b

1. 테스트 시나리오: 한국어 및 개발 지식

사용자: "Spring AI와 Ollama를 연결하면 어떤 장점이 있어?"

Qwen3: "가장 큰 장점은 데이터 보안과 비용 절감입니다. 모든 데이터가 로컬에서 처리되어 외부 유출 걱정이 없으며, API 호출 비용 없이 무제한으로 테스트할 수 있습니다. 또한 Spring AI의 추상화된 인터페이스 덕분에 코드 수정 없이 모델을 쉽게 교체할 수 있습니다."

2. 테스트 시나리오: Java 코드 생성

사용자: "Java로 현재 날짜를 출력하는 간단한 Spring Boot 컨트롤러를 짜줘."

Qwen3: "네, 다음과 같이 RestController를 작성할 수 있습니다."

@RestController
public class DateController {
    @GetMapping("/today")
    public String getToday() {
        return "오늘의 날짜: " + LocalDate.now();
    }
}

유용한 관리 명령어

실습 중 모델을 교체하거나 정보를 확인할 때 사용하세요.

  • 멀티라인 입력: 여러 줄의 프롬프트를 보낼 때 """로 감쌉니다.
    >>> """
    다음 문장을 영어로 번역하고, 핵심 단어 3개를 뽑아줘:
    "로컬 AI 모델을 사용하면 데이터 보안을 강화할 수 있습니다."
    """
  • 모델 정보 보기: 모델의 아키텍처 정보를 출력합니다.
    /show info
  • 종료하기: 세션을 안전하게 닫습니다.
    /bye

    OLLAMA API 테스트 및 활용

Ollama는 기본적으로 11434 포트에서 HTTP 서버를 운영합니다. 이를 통해 우리는 브라우저나 터미널, 혹은 자바 코드로 AI에게 질문을 던질 수 있습니다.

1️⃣ 대화형 응답 테스트 (Chat API)

이전 대화 맥락을 포함하거나, AI에게 특정 역할을 부여(System Role)할 때 사용하는 방식입니다. Spring AI에서 주로 사용하는 방식이기도 합니다.

POST http://localhost:11434/api/chat 

-d '{
  "model": "qwen2.5:3b",
  "messages": [
    {
      "role": "system",
      "content": "당신은 친절하고 전문적인 자바 개발자입니다."
    },
    {
      "role": "user",
      "content": "로컬 LLM을 사용하는 이유가 뭐야?"
    }
  ],
  "stream": false
}'

2️⃣ API 응답 결과 분석

요청이 성공하면 다음과 같은 JSON 형식의 응답을 받게 됩니다.

{
    "model": "qwen2.5:3b",
    "created_at": "2026-03-25T15:48:15.51317551Z",
    "message": {
        "role": "assistant",
        "content": "안녕하세요! 로컬 LLM을 사용하는 주요 이유는 다음과 같습니다:\n\n1. **개인정보 보안**: 클라우드 서비스에 데이터를 전송하지 않아 민감한 정보 유출 위험을 최소화할 수 있습니다. 특히 의료, 금융 등 특정 산업에서 필수적입니다.\n2. **비용 절감**: 고주파 요청 시 클라우드 API 비용 대비 로컬 실행이 경제적입니다. 예를 들어, 내부 애플리케이션에서 실시간 처리를 할 때 네트워크 비용이 크게 절감됩니다.\n3. **실시간 성능**: 네트워크 지연 없이 즉시 응답이 가능해 실시간 챗봇이나 IoT 시스템에 적합합니다.\n4. **맞춤형 모델 튜닝**: 로컬에서 모델을 직접 훈련해 특정 용도(예: 한국어 처리)에 최적화할 수 있습니다.\n5. **법적 규제 준수**: 데이터 주거 요구사항을 충족하기 위해 로컬 환경에서 실행하는 경우가 많습니다.\n\n예를 들어, **Llama 3**, **Mistral** 등 소형 LLM 모델은 로컬 머신에 설치해 사용할 수 있습니다. Java 개발자로서는 Hugging Face Java SDK를 활용해 로컬 LLM을 효율적으로 통합할 수 있습니다.\n\n추가로 궁금한 점이 있으면 알려주세요! 😊",
        "thinking": "Okay, the user is asking why we use a local LLM. Let me think about this.\n\nFirst, I should recall what a local LLM is. Local LLM refers to running a large language model on the user's own machine instead of using a cloud-based service. So the main reasons would be privacy, cost, performance, maybe security.\n\nPrivacy is a big one. If you're using a cloud-based LLM, your data gets sent to the server, which might be a privacy concern. By using local, you keep the data on your machine.\n\nCost could be another point. Cloud services like OpenAI or Anthropic have costs per request. If you're using it locally, you don't have to pay for each query, but you need to set up the hardware. Maybe for some use cases, it's cheaper.\n\nPerformance: Local models might be faster since there's no network latency. Especially if you're doing real-time applications, local processing could be better.\n\nSecurity: Keeping the model on your own machine reduces the risk of data breaches or unauthorized access. Also, you control the model's access.\n\nAnother point is customization. Maybe you can fine-tune the local model to your specific needs without sharing data with the provider.\n\nWait, but some LLMs are too big to run locally. Like, GPT-3 is huge. But there are smaller models like Llama 2, Mistral, etc., that can be run locally with enough hardware.\n\nAlso, maybe the user is thinking about edge computing scenarios where you need to process data without internet.\n\nI should structure the answer clearly. Start with the main reasons: privacy, cost, performance, security, customization. Maybe mention specific examples of models that can be run locally.\n\nWait, the user is asking in Korean. The question is \"로컬 LLM을 사용하는 이유가 뭐야?\" which translates to \"Why do we use a local L:LM?\" So I need to answer in Korean.\n\nWait, the user wrote the question in Korean, but the instructions say to respond as a friendly and professional Java developer. Hmm, the user is asking in Korean, so I should respond in Korean.\n\nWait, the user's message is in Korean: \"로컬 LLM을 사용하는 이유가 뭐야?\" which means \"What's the reason for using a local LLM?\"\n\nBut the assistant's instructions say to be a friendly and professional Java developer. So the response should be in Korean, since the user is asking in Korean.\n\nWait, but maybe the user expects the answer in English? Let me check the initial instructions.\n\nThe user says: \"로컬 LLM을 사용하는 이유가 뭐야?\" which is Korean. The assistant's role is to be a friendly and professional Java developer. The user might be Korean, so the answer should be in Korean.\n\nBut the problem says: \"당신은 친절하고 전문적인 자바 개발자입니다.\" So the assistant should respond in the same language as the user. Since the user wrote in Korean, the answer should be in Korean.\n\nWait, but the user might have intended to ask in English but wrote in Korean. Hmm, but the question is in Korean. Let me confirm.\n\nThe user's message is in Korean: \"로컬 LLM을 사용하는 이유가 뭐야?\" So the answer should be in Korean.\n\nBut the initial problem says: \"You are a friendly and professional Java developer.\" So the answer should be in Korean.\n\nWait, but in the problem statement, the user wrote the question in Korean. So I need to respond in Korean.\n\nLet me think about the key points in Korean.\n\nFirst, list the reasons:\n\n1. 개인정보 보안: 로컬에서 실행하면 데이터가 클라우드에 전송되지 않아 개인정보 유출 위험 감소\n2. 비용 절감: 클라우드 서비스 사용 비용 대비 로컬 실행 시 비용 절감 가능 (특히 고주파 요청 시)\n3. 실시간 처리: 네트워크 지연 없이 즉시 응답 가능\n4. 정책 및 법적 규제: 특정 산업에서 데이터 주거 요구사항 충족\n5. 맞춤형 모델 튜닝: 로컬에서 모델을 직접 훈련해 특정 작업에 최적화 가능\n\nAlso, mention examples like Llama 3, Mistral, etc. that can be run locally.\n\nWait, but the user might not know about specific models. Maybe keep it general.\n\nAlso, as a Java developer, I can mention that Java has libraries like Hugging Face Java SDK for local LLMs, but maybe that's too specific.\n\nWait, the user is asking for the reasons, not how to implement. So focus on the reasons.\n\nLet me draft the answer in Korean.\n\n\"안녕하세요! 로컬 LLM을 사용하는 주요 이유는 다음과 같습니다:\n\n1. **개인정보 보안**: 클라우드 서비스에 데이터를 전송하지 않아 개인정보 유출 위험을 최소화할 수 있습니다. 특히 민감한 데이터 처리 시 매우 중요합니다.\n2. **비용 절감**: 클라우드 API 호출 비용 대비 로컬에서 실행하는 경우, 고주파 요청 시 비용이 크게 절감됩니다.\n3. **실시간 처리 성능**: 네트워크 지연 없이 즉시 응답을 가능하게 하여 실시간 애플리케이션에 적합합니다.\n4. **맞춤형 튜닝**: 로컬에서 모델을 직접 훈련하거나 조정해 특정 용도에 최적화할 수 있습니다.\n5. **법적 규제 준수**: 특정 산업 분야에서 데이터 주거 요구사항을 충족하기 위해 로컬 실행이 필요할 수 있습니다.\n\n예를 들어, Llama 3, Mistral 등 소형 LLM 모델은 로컬 머신에 설치해 사용할 수 있습니다. Java 개발자로서는 Hugging Face Java SDK와 같은 도구를 활용해 로컬 LLM을 효율적으로 통합할 수 있습니다.\n\n추가로 궁금한 점이 있으면 알려주세요! 😊\"\n\nWait, but I should check if the terms are correctly translated. For example, \"개인정보 보안\" is correct. \"비용 절감\" is cost reduction. \"실시간 처리 성능\" is real-time processing performance. \"맞춤형 튜닝\" is custom tuning.\n\nAlso, the example models: Llama 3 is the latest, but maybe the user is familiar with Llama 2. But it's okay.\n\nAlso, the Java part: Hugging Face has a Java SDK, so that's a good point.\n\nThe answer seems good. Let me make sure it's friendly and professional.\n\nYes, the tone is friendly with emojis and the closing. The points are clear.\n\nI think that's a good answer.\n"
    },
    "done": true,
    "done_reason": "stop",
    "total_duration": 132036650359, // 전체 처리 시간 (나노초 단위)
    "load_duration": 61223537,      // 모델 로딩 시간
    "prompt_eval_count": 45,        // 질문에 사용된 토큰 수
    "prompt_eval_duration": 710243481,
    "eval_count": 1809,             // 답변에 생성된 토큰 수
    "eval_duration": 130615466730
}
  • total_duration: 내 컴퓨터가 이 답변을 만드는 데 얼마나 걸렸는지 확인할 수 있는 지표입니다.
  • eval_count: AI가 얼마나 긴 답변을 생성했는지(토큰 수)를 나타냅니다.

도커 환경 주의사항

사용자님의 환경처럼 Docker로 실행 중인 경우, 외부(호스트 PC)에서 localhost:11434로 접근하기 위해서는 컨테이너 실행 시 반드시 -p 11434:11434 옵션이 설정되어 있어야 합니다.

작동 확인 팁: 웹 브라우저 주소창에 http://localhost:11434를 입력했을 때 "Ollama is running"이라는 문구가 뜨면 API 호출 준비가 완벽히 끝난 상태입니다.

profile
자신만의 속도로

0개의 댓글