在UBUNTU下搭建Deepseek
一、安装UBUNTU
这个就不多说了,无外乎下载UBUNTU的iso,然后用UltraIso制作U盘,然后重启设置启动盘,安装…
二、安装Ollama
curl -sSfL https://ollama.com/install.sh | sh
这里可能需要你先安装curl工具,安装就是了,然后再进行上面的安装。
lucky@lucky-Ubuntu:~$ sudo apt install curl
[sudo] lucky 的密码:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
libllvm17t64 python3-netifaces
使用'sudo apt autoremove'来卸载它(它们)。
下列【新】软件包将被安装:
curl
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 226 kB 的归档。
解压缩后会消耗 534 kB 的额外空间。
获取:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu noble-updates/main amd64 curl amd64 8.5.0-2ubuntu10.6 [226 kB]
已下载 226 kB,耗时 1秒 (313 kB/s)
正在选中未选择的软件包 curl。
(正在读取数据库 ... 系统当前共安装有 152081 个文件和目录。)
准备解压 .../curl_8.5.0-2ubuntu10.6_amd64.deb ...
正在解压 curl (8.5.0-2ubuntu10.6) ...
正在设置 curl (8.5.0-2ubuntu10.6) ...
正在处理用于 man-db (2.12.0-4build2) 的触发器 ...
安装Ollama:
lucky@lucky-Ubuntu:~$ curl -sSfL https://ollama.com/install.sh | sh
>>> Installing ollama to /usr/local
>>> Downloading Linux amd64 bundle
######################################################################## 100.0%
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Enabling and starting ollama service...
Created symlink /etc/systemd/system/default.target.wants/ollama.service → /etc/systemd/system/ollama.service.
>>> Installing NVIDIA repository...
>>> Installing CUDA driver...
正在选中未选择的软件包 cuda-keyring。
(正在读取数据库 ... 系统当前共安装有 152088 个文件和目录。)
还有很多就不展示了,总之安装好了。最后几句话注意到了:
linux-headers-6.11.0-17-generic 已经是最新版 (6.11.0-17.17~24.04.2)。
linux-headers-6.11.0-17-generic 已设置为手动安装。
下列软件包是自动安装的并且现在不需要了:
libllvm17t64 python3-netifaces
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
>>> Reboot to complete NVIDIA CUDA driver install.
就是说,重启之后NVIDIA的CUDA才可以装上驱动。这个比在windows下感觉会智能一些,能够发挥出显卡的优势。
看看版本,我的比较奇葩。
lucky@lucky-ubuntu:~$ ollama -v
ollama version is 0.5.11
三、加载Deepseek大模型
看看能不能装deepseek吧,我这里也没有专门指定,我在windows下是指定了32b版本,后来看,我4070tis的达子显卡,跑这个32b的有些吃力。
根据我的显卡配置(英韦达-4070tis)可以支持14B 的模型尺寸,于是拉了一个14B的模型
ollama pu deepseek-r1:14b
可是运行的时候,输入ollama pu deepseek-r1,则会意外的再给我下载一个7b的版本下来。
ucky@lucky-Ubuntu:~$ ollama run deepseek-r1
pulling manifest
pulling 96c415656d37... 100% ▕████████████████████████████████████████████████████████████████████████▏ 4.7 GB
pulling 369ca498f347... 100% ▕████████████████████████████████████████████████████████████████████████▏ 387 B
pulling 6e4c38e1172f... 100% ▕████████████████████████████████████████████████████████████████████████▏ 1.1 KB
pulling f4d24e9138dd... 100% ▕████████████████████████████████████████████████████████████████████████▏ 148 B
pulling 40fb844194b2... 100% ▕████████████████████████████████████████████████████████████████████████▏ 487 B
verifying sha256 digest
writing manifest
success
很好,到底给我安装的哪个版本呢?
>>> /?
Available Commands:
/set Set session variables
/show Show model information
/load <model> Load a session or model
/save <model> Save your current session
/clear Clear session context
/bye Exit
/?, /help Help for a command
/? shortcuts Help for keyboard shortcuts
Use """ to begin a multi-line message.
>>> /show
Available Commands:
/show info Show details for this model
/show license Show model license
/show modelfile Show Modelfile for this model
/show parameters Show parameters for this model
/show system Show system message
/show template Show prompt template
>>> /show info
Model
architecture qwen2
parameters 7.6B
context length 131072
embedding length 3584
quantization Q4_K_M
Parameters
stop "<|begin▁of▁sentence|>"
stop "<|end▁of▁sentence|>"
stop "<|User|>"
stop "<|Assistant|>"
License
MIT License
Copyright (c) 2023 DeepSeek
估计应该是7b的model吧。
问个话试一试,感觉的确比在windows下流畅太多了,使用14b的模型也几乎秒出结果。
>>> 写一段200字文章,描述乡村的景致
<think>
嗯,用户让我写一篇关于乡村景致的200字文章。首先,我需要明确主题是乡村的景色
,可能包括自然景观、建筑和一些人文元素。200字不算太长,所以得简洁明了地描绘
几个关键点。
用户可能是学生,老师布置了作文作业,或者是想用在什么地方,比如演讲或者展示。
不管怎样,文章需要生动形象,让人有画面感。我应该考虑使用一些具体的意象,比如
田野、老树、炊烟这些元素,能够很好地勾勒出乡村的氛围。
接下来,我要确定文章的结构。开头可以描绘远处的景象,比如山峦和田野,中间部分
描述村庄里的建筑和生活气息,最后加上一些人文元素,比如老人和孩子,让画面更生
动。这样结构清晰,层次分明。
在语言风格上,应该优美而富有诗意,用一些比喻和拟人手法,比如“宛如一幅水墨画
卷”、“炊烟袅袅升起”,这样可以增强文章的感染力。同时,注意字数控制,在
200字左右结束,不要太长。
可能用户希望文章不仅描述景色,还能传达一种宁静、和谐的感觉,所以我要在结尾处
加入一些情感元素,比如夕阳下的宁静或生活的美好,让读者感受到乡村的安详和温暖
。
最后,检查一下有没有重复或者不必要的部分,确保每一句话都为整体服务。这样写出
来的文章应该既符合用户的要求,又能打动人心。
</think>
清晨的阳光洒在起伏的山峦上,远处的田野一片金黄,微风拂过,稻浪翻滚。
village的房顶升起袅袅炊烟,在晨雾中若隐若现。村口的老槐树下,几位老人围坐聊
天,孩童在一旁追逐嬉戏。石板路上斑驳的青苔,诉说着岁月的痕迹。田间的小溪潺潺
流过,清澈见底,偶尔有鱼儿跃出水面。傍晚时分,夕阳将天空染成橘红色,晚霞映照
在田野上,宛如一幅水墨画卷。乡村的夜幕降临得格外静谧,星辰闪烁,仿佛守护这片
宁静的土地。这里的一草一木、一砖一瓦,都承载着人们对自然的敬畏与生活的热爱。
四、ollama服务设置
为了能够让deepseek大模型在局域网甚至公网上提供服务,那么需要ollama能够提供网络服务。
在windows上是设置环境变量(可参看我的前面的windows下的Deepseek搭建文章),在linux下一样也是设置。
设置OLLAMA_HOST=0.0.0.0环境变量,从而允许远程访问。
需要用gedit文件编辑器修改ollama.service文件
sudo gedit /etc/systemd/system/ollama.service
如果没有gedit编辑器,那么就安装呗,总之我觉得这个文件编辑器比系统自带的vi好用,亲民。当然,那种编程码农除外。
sudo gedit /etc/systemd/system/ollama.service
好啦,安装好了。打开文件之后这个样子
改为:
重新加载并重启ollama服务:
sudo systemctl daemon-reload
sudo systemctl restart ollama
验证Ollama服务是否正常运行
sudo netstat -tulpn | grep ollama
显示故障:
lucky@lucky-ubuntu:~/公共$ sudo netstat -tulpn | grep ollama
sudo: netstat:找不到命令
于是安装
sudo apt install net-tools
成功之后再次运行就可以了。
lucky@lucky-ubuntu:~$ sudo netstat -tulpn | grep ollama
tcp 0 0 127.0.0.1:40941 0.0.0.0:* LISTEN 24835/ollama
tcp 0 0 127.0.0.1:11434 0.0.0.0:* LISTEN 6731/ollama
打开网址,输入:127.0.0.1:11434,可以得到如下结果:
输入127.0.0.1:40941则不行,是需要运行7B的模型才行吧?
试一试,也不行,不知道谁占用了40941,谁给我解释一下。
另外遗憾的是,在局域网内,其他计算机还是访问不了。
找了很多文档测试,最后发现可以这样重新设置,并取得成功:
打开文件
sudo gedit /etc/systemd/system/ollama.service
重新设置这两句话:
Environment=“OLLAMA_HOST=0.0.0.0”
Environment=“OLLAMA_ORIGINS=*”
然后在终端分别运行:
systemctl daemon-reload
systemctl restart ollama
再在远程打开测试:
成功了~!
IP地址就是UBUNTU运行ollama的计算机地址。
现在具备了提供ollama服务的条件了,接下来是使用webui进行网页管理使用deepseek大模型的应用了。
WebUI安装
首先要明白的是,webui是将ollama提供的大模型服务转成应用的web服务,也就是说这个webui是安装在提供大模型服务的这台机器上,为局域网内的其他计算机提供大模型的web应用的。也就是说,要在服务机器上安装并运行webui服务。明白了这些,再进行下面的安装(这些都是我跌跌撞撞试错无数得来的经验。
中间参考了很多安装手册,结果都有问题,于是回溯到源头,打开官网寻求帮助:
WEBUI官网
按照这里的要求参看手动安装一节,分两步运行:
Manual Installation
There are two main ways to install and run Open WebUI: using the uv runtime manager or Python’s pip. While both methods are effective, we strongly recommend using uv as it simplifies environment management and minimizes potential conflicts.
Installation with uv (Recommended)
The uv runtime manager ensures seamless Python environment management for applications like Open WebUI. Follow these steps to get started:
- Install uv
Pick the appropriate installation command for your operating system:
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows:
powershell -ExecutionPolicy ByPass -c “irm https://astral.sh/uv/install.ps1 | iex”- Run Open WebUI
Once uv is installed, running Open WebUI is a breeze. Use the command below, ensuring to set the DATA_DIR environment variable to avoid data loss. Example paths are provided for each platform:
macOS/Linux:
DATA_DIR=~/.open-webui uvx --python 3.11 open-webui@latest serve
Windows:
$env:DATA_DIR=“C:\open-webui\data”; uvx --python 3.11 open-webui@latest serve
打开终端,首先运行
curl -LsSf https://astral.sh/uv/install.sh | sh
这部分没有问题,接着运行
DATA_DIR=~/.open-webui uvx --python 3.11 open-webui@latest serve
出问题了,注意看:
lucky@lucky-ubuntu:~/下载$ DATA_DIR=~/.open-webui uvx --python 3.11 open-webui@latest serve
找不到命令 “uvx”,但可以通过以下软件包安装它:
sudo snap install astral-uv
需要安装uvx,那就按照要求安装:
lucky@lucky-ubuntu:~/下载$ sudo snap install astral-uv
[sudo] lucky 的密码:
错误:这个 snap "astral-uv" 的版本是使用经典模式发布的,因此可能会在安全沙箱以外执行任意系统更改,这可能会对您的系统造成风险。
如果您理解并希望继续,请再次运行命令并包括 --classic 参数。
需要安装经典模式的,于是继续:
sudo snap install astral-uv --classic
接下来运行很流畅(我开了Clash怕下载出问题),安装uvx完成之后,接着前面的第二步运行:
lucky@lucky-ubuntu:~/下载$ DATA_DIR=~/.open-webui uvx --python 3.11 open-webui@latest serve
Built peewee==3.17.8
Built pypika==0.48.9
Built red-black-tree-mod==1.22
Built compressed-rtf==1.0.6
Built docx2txt==0.8
Built langdetect==1.0.9
Installed 317 packages in 167ms
...................
安装的很流畅,很多,大约5分钟完成,看到这个说明你安装好了,WEBUI的服务也运行起来了。
INFO: Started server process [30092]██▉ | 41.9M/90.9M [00:02<00:02, 20.4MB/s]
INFO: Waiting for application startup.████ | 52.4M/90.3M [00:07<00:04, 7.94MB/s]
INFO: Application startup complete.█████████████████▌ | 73.4M/90.3M [00:09<00:01, 8.77MB/s]
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)M/90.3M [00:11<00:00, 9.47MB/s]
如果要退出,就将这里的终端运行Ctr+C。
好了,现在在远程就可以运行了(本地也可以),输入网址:
http://localhost:8080/
局域网外面的机器:
很激动哈~!
在局域网里面测试一下:
这个结果有点惊诧~!换14b的模型试一试
我第个娘阿,终于可用了,我真的害怕给我来段英语~!
然后在手机上也测试了,一样,也可以实现本地的应用。
就到这里吧,挺开心的~!