在本地服务器上编译 ONLYOFFICE 文档
简介
ONLYOFFICE 文档是一个在线办公套件,包含文本文档、电子表格和演示文稿的查看器和编辑器,完全兼容 Office Open XML 格式:.docx、.xlsx、.pptx,并支持实时协作编辑。
您可以轻松地从源代码编译 ONLYOFFICE 文档,并使用专门设计的 build_tools 工具将解决方案部署在本地服务器上。build_tools 工具允许自动获取和安装编译过程所需的所有组件,以及 ONLYOFFICE 文档正常工作所需的所有依赖项,还可以获取 ONLYOFFICE 文档的最新版本源代码并构建其所有组件。
我们只能保证从 master 分支构建的产品正常工作。
系统要求
硬件
- CPU:4 核
- 内存:至少 8 GB,但取决于主机操作系统。更多更好
- SSD:至少 100 GB 的可用空间
- 交换空间:至少 4 GB,但取决于主机操作系统。更多更好
软件
- 操作系统:64 位 Ubuntu 24.04
该解决方案已在 Ubuntu 24.04 上测试。其他发行版可能需要一些特定操作,这里未描述。
安装依赖项
如果您的计算机上尚未安装 Python 和 Git,您可能需要安装它们。这可以通过以下命令完成:
sudo apt-get install -y python3 git
构建 ONLYOFFICE 文档源代码
-
克隆 build_tools 仓库:
git clone https://github.com/ONLYOFFICE/build_tools.git -
进入
build_tools/tools/linux目录:cd build_tools/tools/linux -
运行
automate.py脚本,指定server参数以编译 ONLYOFFICE 文档:python3 ./automate.py server
等待脚本执行。根据您的计算机性能,这个过程可能需要相当长的时间。例如,在 4x2.3GHz vCPUs 上至少需要 3 小时。
该脚本将编译 ONLYOFFICE 文档的所有依赖项和组件。
构建的 ONLYOFFICE 文档将位于 ../../out/linux_64/onlyoffice/documentserver/ 目录中。
安装和配置 NGINX
ONLYOFFICE 文档使用 NGINX 作为 Web 服务器。
安装和配置 NGINX
-
安装 NGINX:
sudo apt-get install nginx -
禁用默认网站:
sudo rm -f /etc/nginx/sites-enabled/default -
创建
/etc/nginx/sites-available/onlyoffice-documentserver文件,内容如下:map $http_host $this_host {"" $host;default $http_host;}map $http_x_forwarded_proto $the_scheme {default $http_x_forwarded_proto;"" $scheme;}map $http_x_forwarded_host $the_host {default $http_x_forwarded_host;"" $this_host;}map $http_upgrade $proxy_connection {default upgrade;"" close;}proxy_set_header Host $http_host;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection $proxy_connection;proxy_set_header X-Forwarded-Host $the_host;proxy_set_header X-Forwarded-Proto $the_scheme;server {listen 0.0.0.0:80;listen [::]:80 default_server;server_tokens off;rewrite ^\/OfficeWeb(\/apps\/.*)$ /web-apps$1 redirect;location / {proxy_pass http://localhost:8000;proxy_http_version 1.1;}} -
将新创建的网站的符号链接添加到
/etc/nginx/sites-available目录:sudo ln -s /etc/nginx/sites-available/onlyoffice-documentserver /etc/nginx/sites-enabled/onlyoffice-documentserver -
重启 NGINX 以应用更改:
sudo nginx -s reload
生成字体数据
cd out/linux_64/onlyoffice/documentserver/
mkdir fonts
LD_LIBRARY_PATH=${PWD}/server/FileConverter/bin server/tools/allfontsgen \
--input="${PWD}/core-fonts" \
--allfonts-web="${PWD}/sdkjs/common/AllFonts.js" \
--allfonts="${PWD}/server/FileConverter/bin/AllFonts.js" \
--images="${PWD}/sdkjs/common/Images" \
--selection="${PWD}/server/FileConverter/bin/font_selection.bin" \
--output-web='fonts' \
--use-system="true"
生成演示主题
cd out/linux_64/onlyoffice/documentserver/
LD_LIBRARY_PATH=${PWD}/server/FileConverter/bin server/tools/allthemesgen \
--converter-dir="${PWD}/server/FileConverter/bin"\
--src="${PWD}/sdkjs/slide/themes"\
--output="${PWD}/sdkjs/common/Images"
运行 ONLYOFFICE 文档
所有 ONLYOFFICE 文档组件作为前台进程运行。因此,您需要单独的终端控制台来运行它们,或者使用特定工具将前台进程在后台模式下运行。
-
启动 FileConverter 服务:
cd out/linux_64/onlyoffice/documentserver/server/FileConverterLD_LIBRARY_PATH=$PWD/bin NODE_ENV=development-linux NODE_CONFIG_DIR=$PWD/../Common/config ./converter -
启动 DocService 服务:
cd out/linux_64/onlyoffice/documentserver/server/DocServiceNODE_ENV=development-linux NODE_CONFIG_DIR=$PWD/../Common/config ./docservice