购买阿里ECS服务
Dify推荐配置
CPU >= 2 Core
RAM >= 4 GiB
经测试后,推荐配置 2核(vCPU) 4 GiB 3MB带宽即可 ,响应速度能满足日常使用要求
操作系统推荐 CentOS或Ubuntu
配置 Docker
参考官方文档
以Centos系统为例,操作命令如下
ShellScript
## 更新您的包管理工具。
sudo yum -y update
## 添加阿里云源到您的实例中,这个源包含Docker软件包,方便您使用命令来安装和更新Docker。
sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
## 安装Docker社区版本,容器运行时containerd.io,以及Docker构建和Compose插件。
sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
## 启动Docker并设置Docker守护进程在系统启动时自动启动,这样可以确保每次系统启动时,Docker服务也会自动启动。
sudo systemctl start docker
sudo systemctl enable docker
## 通过查看Docker版本命令,验证Docker是否安装成功。
sudo docker -v
配置Docker镜像源
创建并编辑/etc/docker/daemon.json
文件
ShellScript
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false,
"max-concurrent-downloads": 2,
"max-concurrent-uploads": 2,
"max-download-attempts": 15,
"registry-mirrors": [
"https://docker.m.daocloud.io/",
"https://huecker.io/",
"https://dockerhub.timeweb.cloud",
"https://noohub.ru/",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn",
"https://xx4bwyg2.mirror.aliyuncs.com",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
安装Git环境
ShellScript
## 安装以来
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc-c++ perl-ExtUtils-MakeMaker
## 安装并验证git
yum install git
git --version
安装Dify
克隆 Dify 代码仓库,克隆 Dify 源代码至本地环境。
git clone https://github.com/langgenius/dify.git
启动 Dify
进入 Dify 源代码的 Docker 目录
cd dify/docker
复制环境配置文件
cp .env.example .env
启动 Docker 容器
docker compose up -d
运行命令后,你应该会看到类似以下的输出,显示所有容器的状态和端口映射:
ShellScript
[+] Running 11/11
✔ Network docker_ssrf_proxy_network Created 0.1s
✔ Network docker_default Created 0.0s
✔ Container docker-redis-1 Started 2.4s
✔ Container docker-ssrf_proxy-1 Started 2.8s
✔ Container docker-sandbox-1 Started 2.7s
✔ Container docker-web-1 Started 2.7s
✔ Container docker-weaviate-1 Started 2.4s
✔ Container docker-db-1 Started 2.7s
✔ Container docker-api-1 Started 6.5s
✔ Container docker-worker-1 Started 6.4s
✔ Container docker-nginx-1 Started 7.1s
最后检查是否所有容器都正常运行:
ShellScript
docker compose ps
在这个输出中,你应该可以看到包括 3 个业务服务 api / worker / web
,以及 6 个基础组件 weaviate / db / redis / nginx / ssrf_proxy / sandbox
。
ShellScript
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
docker-api-1 langgenius/dify-api:0.6.13 "/bin/bash /entrypoi…" api About a minute ago Up About a minute 5001/tcp
docker-db-1 postgres:15-alpine "docker-entrypoint.s…" db About a minute ago Up About a minute (healthy) 5432/tcp
docker-nginx-1 nginx:latest "sh -c 'cp /docker-e…" nginx About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
docker-redis-1 redis:6-alpine "docker-entrypoint.s…" redis About a minute ago Up About a minute (healthy) 6379/tcp
docker-sandbox-1 langgenius/dify-sandbox:0.2.1 "/main" sandbox About a minute ago Up About a minute
docker-ssrf_proxy-1 ubuntu/squid:latest "sh -c 'cp /docker-e…" ssrf_proxy About a minute ago Up About a minute 3128/tcp
docker-weaviate-1 semitechnologies/weaviate:1.19.0 "/bin/weaviate --hos…" weaviate About a minute ago Up About a minute
docker-web-1 langgenius/dify-web:0.6.13 "/bin/sh ./entrypoin…" web About a minute ago Up About a minute 3000/tcp
docker-worker-1 langgenius/dify-api:0.6.13 "/bin/bash /entrypoi…" worker About a minute ago Up About a minute 5001/tcp
通过这些步骤,你应该可以成功在阿里云服务器安装 Dify。
后续,可以通过配置域名关联该服务器外网IP,通过域名访问此Dify服务。