温馨提示×

怎样让centos开机自启cmatrix

小樊
42
2026-09-18 04:31:21
栏目: 智能运维

在 CentOS 上让 cmatrix 开机自动运行,一般有几种方式,取决于你是在图形界面登录后运行,还是开机直接进入字符终端运行。下面按常见场景说明。


一、字符界面(TTY)开机自动运行 cmatrix(推荐)

方法 1:使用 systemd 开机启动(最规范)

1. 确保已安装 cmatrix

which cmatrix
# 如果没有
yum install -y cmatrix

2. 创建 systemd 服务

vi /etc/systemd/system/cmatrix.service

内容如下(getty 终端方式):

[Unit]
Description=CMatrix on TTY1
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/cmatrix -b
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1
Restart=always

[Install]
WantedBy=multi-user.target

3. 启用服务

systemctl daemon-reload
systemctl enable cmatrix.service

重启后,tty1 会自动运行 cmatrix

⚠ 注意:这会让 tty1 被 cmatrix 占用,可用 Ctrl+Alt+F2 切换其他终端


二、登录后自动运行(当前用户)

如果你只是想 登录后自动显示 cmatrix

方法 2:写入 shell 配置文件

echo "cmatrix -b" >> ~/.bashrc

或只对 root:

echo "cmatrix -b" >> /root/.bashrc

登录即运行(但退出就结束)。


三、图形界面(GUI)开机自启

如果你是 GNOME / KDE 桌面

方法 3:添加启动程序

vi ~/.config/autostart/cmatrix.desktop

内容:

[Desktop Entry]
Type=Application
Name=CMatrix
Exec=/usr/bin/cmatrix -b
Terminal=true

保存后,下次登录桌面自动运行。


四、常见问题

cmatrix 退出后无限重启?

在 systemd 中:

Restart=no

只在一个终端运行?

TTYPath=/dev/tty2


推荐方案总结

场景 推荐方式
服务器无桌面 systemd + tty
登录即用 .bashrc
桌面环境 autostart

如果你告诉我 CentOS 版本(6/7/8/9)是否有图形界面,我可以给你更精确配置。

0