在 CentOS 上让 cmatrix(字符矩阵屏保效果)开机自动启动,常见有几种方式,取决于你是 开机后自动登录并运行,还是 系统启动阶段就跑起来。下面给你几种常用且可行的方案。
which cmatrix
如果没有:
yum install -y epel-release
yum install -y cmatrix
适用于 服务器 + 自动登录终端(tty)
编辑 systemd 配置:
mkdir -p /etc/systemd/system/getty@tty1.service.d
vi /etc/systemd/system/getty@tty1.service.d/autologin.conf
内容如下:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
重载并重启:
systemctl daemon-reload
reboot
编辑 root 用户:
vi ~/.bash_profile
在末尾添加:
if [ "$(tty)" = "/dev/tty1" ]; then
cmatrix -b
fi
✅ 效果:
适合 无登录 shell 场景
vi /etc/systemd/system/cmatrix.service
内容:
[Unit]
Description=cmatrix on tty1
After=getty.target
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix -b
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1
Restart=always
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable cmatrix
systemctl start cmatrix
⚠️ 注意:
如果你用的是 CentOS 桌面版:
gnome-session-properties
添加:
名称:cmatrix
命令:gnome-terminal -e "cmatrix -b"
cmatrix -b # 加粗字符
cmatrix -C cyan # 青色
cmatrix -u 2 # 更新速度
| 场景 | 推荐 |
|---|---|
| 服务器 / 展示机 | ✅ tty 自动登录 + bash_profile |
| 桌面系统 | ✅ 启动项 |
| 纯 systemd | ⚠️ 有坑 |
如果你愿意,可以告诉我:
我可以给你 完全定制的一套配置。