AI Application DeploymentAI 应用部署

Install Ollama on Linux and Expose It Safely在 Linux 上安装 Ollama 并安全提供服务

Install Ollama on Linux, run a first model, verify the local API and understand why port 11434 should not be exposed to the public internet without authentication.在 Linux 上安装 Ollama、运行首个模型、验证本地 API,并理解为什么不能在没有认证的情况下把 11434 端口直接暴露到公网。

Difficulty 3/5难度 3/525 minutes25 分钟64-bit Linux; model-specific RAM, disk and optional GPU capacity64 位 Linux;内存、硬盘和可选 GPU 容量取决于具体模型

Choose the model before the server

Ollama simplifies local model execution, but it does not remove model resource requirements. Estimate memory, disk and accelerator needs from the exact model and quantization you plan to run. A small CPU-only test and a production inference service are different workloads.

Safe network design

Ollama listens locally by default. Keep that boundary unless you have added an authenticated application or a protected reverse proxy. Do not publish port 11434 directly to the internet.

Operational checklist

Pin and document the model names used by your application.
Reserve enough disk space for model files and updates.
Monitor memory pressure, response latency and service restarts.
Restrict firewall rules to the application hosts that need the API.
Test backup and rebuild procedures; model files can usually be downloaded again, but configuration and application data must be protected.

Sources and next steps

Use the official Ollama Linux documentation and quickstart as the source of truth. If you need a browser interface, continue with the Open WebUI deployment guide.

先选模型,再选服务器

Ollama 简化了本地模型运行,但不会消除模型本身的资源要求。应根据准备运行的具体模型和量化版本估算内存、硬盘和加速卡需求。小型 CPU 测试与生产推理服务是完全不同的负载。

安全的网络设计

Ollama 默认仅在本机监听。除非已经通过带认证的应用或受保护的反向代理接入,否则应保持这一边界。不要把 11434 端口直接暴露到公网。

运维检查

固定并记录应用使用的模型名称和版本。
为模型文件和后续更新预留足够硬盘空间。
监控内存压力、响应延迟和服务重启情况。
防火墙仅允许真正需要调用 API 的应用主机访问。
测试备份和重建流程;模型文件通常可以重新下载,但配置和应用数据必须备份。

资料来源与下一步

请以 Ollama 官方 Linux 文档快速入门 为准。需要浏览器界面时,可继续阅读 Open WebUI 部署教程

Deployment steps部署步骤

01

Confirm the host architecture and capacity确认主机架构与资源

Confirm the Linux architecture, free disk and available memory. Select a model that fits the machine rather than assuming every model will run well.

确认 Linux 架构、可用硬盘和内存,并选择适合当前机器的模型,不要假设所有模型都能流畅运行。

uname -m
free -h
df -h
02

Install Ollama安装 Ollama

Use the current installation command from the official Linux documentation, then inspect the installed version.

使用官方 Linux 文档中的当前安装命令,并在完成后检查安装版本。

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

Check the service检查系统服务

On systemd-based distributions, confirm the service is active and inspect its recent logs if startup fails.

在使用 systemd 的发行版中确认服务已启动;如果启动失败,请查看近期日志。

systemctl status ollama --no-pager
journalctl -u ollama --no-pager -n 100
04

Run a first model运行首个模型

Run a model listed in the official library. The first launch downloads model files, so time and disk usage vary.

运行官方模型库中的模型。首次启动会下载模型文件,因此耗时和硬盘占用会因模型而异。

ollama run gemma3
05

Verify the local API验证本地 API

Verify the API from the same host. Keep the port private and connect remote applications through an authenticated layer.

从同一主机验证 API。保持端口仅内部可用,远程应用应通过带认证的服务层连接。

curl http://127.0.0.1:11434/api/generate -d '{"model":"gemma3","prompt":"Hello","stream":false}'