在 CentOS 上“启动 LibreOffice 服务”通常有两种常见场景,取决于你想用 LibreOffice 做什么。下面分别说明。
如果你是想用 LibreOffice 做文档转换(如 docx → pdf)、在服务器上跑后台任务,一般是启动 LibreOffice Headless 服务。
sudo yum install libreoffice libreoffice-headless
(CentOS 8 可用 dnf)
libreoffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
或简写:
soffice --headless --convert-to pdf test.docx
创建 systemd 服务文件:
sudo vi /etc/systemd/system/libreoffice.service
内容示例:
[Unit]
Description=LibreOffice Headless Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard
Restart=on-failure
User=libreoffice
[Install]
WantedBy=multi-user.target
创建专用用户(可选):
sudo useradd -m libreoffice
启动服务:
sudo systemctl daemon-reload
sudo systemctl start libreoffice
sudo systemctl enable libreoffice
查看状态:
systemctl status libreoffice
直接命令:
libreoffice
或:
soffice
需要安装 X 环境或使用 headless 模式(见上)。
说明你没用 --headless,或没有 X 环境。
netstat -tunlp | grep 8100
或:
ps aux | grep soffice
| 需求 | 做法 |
|---|---|
| 文档转换 | --headless |
| 后台服务 | systemd + socket |
| 图形界面 | 桌面环境直接运行 |
如果你能说明具体用途(如:Java 调用、PHP 转换、Docker 部署),我可以给你更精确的配置。