设置ollama保存模型的路径和监听端口
sudo mkdir /home/ollama_models
sudo chmod 777 /home/ollama_models
sudo vi /etc/systemd/system/ollama.service
在 [Service]下面添加相应的环境变量Environment,包括OLLAMA_MODELS和OLLAMA_HOST
Environment="OLLAMA_MODELS=/home/ollama_models"
Environment="OLLAMA_HOST=0.0.0.0:11434"
通过上述设置,以后ollama pull命令拉取到的模型都保存在/home/ollama_models,而ollama run命令运行的模型都可以在地址0.0.0.0:11434被访问。修改后的ollama.service完整内容如下:
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Environment="OLLAMA_MODELS=/home/ollama_models"
Environment="OLLAMA_HOST=0.0.0.0:11434"
[Install]
WantedBy=default.target
sodu执行下面两个命令使设置生效并重启ollama:
sudo systemctl daemon-reload
sudo systemctl restart ollama
/usr/share/ollama目录保留,最好给一个权限:
sudo chmod 777 /usr/share/ollama