(Local LLM) Ollama 시작하기

Local LLM 시리즈

  1. (Local LLM) Ollama 시작하기
  2. Codex 와 Local LLM 연결하기

Ollama 란

ollama 는 LLM model 을 local machine 에서 서버로 서비스를 제공할 수 있는 플랫폼이다.

  • ollama 제공 및 외부 LLM Model 을 서버 및 채팅 제공 CLI
  • LLM model 파라미터 조정

Gemini 통해 그린 ollama 서비스 다이어그램.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
┌─────────────────────────────────────────────────────────────────┐
│ Windows 11 Host (ASUS A14 / RTX 4060 Laptop GPU 8GB) │
│ │
│ ┌────────────────────────┐ [Mirrored Network Mode] │
│ │ Windows App / IDE │ - Ports are shared directly │
│ │ (VS Code, Cursor 등) │ - No Port Forwarding Needed │
│ └───────────┬────────────┘ │
│ │ (HTTP Request to localhost:11434) │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ WSL2 Ubuntu Environment (goyangi2) │ │
│ │ │ │
│ │ ollama.service [systemd] │ │
│ │ └── Port: 0.0.0.0:11434 (LISTENING) │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Ollama Runner (llama.cpp / GGML Backend) │ │ │
│ │ └──────────────────────┬───────────────────────┘ │ │
│ └────────────────────────────────┼────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────▼────────────────────────────┐ │
│ │ NVIDIA CUDA Driver Layer │ │
│ └────────────────────────────────┬────────────────────────────┘ │
│ │ (100% GPU Offload) │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ RTX 4060 VRAM (8GB) Dedicated Memory │ │
│ │ ├── Model Weights (Gemma 4 4.6B Q5) ─── [ 5.4 GiB ] │ │
│ │ ├── KV Cache (num_ctx: 12288) ───────── [ 392.0 MiB ] │ │
│ │ └── Compute Graph (CUDA0) ───────────── [ 302.0 MiB ] │ │
│ │ │ │
│ │ └── [ 🚀 Total GPU Memory Used: 6.6 GiB / 8.0 GiB ] │ │
│ └─────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘

ollama 설치

ollama CLI 와 Model 은 아래 사이트에서 다운로드 받을 수 있다.

설치후 LLM Chat, API call, Codex / Claude CLI 에 연동해서 사용할 수 있다.


설치

https://ollama.com/download/linux

1
curl -fsSL https://ollama.com/install.sh | sh

ollama CLI 명령

ollama CLI 명령

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ ollama
Ollama 0.21.2

▸ Chat with a model
Start an interactive chat with a model

Launch OpenClaw (install)
Personal AI with 100+ skills

Launch Claude Code
Anthropic's coding tool with subagents

Launch OpenCode (not installed)
Anomaly's open-source coding agent

More...
Show additional integrations

사용 가능한 명령:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Usage:
ollama [flags]
ollama [command]

Available Commands:
serve Start Ollama
create Create a model
show Show information for a model
run Run a model
stop Stop a running model
pull Pull a model from a registry
push Push a model to a registry
signin Sign in to ollama.com
signout Sign out from ollama.com
list List models
ps List running models
cp Copy a model
rm Remove a model
launch Launch the Ollama menu or an integration
help Help about any command

Flags:
-h, --help help for ollama
--nowordwrap Don't wrap words to the next line automatically
--verbose Show timings for response
-v, --version Show version information

Use "ollama [command] --help" for more information about a command.

모델 다운로드 pull 명령으로 ollama 저장소 제공 모델 다운로드할 수 있다.


[pull 명령]

pull 명령으로 모델을 다운로드 한다.

1
2
3
$ ollama pull gemma4:e2b
pulling manifest
pulling 4e30e2665218: 2% ▕█ ▏ 109 MB/7.2 GB 56 MB/s 2m5s

pull 로 다운받은 모델 저장 디렉토리:

  • /usr/share/ollama/.ollama/models :(시스템 서비스 실행 시)

[Ollama 경로 변경]

Ollama는 환경 변수 OLLAMA_MODELS 를 참조합니다.

1
export OLLAMA_MODELS="/data/models/ollama"

