温馨提示×

centos cmatrix如何设开机启

小樊
32
2026-08-04 03:15:44
栏目: 智能运维

CentOS 上让 cmatrix(字符矩阵屏保效果)开机自动启动,常见有几种方式,取决于你是 开机后自动登录并运行,还是 系统启动阶段就跑起来。下面给你几种常用且可行的方案。


一、前提:确认 cmatrix 已安装

which cmatrix

如果没有:

yum install -y epel-release
yum install -y cmatrix

二、方案一:开机后自动运行(推荐 ✅)

适用于 服务器 + 自动登录终端(tty)

1️⃣ 设置 tty 自动登录(root 为例)

编辑 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

2️⃣ 登录后自动运行 cmatrix

编辑 root 用户:

vi ~/.bash_profile

在末尾添加:

if [ "$(tty)" = "/dev/tty1" ]; then
    cmatrix -b
fi

✅ 效果:

  • 开机 → 自动登录 tty1 → 自动运行 cmatrix

三、方案二:使用 systemd 服务(不推荐用于图形)

适合 无登录 shell 场景

1️⃣ 创建 service 文件

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

2️⃣ 启用并启动

systemctl daemon-reload
systemctl enable cmatrix
systemctl start cmatrix

⚠️ 注意:

  • 可能和 getty 冲突
  • 更适合嵌入式 / 展示机

四、方案三:图形界面(GNOME / KDE)

如果你用的是 CentOS 桌面版

GNOME

gnome-session-properties

添加:

名称:cmatrix
命令:gnome-terminal -e "cmatrix -b"

五、常用 cmatrix 参数

cmatrix -b      # 加粗字符
cmatrix -C cyan # 青色
cmatrix -u 2    # 更新速度

六、推荐组合 ✅

场景 推荐
服务器 / 展示机 ✅ tty 自动登录 + bash_profile
桌面系统 ✅ 启动项
纯 systemd ⚠️ 有坑

如果你愿意,可以告诉我:

  • ✅ CentOS 7 / 8 / Stream?
  • ✅ 是否有图形界面?
  • ✅ 是否 root 用户?

我可以给你 完全定制的一套配置

0