跳到主要内容

在本地服务器上编译 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 文档源代码​

  1. 克隆 build_tools 仓库:

    git clone https://github.com/ONLYOFFICE/build_tools.git
  2. 进入 build_tools/tools/linux 目录:

    cd build_tools/tools/linux
  3. 运行 automate.py 脚本,指定 server 参数以编译 ONLYOFFICE 文档:

    python3 ./automate.py server
    备注

    如果您在没有任何参数的情况下运行脚本,这将同时构建 ONLYOFFICE 文档、文档生成器和桌面编辑器。

    python3 ./automate.py

    如果需要,您可以通过运行带有相应参数的脚本来同时构建多个产品。要了解有关编译文档生成器的更多信息,您可以阅读本文。要了解有关编译桌面编辑器的更多信息,请参阅本文。

等待脚本执行。根据您的计算机性能,这个过程可能需要相当长的时间。例如,在 4x2.3GHz vCPUs 上至少需要 3 小时。

该脚本将编译 ONLYOFFICE 文档的所有依赖项和组件。

构建的 ONLYOFFICE 文档将位于 ../../out/linux_64/onlyoffice/documentserver/ 目录中。

安装和配置 NGINX​

ONLYOFFICE 文档使用 NGINX 作为 Web 服务器。

安装和配置 NGINX​

  1. 安装 NGINX:

    sudo apt-get install nginx
  2. 禁用默认网站:

    sudo rm -f /etc/nginx/sites-enabled/default
  3. 创建 /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;
    }
    }
  4. 将新创建的网站的符号链接添加到 /etc/nginx/sites-available 目录:

    sudo ln -s /etc/nginx/sites-available/onlyoffice-documentserver /etc/nginx/sites-enabled/onlyoffice-documentserver
  5. 重启 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 文档组件作为前台进程运行。因此,您需要单独的终端控制台来运行它们,或者使用特定工具将前台进程在后台模式下运行。

  1. 启动 FileConverter 服务:

    cd out/linux_64/onlyoffice/documentserver/server/FileConverter
    LD_LIBRARY_PATH=$PWD/bin NODE_ENV=development-linux NODE_CONFIG_DIR=$PWD/../Common/config ./converter
  2. 启动 DocService 服务:

    cd out/linux_64/onlyoffice/documentserver/server/DocService
    NODE_ENV=development-linux NODE_CONFIG_DIR=$PWD/../Common/config ./docservice