설정 후 source ~/.bashrc와 sudo systemctl restart ollama를 잊지 마세요.


[ls 명령]

모델 목록 조회

1
2
3
4
5
6
$ ollama ls
NAME ID SIZE MODIFIED
gemma4:e2b 7fbdbf8f5e45 7.2 GB 3 days ago
gemma4-e4b-32k:latest 6d2a1a196ef9 9.6 GB 4 weeks ago
gemma4:e4b c6eb396dbd59 9.6 GB 4 weeks ago
qwen2.5-coder:latest dae161e27b0e 4.7 GB 4 weeks ag
  • gemma4-e4b: 다운로드한 원래 모델
  • gemma4-e4b-32k: 모델의 파라미터를 수정한 Modelfile 에서 생성한 새 모델

[rm 명령]

rm 명령으로 다운 받은 모델을 삭제한다.

1
ollama rm gemma4:e4b

[show 명령]

show 명령으로 모델의 세부 정보를 조회할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ ollama show gemma4:e4b
Model
architecture gemma4
parameters 8.0B
context length 131072
embedding length 2560
quantization Q4_K_M
requires 0.20.0

Capabilities
completion
vision
audio
tools
thinking

Parameters
temperature 1
top_k 64
top_p 0.95

License
Apache License
Version 2.0, January 2004
...

[run 명령]

run 명령은 ollama 모델로 다운받은 NAME 이름의 모델을 서비스로 시작해 준다.

  • 시스템의 ollama 서비스를 시작해 http로 11434 포트를 통해서 제공된다.
  • run 명령은 CLI 채팅을 시작
1
2
3
4
ollama run gemma4:e2b
>>> Send a message (/? for help)
>>>
Use Ctrl + d or /bye to exit

run NAME 명령 혹은 serve 명령으로 시스템 서비스로 11434 포트를 통해 웹서비스가 시작된다.

1
2
3
$ sudo ss -tunlp | grep ollama
tcp LISTEN 0 4096 127.0.0.1:35965 0.0.0.0:* users:(("ollama",pid=824718,fd=3))
tcp LISTEN 0 4096 127.0.0.1:11434 0.0.0.0:* users:(("ollama",pid=165,fd=3))

브라우저로 11434 포트에 접속해 보면 ‘Ollama is running’ 을 확인 가능하다.


[ps 명령]

ps 명령은 실행중인 ollama 프로세스를 확인할 수 있다.

1
2
3
$ ollama ps
NAME ID SIZE PROCESSOR CONTEXT UNTIL
gemma4:e2b 7fbdbf8f5e45 7.7 GB 75%/25% CPU/GPU 4096 4 minutes from now

ollama 는 설치시 리눅스 계열에서는 systemd 로 설치된다. systemd 상태를 확인할 수 있다.

1
2
3
4
5
6
7
$ systemctl status ollama
● ollama.service - Ollama Service
Loaded: loaded (/etc/systemd/system/ollama.service; enabled; preset: enabled)
Active: active (running) since Fri 2026-05-29 22:02:07 KST; 9h ago
Main PID: 165 (ollama)
Tasks: 25 (limit: 28826)

[로그 확인]

로그 확인은 journalctl 를 사용한다.

1
2
3
4
journalctl -u ollama -f
5월 29 07:42:11 goyangi2 ollama[165]: time=2026-05-29T07:42:11.649+09:00 level=INFO source=server.go:1398 msg="waiting for server to become available" status="llm server loading model"
5월 29 07:42:19 goyangi2 ollama[165]: time=2026-05-29T07:42:19.188+09:00 level=INFO source=server.go:1402 msg="llama runner started in 69.72 seconds"
5월 29 07:42:19 goyangi2 ollama[165]: [GIN] 2026/05/29 - 07:42:19 | 200 | 1m10s | 127.0.0.1 | POST "/api/generate"

줄수 만큼 로그 기록 확인

1
journalctl -u ollama -n 100 

[OpenAI API 호환 엔드포인트]

Ollama는 별도의 설정 없이도 OpenAI와 호환되는 API 엔드포인트를 기본적으로 제공합니다.


[stop 명령]

1
ollama stop

ollama 시스템 서비스를 시작한다.

