温馨提示×

如何让compton在centos上运行

小樊
36
2025-12-29 11:21:29
栏目: 智能运维

在 CentOS 上运行 Compton 的完整步骤

一 环境准备与安装

  • 确认会话类型:Compton 是 X11 的窗口合成器,在 Wayland 会话下不会生效。请先登录到 GNOME on Xorg / Xfce / i3 等 X11 会话
  • 启用 EPEL 并更新系统(CentOS 7/8 均适用):
    sudo yum install -y epel-release
    sudo yum update -y # 或使用 dnf:sudo dnf update -y
  • 安装 Compton:
    sudo yum install -y compton # CentOS 8+/Stream 也可用:sudo dnf install -y compton
  • 若仓库无包或需要新特性,可从源码编译(需提前安装 git、cmake、gcc、make 及 X11/OpenGL 开发库):
    git clone https://github.com/Compton/Compton.git
    cd Compton && mkdir build && cd build
    cmake … && make -j$(nproc)
    sudo make install
    注:源码安装的可执行文件通常在 /usr/local/bin/compton

二 快速测试与最小配置

  • 生成基础配置并启动测试:
    mkdir -p ~/.config
    cat > ~/.config/compton.conf <<‘EOF’ backend = “glx”; shadow = true; shadow-radius = 10; shadow-offset-x = 5; shadow-offset-y = 5; shadow-color = “#00000080”; shadow-exclude = [ “class_g = ‘GtkDialog’”, “class_g = ‘KDialog’”, “window_type = ‘dock’”, “window_type = ‘desktop’” ]; opacity = 0.9; inactive-opacity = 0.8; active-opacity = 1.0; vsync = true; EOF

  • 前台试运行(便于观察报错):
    compton --config ~/.config/compton.conf
    若无报错且窗口阴影/透明度生效,即可进入下一步。

三 设置开机自启动

  • 推荐方式一(登录会话自动启动,用户级):在桌面会话的“启动应用程序”里新增命令:
    compton --config ~/.config/compton.conf
  • 推荐方式二(systemd 用户服务,更稳定):
    1. 创建服务文件:
      sudo tee /etc/systemd/system/compton.service >/dev/null <<‘EOF’ [Unit] Description=Compton Window Composer After=display-manager.service

[Service] Type=simple ExecStart=/usr/bin/compton --config /home/你的用户名/.config/compton.conf Restart=on-failure User=你的用户名

[Install] WantedBy=multi-user.target EOF 2) 启用并启动:
sudo systemctl daemon-reload
sudo systemctl enable --now compton.service
3) 查看状态与日志:
systemctl status compton.service
journalctl -u compton.service -b
提示:若你使用源码安装到 /usr/local/bin/compton,请将 ExecStart 改为 /usr/local/bin/compton

四 常见问题与排查

  • 会话与兼容性:确保在 Xorg 会话;若在 Wayland 上,请切换到 GNOME on Xorg 或使用支持 Wayland 的合成器。
  • 显卡驱动与 OpenGL:安装并更新 Intel/AMD/NVIDIA 驱动;运行 lspci -k | grep -A3 VGA 检查驱动加载情况;性能差时可临时改用 backend = “xrender” 或关闭阴影。
  • 与其他合成器冲突:若桌面自带合成(如某些环境),请先关闭以避免冲突。
  • 快速验证:
    ps -e | grep compton(是否运行)
    compton --config ~/.config/compton.conf(前台运行看错误输出)
    journalctl -u compton.service(查看服务日志)

0