首先确保系统已更新,然后安装Compton。根据CentOS版本选择包管理器:
yum;dnf(若未安装EPEL仓库,需先运行sudo yum install epel-release -y)。sudo yum update -y && sudo yum install compton -y # CentOS 7
sudo dnf update -y && sudo dnf install compton -y # CentOS 8+
Compton的配置文件路径分为系统级(影响所有用户)和用户级(仅影响当前用户),优先使用用户级配置:
~/.config/compton.conf(若不存在则创建);/etc/compton.conf(需root权限编辑)。创建/编辑配置文件(以用户级为例):
mkdir -p ~/.config && touch ~/.config/compton.conf # 创建目录及文件
nano ~/.config/compton.conf # 使用nano编辑(或vim、gedit等)
常用配置选项(根据需求调整):
# 后端设置(推荐glx或wayland,提升性能)
backend = "glx";
# 阴影设置(排除Firefox等应用窗口)
shadow = true;
shadow-exclude = [".*", "class='Firefox'", "title='Firefox'"];
# 透明度设置(禁用可提升性能)
opacity = 0.9;
unredirect-if-transparent = true;
# 垂直同步(避免屏幕撕裂)
vsync = true;
# 帧率限制(减少CPU占用)
frame-rate = 60;
# GPU加速(启用可提升性能)
glx-no-stencil = true;
glx-copy-from-front = false;
配置完成后,通过以下命令启动Compton并指定配置文件:
compton -c ~/.config/compton.conf &
(&表示后台运行,避免占用终端)
若需要Compton随系统启动,需创建systemd服务文件:
sudo nano /etc/systemd/system/compton.service
添加以下内容(替换your-username为实际用户名):
[Unit]
Description=Compton Window Compositor
After=display-manager.service
[Service]
ExecStart=/usr/bin/compton -c /home/your-username/.config/compton.conf
Restart=always
User=your-username
[Install]
WantedBy=multi-user.target
启用并启动服务:
sudo systemctl daemon-reload # 重新加载systemd配置
sudo systemctl enable compton.service # 设置开机自启动
sudo systemctl start compton.service # 立即启动服务
sudo systemctl status compton.service
若显示“active (running)”,则表示服务正常运行。journalctl -u compton.service -e # 查看最新日志
若配置出现问题,日志会提示具体错误信息(如后端不支持、权限不足等)。shadow(阴影)、opacity(透明度)等特效,或降低frame-rate(帧率)。glx后端需要),否则可能出现黑屏、闪烁等问题。cp ~/.config/compton.conf ~/.config/compton.conf.bak),便于恢复。