Skip to content

Commit 22297d7

Browse files
doc: add ollama integration
1 parent 5347121 commit 22297d7

4 files changed

Lines changed: 141 additions & 1 deletion

File tree

83.2 KB
Loading
119 KB
Loading

docs/model_integration/ollama.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
!!! Abstract ""
2+
3+
本文以阿里云新加坡区 ECS 实例为例,演示 ollama 安装及其与 SQLBot 对接。
4+
5+
## 安装ollama
6+
7+
执行以下命令安装 ollama:
8+
```shell
9+
curl -fsSL https://ollama.com/install.sh | sh
10+
```
11+
12+
输出如下:
13+
```shell
14+
root@iZt4n4e3wmu6ddsc0hb3wbZ:~# curl -fsSL https://ollama.com/install.sh | sh
15+
>>> Installing ollama to /usr/local
16+
>>> Downloading Linux amd64 bundle
17+
######################################################################## 100.0%
18+
>>> Creating ollama user...
19+
>>> Adding ollama user to render group...
20+
>>> Adding ollama user to video group...
21+
>>> Adding current user to ollama group...
22+
>>> Creating ollama systemd service...
23+
>>> Enabling and starting ollama service...
24+
Created symlink /etc/systemd/system/default.target.wants/ollama.service → /etc/systemd/system/ollama.service.
25+
>>> The Ollama API is now available at 127.0.0.1:11434.
26+
>>> Install complete. Run "ollama" from the command line.
27+
WARNING: No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode.
28+
```
29+
30+
## 修改ollama配置
31+
32+
修改文件ollama.service,让 ollama 访问可被外部访问
33+
```shell
34+
vim /etc/systemd/system/ollama.service
35+
```
36+
37+
加入以下内容:
38+
```
39+
Environment="OLLAMA_HOST=0.0.0.0:11434"
40+
Environment="OLLAMA_ORIGINS=*
41+
```
42+
43+
文件内容如下:
44+
```
45+
[Unit]
46+
Description=Ollama Service
47+
After=network-online.target
48+
49+
[Service]
50+
ExecStart=/usr/local/bin/ollama serve
51+
User=ollama
52+
Group=ollama
53+
Restart=always
54+
RestartSec=3
55+
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
56+
Environment="OLLAMA_HOST=0.0.0.0:11434"
57+
Environment="OLLAMA_ORIGINS=*
58+
59+
[Install]
60+
WantedBy=default.target
61+
```
62+
63+
## 重启ollama服务
64+
65+
执行命令重启 ollama:
66+
```shell
67+
service ollama restart
68+
```
69+
70+
## 安装运行大模型
71+
72+
此处以 qwen3-14b 为例,执行以下命令安装大模型:
73+
```shell
74+
ollama run qwen3:14b
75+
```
76+
77+
输出如下:
78+
```shell
79+
root@iZt4n4e3wmu6ddsc0hb3wbZ:~# ollama run qwen3:14b
80+
pulling manifest
81+
pulling a8cc1361f314: 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 9.3 GB
82+
pulling ae370d884f10: 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 1.7 KB
83+
pulling d18a5cc71b84: 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 11 KB
84+
pulling cff3f395ef37: 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 120 B
85+
pulling 78b3b822087d: 100% ▕████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 488 B
86+
verifying sha256 digest
87+
writing manifest
88+
success
89+
>>> Send a message (/? for help)
90+
```
91+
92+
## 安装 OpenWebUI(可选)
93+
94+
!!! Abstract ""
95+
96+
OpenWebUI 可在 web 界面上与大模型进行交互,非必需。
97+
98+
### 安装docker
99+
100+
在服务器上安装 Docker,本文使用 DataEase 项目组编写安装脚本进行安装,用户可自行选择如何安装 Docker。
101+
```shell
102+
curl -fsSL https://resource.fit2cloud.com/get-docker-linux.sh | bash
103+
104+
# 设置 docker 开机自启,并启动 docker 服务
105+
systemctl enable docker; systemctl daemon-reload; service docker start
106+
```
107+
108+
### 安装OpenWebUI
109+
110+
按官方示例,以 docker 直接启动 OpenWebUI,它会自动关联本地 ollama。
111+
```shell
112+
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
113+
```
114+
115+
OpenWebUI启动需要一些时间,需确认容器运行状态为「healthy」:
116+
```shell
117+
root@iZt4n4e3wmu6ddsc0hb3wbZ:~# docker ps -a
118+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
119+
ba913b54d026 ghcr.io/open-webui/open-webui:main "bash start.sh" 10 minutes ago Up 9 minutes (healthy) 0.0.0.0:3000->8080/tcp, [::]:3000->8080/tcp open-webui
120+
```
121+
122+
启动完成后,可在浏览器上通过 ip:3000来访问,如下图所示:
123+
![openwebui](../img/model_integration/openwebui.png)
124+
125+
## 确认服务状态
126+
127+
在 SQLBot 服务器上访问 ollama 服务,确认网络是通的:
128+
```shell
129+
root@iZt4n4e3wmu6ddsc0hb3wbZ:~#nc -zv 47.237.135.165 11434
130+
Connection to 47.237.135.165 port 11434 [tcp/*] succeeded!
131+
```
132+
133+
## 接入SQLBot
134+
135+
基础模型此处输入之前安装运行的 qwen3:14b。
136+
ollama 默认运行在 11434 端口上,API 域名输入 http://47.237.135.165:11434/v1,注意47.237.135.165换成自己实际的 ip 地址。
137+
API Key 可以随意填写,保存即可。
138+
![ollama](../img/model_integration/ollama_sqlbot.png)

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ nav:
6868
- AI 模型配置: system/model.md
6969
- 嵌入式管理: system/embedding.md
7070
- 系统设置: system/system.md
71-
- MCP 服务 : mcp_server.md
71+
- 模型接入:
72+
- Ollama: model_integration/ollama.md
73+
- MCP 服务: mcp_server.md
7274
- 联系我们: contact.md
7375

7476
markdown_extensions:

0 commit comments

Comments
 (0)