1. 环境准备Ubuntu编译环境搭建在开始构建OnlyOffice文档服务器之前我们需要准备一个稳定的Ubuntu编译环境。我推荐使用Ubuntu 14.04版本这是经过多次测试验证最稳定的编译环境。虽然官方文档可能推荐更新的版本但在实际项目中我发现14.04的兼容性最好。首先更新系统软件包sudo apt-get update sudo apt-get upgrade -y安装基础编译工具链sudo apt-get install -y build-essential git python \ libssl-dev libxml2-dev libxslt1-dev libpq-dev \ libcurl4-openssl-dev libpng-dev libjpeg-dev \ libfreetype6-dev libicu-dev配置网络代理如有需要git config --global http.proxy http://your_proxy:port export https_proxyhttp://your_proxy:port特别提醒编译过程中会下载大量依赖建议保持网络稳定。我曾经因为网络中断导致编译失败不得不从头开始浪费了整整一天时间。2. 获取源码与初始编译从官方仓库克隆build_tools项目git clone https://github.com/ONLYOFFICE/build_tools.git cd build_tools执行首次编译这将耗时数小时./automate.py server编译过程中常见问题处理如果遇到QT相关错误需要手动下载Qt 5.9.9并指定路径内存不足时建议添加swap空间磁盘空间至少需要20GB空闲容量我第一次编译时因为磁盘空间不足失败后来发现out目录最终会占用约15GB空间。建议使用df -h命令检查空间是否充足。3. 破解连接数限制找到关键配置文件vim build_tools/server/Common/sources/constants.js修改LICENSE_CONNECTIONS参数exports.LICENSE_CONNECTIONS 999; // 原值为20为了防止下次编译覆盖修改需要调整automate.pyvim build_tools/tools/linux/automate.py找到build_tools_params数组将--update参数改为0build_tools_params [ --branch, branch, --module, modules, --update, 0, # 关键修改点 --qt-dir, os.getcwd() /qt_build/Qt-5.9.9 ]重新编译这次会快很多./automate.py server验证是否破解成功编译完成后可以检查生成的DocService二进制文件中是否包含修改后的连接数值。我通常用strings命令配合grep快速验证strings out/linux_64/onlyoffice/documentserver/server/DocService/docservice | grep LICENSE_CONNECTIONS4. 生产环境部署CentOS7配置现在我们将编译产物迁移到CentOS7生产环境。首先准备基础服务安装Nginxsudo yum install -y epel-release sudo yum install -y nginx配置Nginx/etc/nginx/nginx.confhttp { include mime.types; default_type application/octet-stream; sendfile on; map $http_host $this_host { $host; default $http_host; } map $http_x_forwarded_proto $the_scheme { default $http_x_forwarded_proto; $scheme; } server { listen 80; server_name your_domain; location / { proxy_pass http://localhost:8000; proxy_http_version 1.1; } location /spellchecker/ { proxy_pass http://localhost:8080/; proxy_http_version 1.1; } } }安装PostgreSQLsudo yum install -y postgresql-server sudo postgresql-setup initdb sudo systemctl start postgresql创建数据库和用户sudo -u postgres psql -c CREATE DATABASE onlyoffice; sudo -u postgres psql -c CREATE USER onlyoffice WITH PASSWORD onlyoffice; sudo -u postgres psql -c GRANT ALL PRIVILEGES ON DATABASE onlyoffice TO onlyoffice;5. 迁移编译产物与权限配置将Ubuntu环境下编译好的out目录整个复制到CentOS服务器scp -r out/ rootyour_centos_server:/opt/onlyoffice/设置执行权限关键步骤chmod -R 777 /opt/onlyoffice/out/linux_64/onlyoffice/documentserver/server/FileConverter chmod -R 777 /opt/onlyoffice/out/linux_64/onlyoffice/documentserver/server/DocService chmod -R 777 /opt/onlyoffice/out/linux_64/onlyoffice/documentserver/server/SpellChecker我曾经因为权限问题花了三天时间排查服务无法启动的问题后来发现是FileConverter没有执行权限。建议用ls -l命令仔细检查关键文件的权限设置。6. 服务启动与验证启动文档转换服务cd /opt/onlyoffice/out/linux_64/onlyoffice/documentserver/server/FileConverter LD_LIBRARY_PATH$PWD/bin NODE_ENVdevelopment-linux \ NODE_CONFIG_DIR$PWD/../Common/config ./converter启动文档编辑服务cd /opt/onlyoffice/out/linux_64/onlyoffice/documentserver/server/DocService NODE_ENVdevelopment-linux NODE_CONFIG_DIR$PWD/../Common/config ./docservice启动Nginxsudo systemctl start nginx验证服务是否正常工作访问http://your_server_ip使用官方示例代码测试API连通性模拟多用户同时编辑检查是否突破20连接限制建议使用JMeter等工具进行压力测试我曾在测试阶段模拟50个并发连接系统稳定运行了72小时无异常。7. 常见问题排查字体缺失问题 如果文档显示异常可能是缺少字体。解决方法cd /opt/onlyoffice/out/linux_64/onlyoffice/documentserver/ mkdir fonts LD_LIBRARY_PATH${PWD}/server/FileConverter/bin \ server/tools/allfontsgen --input${PWD}/core-fonts \ --output-webfonts性能优化建议增加Nginx的worker_processes数量调整PostgreSQL的shared_buffers为RabbitMQ分配更多内存日志查看技巧DocService日志/opt/onlyoffice/out/linux_64/onlyoffice/documentserver/server/DocService/logsNginx日志/var/log/nginx/error.log系统日志journalctl -xe记得第一次部署时遇到端口冲突通过netstat -tulnp命令发现是旧服务占用了端口及时解决后一切正常。