1
ollama serve

systemd 를 직접 종료할 수 있겠다.

1
sudo systemctl stop ollama

서비스 환경변수 확인

1
$ sudo systemctl show ollama --property=Environment


Modelfile 로 성능 조정

ollama 는 Modelfile 을 이용해 기존 모델의 파라미터를 조정해 새로운 모델로 서빙할 수 있다.

모델파일

Modelfile 은 텍스트 파일로 특정 모델의 파라미터, 프롬프를 조정해 새로운 모델로 생성할 수 있다.


모델은 FROM 구문에 지정한다. 1) ollma 에 등록된 모델을 사용하거나, 2) gguf 경로, 3) hf.co 의 URI 를 사용하면 된다.

1
2
3
4
5
6
7
$ ollama ls
NAME ID SIZE MODIFIED
qwen3-14b-han:latest bb1dc5fee044 9.0 GB 10 hours ago
hf.co/unsloth/Qwen3-14B-GGUF:Q4_K_M 1c75fc1b9127 9.0 GB 10 hours ago
gemma4-e4b-32k:latest 2bb4cc1b3660 9.6 GB 3 days ago
my-default:latest 2bb4cc1b3660 9.6 GB 3 days ago
gemma4:e4b c6eb396dbd59 9.6 GB 3 days ago

모델파일 작성

Modelfile 작성시 텍스트 파일에 FROM 구문으로 모델을 지정하고 팔라미터를 설정하면 된다.

다음은 ollama 모델에 할당한 num_ctx 토큰량 컨텍스트 크기를 직접 지정하는 예이다.

1
2
FROM qwen2.5-coder:7b              # 모델 이름(ollama 다운로드) 혹은 모델의 위치
PARAMETER num_ctx 32768 # 컨텍스트 크기를 32768(32k)로 설정

[모델 생성]

새 파라미터로 모델을 생성

1
ollama create qwen-7b-32k -f Modelfile

새 모델 런치

1
ollama run qwen-7b-32k

모델 파일 파라미터

  1. GPU 가속 최적화 (GPU Layers 설정)

Ollama는 기본적으로 GPU에 모델 레이어를 분배하지만, 때때로 VRAM 여유가 있음에도 일부를 CPU(RAM)에 남겨두는 경우가 있습니다. 모든 연산을 GPU에서 처리하도록 강제하면 속도가 비약적으로 향상됩니다.

  • gpu layers 는 모델 메타 정보에서 확인이 가능하다
1
2
3
FROM qwen2.5-coder:7b
# -1은 가능한 모든 레이어를 GPU에 올리라는 뜻입니다.
PARAMETER num_gpu -1
  1. Context Window

ollma 모델은 **Context Window(문맥 창)**가 4096 으로 제한되는데 num_ctx 토큰량 컨텍스트 크기를 직접 지정한다.

1
PARAMETER num_ctx 32768            # 컨텍스트 크기를 32768(32k)로 설정
  1. KV 캐시 양자화 (Flash Attention 및 메모리 절약)

32k와 같은 긴 컨텍스트를 사용할 때 가장 많은 메모리를 잡아먹는 것은 모델 자체보다 KV Cache(이전 대화를 기억하는 메모리)입니다. Ollama 최신 버전에서는 이를 압축하여 VRAM 부담을 줄일 수 있습니다.

1
PARAMETER temperature 1.0
  1. 무작위 토큰 선택을 제한하여 코드 일관성 유지

PARAMETER top_p 0.95
PARAMETER top_k 64


기존 모델의 파라미터 확인

다운 받은 모델의 세부 파라미터를 확인할 수 있다. 이 정보를 모델 파일로 리다이렉트해서 편집해 사용할 수 있다.

ollama show 로 모델의 파라미터를 확인하고 결과를 모델 파일로 리다이렉트하면 저장할 수 있다.

1
ollama show qwen3-14b-coding --modelfile > Modelfile

필요한 부분을 수정후 새 모델로 실행하면 된다.

1
2
ollama create ds-v4 -f Modelfile
ollama run ds-v4
Author

Gangtai Goh

Posted on

2026-05-30

Updated on

2026-06-28

Licensed under