1. 前言
本地部署DeepSeek并实现内网穿透,为家庭成员提供强大的AI支持。通过使用Ollama、Docker、OpenWebUI和Nginx,内网穿透,我们可以轻松实现快速响应和及时搜索功能。
2.软硬件环境
- 系统:ubuntu22.04, cuda12
- GPU: RTX2080Ti
3. Ollama的作用
什么是Ollama?
Ollama 是一个用于 AI 模子推理的后端框架,专为高性能和及时性设计。它答应我们将AI模子部署到各种语言(如JavaScript、Python)中,从而实现快速响应和及时搜索功能。
### 如何利用Ollama举行本地部署?
- curl -fsSL https://ollama.com/install.sh | sh
复制代码 安装完成后,在下令行验证 2. 下载deepseek模子:
- ollama run deepseek-r1:7b
复制代码 —
3.运行deepseek模子
4.开启ollama服务
设置Ollama服务配置
设置OLLAMA_HOST=0.0.0.0环境变量,从而答应远程访问。
下令语法:sudo vim /etc/systemd/system/ollama.service
- sudo systemctl daemon-reload && sudo systemctl restart ollama
复制代码 4. Docker的部署优势
什么是Docker?
Docker 是一个容器化平台,答应我们将应用步伐和其依赖项打包成易于迁移和部署的独立实体。对于DeepSeek本地部署来说,Docker提供了高度同等性和稳定性。
使用docker部署openwebui和nginx服务
- sudo docker pull nginx
- sudo docker network create ds-net(要将openwebui,nginx服务放在一个docker网络中)
- sudo docker run --networks ds-net -d -p xxxx:8080 --gpus all --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.nju.edu.cn/open-webui/open-webui:main
- sudo docker run -d --name nginx-ds --network ds-net -v /your/path/nginx.conf:/etc/nginx/nginx.conf -v /your/ssl_ca/path:/certs -p 5002:443 nginx
复制代码
- 服务运行:
- 这里需要一些后端的底子知识,docker容器端口和宿主机端口,根据个人需求来设定。
5. OpenWebUI的用户界面
什么是OpenWebUI?
OpenWebUI 是一个开源的AI交互界面,支持自然语言交互(NLU)和知识图谱检索。它为用户提供直观的搜索和题目答复功能。
如何利用OpenWebUI举行本地部署?
- 通过openwebui使用deepseek:
第一次登录openwebui需要注册,且第一次注册账号默认为管理员账号。
在这里就部署好本地deepseek服务啦,但是这只能在本地使用,或提供给局域网下的用户使用。如果要想随时随地使用怎么办呢?那就还需要设置内网穿透和反向代理了,这里需要一些更专业的知识了。
6. 内网穿透
内网穿透需要你有公网ip,公网ip 请向运营商申请。有公网ip后,注册一个域名,将域名解析到你的公网ip。公网ip可能是动态变革的,以是需要使用一个脚本将你的公网ip动态解析到域名上。可以参考aliyun,dns解析。此处涉及知识较专业,如有不明请找专业人员协助。
7. Nginx的负载平衡功能
什么是Nginx?
Nginx 是一个高可用性和负载平衡的Web服务器。对于DeepSeek本地部署来说,Nginx确保了服务的稳定性和扩展性。
如何利用Nginx举行部署?
- 配置Nginx:
- 配置Nginx来代理openwebui,对外网提供访问能力。
- 我这里有两个docker容器服务,一个是openwebui,另一个是searxng搜索引擎服务。
- user nginx;
- worker_processes auto;
- error_log /var/log/nginx/error.log notice;
- pid /var/run/nginx.pid;
- events {
- worker_connections 1024;
- }
- http {
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /var/log/nginx/access.log main;
- sendfile on;
- #tcp_nopush on;
- keepalive_timeout 65;
- # include /etc/nginx/conf.d/*.conf
- server {
- listen 443 ssl;
- server_name xxx.xxxxx.cn;(你的域名,需要申请域名并备案)
- ssl_certificate /ssl_ca/path.pem;(要将域名的nginx证书上传到nginx容器的/etc/certs目录下)
- ssl_certificate_key /ssl_ca/path.key;
- ssl_protocols TLSv1.2 TLSv1.3;
- location / {
- proxy_pass http://open-webui:8080/;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- }
- }
- server {
- listen 8001 ssl;
- server_name xxx.xxxxx.cn;(你的域名,需要申请域名并备案)
- ssl_certificate /ssl_ca/path.pem;(要将域名的nginx证书上传到nginx容器的/etc/certs目录下)
- ssl_certificate_key /ssl_ca/path.key;
- ssl_protocols TLSv1.2 TLSv1.3;
- location / {
- proxy_pass http://searxng:8080/;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- }
- }
- }
复制代码
- 如许外网可以通过https://xxx.xx.cn:your-port来访问你的deepseek服务啦。
8. 总结
通过使用Ollama实现快速响应,Docker提供容器化部署的优势,OpenWebUI简化了用户交互界面,以及Nginx实现高可用性和负载平衡,我们可以轻松完成DeepSeek本地部署。这一技术不仅提升了家庭AI支持的效率,也为未来的扩展性奠基了底子。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |