在Linux环境下从0搭建Dify准备工作系统环境私有化部署下载 Dify 代码ZIP包启动Dify隐藏原有logo安装python3和相关依赖启动 DIfy Docker 容器访问 Dify本地环境服务器环境准备工作因工作需要私有化部署公司内部的知识库研究了一下准备采用DifyRAG的方式实现以下是具体步骤。系统环境服务器配置官方建议2核4G以上Liunx版本Rocky Linux release 9.4Docker版本 28.1.1Dify版本1.13.3私有化部署官方建议用Docker Compose的方式部署由于最近Github不太稳定或者是我本地网络的问题在克隆 Dify 代码仓库的时候总是显示失败这里采用直接下载ZIP文件的方式部署。下载 Dify 代码ZIP包按理说我git clone不了的话wget也应该不行结果就是wget下来了不去深究了。#Centos/Rockywgethttps://github.com/langgenius/dify/archive/refs/tags/1.13.3.zip另附上git clone方式拉取。# 拉取当前最新版本gitclone https://github.com/langgenius/dify.git启动Dify将下载好的zip包解压缩#Centos/Rockyunzipdify-1.13.3.zip进到目录里面#Centos/Rockycddify-1.13.3/docker拷贝个配置模版作为配置文件#Centos/Rockycp.env.example .env编辑配置文件#Centos/Rockyvim.env修改端口配置避免跟80端口冲突容器映射出来的端口改为8088NGINX两个端口保持一致#Nginx端口EXPOSE_NGINX_PORT8088NGINX_PORT8088Dify的知识库默认上传文件大小限制为15M对于我们要上传的文件有点小了这里改为150M可以根据实际情况做调整。#上传文件大小改为150MUPLOAD_FILE_SIZE_LIMIT150#上传图片大小改为150MUPLOAD_IMAGE_FILE_SIZE_LIMIT150#上传视频大小改为1000MUPLOAD_VIDEO_FILE_SIZE_LIMIT1000#上传音频大小改为500MUPLOAD_AUDIO_FILE_SIZE_LIMIT500#NGINX上传限制改为150M跟上面有没有冲突没有试大概率是有的NGINX_CLIENT_MAX_BODY_SIZE150M隐藏原有logo一共有4个文件文件1dify-1.13.3/web/app/components/base/chat/chat-with-history/sidebar/index.tsx注释掉power by这一段文件2dify-1.13.3/web/app/components/base/chat/embedded-chatbot/index.tsx同样是power by文件3dify-1.13.3/web/app/components/base/chat/embedded-chatbot/header/index.tsx依然是power by文件4dify-1.13.3/web/app/components/custom/custom-web-app-brand/components/powered-by-brand.tsx最后的power by然后回去修改一下dify-1.13.3/docker/docker-compose.yaml找到web端的配置注释掉原有的image替换成本地。image: myweb build:../web进入dify-1.13.3/docker目录dockercompose downdockercompose up-d--build安装python3和相关依赖在更新sandbox后执行python代码报错Got error code: -500. Got error msg: fork/exec /usr/local/bin/python3: no such file or directory和Traceback (most recent call last): File “/var/sandbox/sandbox-python/tmp/c0d32cf9_dee7_40da_becf_83cf69b6b501.py”, line 48, in File “”, line 2, in ModuleNotFoundError: No module named ‘dateutil’ error: exit status 255经查是容器中没有安装python3和相关依赖导致先去调整了配置文件。文件1dify-1.13.3/docker/volumes/sandbox/conf/config.yamlapp: port:8194debug: True key: dify-sandbox max_workers:4max_requests:50worker_timeout:5python_path: /opt/python/bin/python3 nodejs_path: /usr/local/bin/node enable_network: True# please make sure there is no network risk in your environmentallowed_syscalls:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336]proxy: socks5:http:https:文件2dify-1.13.3/docker/volumes/sandbox/dependencies/python-requirements.txtpython-dateutil numpy scipy cython joblib scikit-learn transformers datasets accelerate icetk cpm_kernels pyspark colorama bitsandbytes sentencepiece streamlit transformers_stream_generator xformers protobuf4.25.3 transformers4.38.1 tokenizers0.15.0 cpm_kernels1.0.11 torch2.1.0 gradio4.19.2 sentencepiece0.2.0 sentence_transformers2.4.0 accelerate0.27.2 streamlit1.31.0 fastapi0.109.0 loguru~0.7.2 mdtex2html1.3.0 latex2mathml3.77.0 jupyter_client8.6.0 openai1.12.0 zhipuai2.0.1 pydantic2.6.2 sse-starlette2.0.0 uvicorn0.27.1 timm0.9.12 tiktoken0.6.0 langchain0.1.9 langchainhub0.1.14 arxiv2.1.0调整配置后再次重启容器dockercompose downdockercompose up-d这里虽然加了python-dateutil但还是会报错遂直接进入容器安装1.首先检查当前容器状态# 查看容器运行状态dockerps|grepsandbox# 进入容器dockerexec-itdocker-sandbox-1 /bin/bash2.在容器内检查 Python 和模块# 在容器内执行以下命令# 1. 检查 Python 版本python3--versionwhichpython3# 2. 检查 pippip3--versionwhichpip3# 3. 检查 dateutil 是否已安装python3-cimport dateutil; print(dateutil.__version__)2/dev/null||echodateutil 未安装# 4. 检查已安装的包pip3 list|grep-idateutil pip3 list|grep-ipython-dateutil3.安装缺失的模块# 在容器内执行pip3installpython-dateutil# 如果权限问题使用pip3install--userpython-dateutil# 或python3-mpipinstallpython-dateutil4.验证安装python3-cimport dateutil; print(dateutil.__version__)至此问题得到解决。启动 DIfy Docker 容器这里发现没有安装Docker安装之。#Centos/Rockydockercompose up-d访问 Dify本地环境http://localhost:8088/install服务器环境http://your_server_ip:8088/install