温馨提示×

centos libreoffice如何配置

小樊
38
2026-09-21 14:48:56
栏目: 智能运维

CentOS 上配置 LibreOffice,通常分为 安装、运行环境配置、服务化(可选) 三个部分。下面按常见使用场景说明。


一、安装 LibreOffice(CentOS 7 / 8 / Stream)

1. 使用系统仓库安装(最简单)

# CentOS 7
yum install -y libreoffice

# CentOS 8 / Stream
dnf install -y libreoffice

安装完成后检查:

libreoffice --version

⚠️ 系统仓库版本通常较旧,但稳定。


2. 安装官方最新版(推荐用于转换/开发)

从官网下载 RPM 包:

wget https://download.documentfoundation.org/libreoffice/stable/24.2.5/rpm/x86_64/LibreOffice_24.2.5_Linux_x86-64_rpm.tar.gz
tar -xzf LibreOffice_24.2.5_Linux_x86-64_rpm.tar.gz
cd LibreOffice_24.2.5.x.x/RPMS
yum localinstall -y *.rpm

二、基本运行配置

1. 无桌面环境运行(服务器常用)

CentOS 服务器通常无 GUI,需要指定用户和 headless 模式:

libreoffice --headless --convert-to pdf example.docx

如报字体或权限问题,建议:

useradd louser
su - louser
libreoffice --headless --convert-to pdf test.docx

2. 字体配置(中文必看)

CentOS 默认缺少中文字体,转换会乱码。

安装中文字体

yum install -y wqy-zenhei-fonts wqy-microhei-fonts

或复制 Windows 字体:

mkdir /usr/share/fonts/windows
cp *.ttf /usr/share/fonts/windows
fc-cache -fv

三、Java 配置(部分功能需要)

yum install -y java-11-openjdk

检查 Java:

libreoffice --headless --version

如需要指定 JVM:

vim ~/.config/libreoffice/4/user/config/javasettings_Linux_X86_64.xml

四、作为服务运行(文档转换服务)

1. 使用 socat + LibreOffice(轻量)

libreoffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;"

2. 使用 systemd 管理

/etc/systemd/system/libreoffice.service

[Unit]
Description=LibreOffice Headless

[Service]
User=louser
ExecStart=/usr/bin/libreoffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;"
Restart=always

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start libreoffice
systemctl enable libreoffice

五、常见问题

1. 报错:no suitable windowing system

yum install -y xorg-x11-server-Xvfb
Xvfb :1 &
export DISPLAY=:1

2. 权限问题

不要用 root 直接运行 LibreOffice。

3. 转换失败

删除用户配置:

rm -rf ~/.config/libreoffice

六、典型用途示例

  • ✅ Word / Excel → PDF
  • ✅ 文档批量转换
  • ✅ Java / Python 调用(jodconverter、unoconv)

如果你能说明:

  • CentOS 版本
  • 是否无桌面
  • 用途(转换 / 开发 / 服务)

我可以给你精确配置方案

0