Clone
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
一、Ollma部署(GUN/Linux)
1.1 下载Ollama,上传至服务器,解压缩
#下载
wget https://github.com/ollama/ollama/releases/download/v0.5.12/ollama-linux-amd64.tgz
#解压
mkdir /opt/ollama && tar -zxvf ollama-linux-amd64.tgz -C /opt/ollama
#创建软链接到/usr/bin目录
ln -s /opt/ollama/bin/ollama /usr/bin/ollama
1.2 创建和启动服务参考链接
#创建用户
sudo useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama
sudo usermod -a -G ollama $(whoami)
#授权文件夹目录
chown -R ollama /opt/ollama
#创建服务
vim /etc/systemd/system/ollama.service
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"
#环境变量,指定当前服务监听的IP和端口
#Environment="OLLAMA_HOST=0.0.0.0:11434"
#环境变量,服务器无内网时需要配置代理拉取大模型
#Environment="HTTP_PROXY=http://your-proxy-server:port"
#Environment="HTTPS_PROXY=http://your-proxy-server:port"
[Install]
WantedBy=default.target
#加载服务
systemctl daemon-reload
#启动服务
systemctl start ollama
systemctl enable ollama
二、MacOS和Windows配置外部访问(使局域网其他设备可以通过API连接大模型)
2.1 MacOS15.3
- 安装好ollama后编辑配置文件,没有就新建一个
nano /Users/xxxusername//Library/LaunchAgents/com.ollama.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ollama</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/ollama</string>
<string>serve</string>
</array>
#开机启动参数
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/ollama.log</string>
<key>StandardErrorPath</key>
<string>/tmp/ollama.error.log</string>
#以下5行是配置OLLAMA_HOST的环境变量
<key>EnvironmentVariables</key>
<dict>
<key>OLLAMA_HOST</key>
<string>0.0.0.0</string>
</dict>
</dict>
</plist>
- 加载配置文件
launchctl load /Users/xxxusername//Library/LaunchAgents/com.ollama.plist
- 运行服务
launchctl start ollama
2.2 Windows11
- 在开始菜单或任务栏搜索“编辑系统环境变量”,点击进入环境变量配置界面。或者右键点击此电脑,进入属性,打开高级系统设置,点击环境变量进入配置。
- 新建一个系统环境变量
变量名:OLLAMA_HOST
变量值:0.0.0.0
三、通过ollama部署本地AI大模型
#需要哪个版本就运行哪个版本,会进行自动下载和运行
ollama run deepseek-r1:8b
#下载模型,不运行使用pull命令
ollama pull deepseek-r1:14b
#查看当前已下载的模型列表
ollama list