温馨提示×

centos怎么让cmatrix开机启动

小樊
37
2026-09-15 04:22:56
栏目: 智能运维

在 CentOS 上让 cmatrix 开机自动启动,常见有几种方式,取决于你用的是 CentOS 6(init) 还是 CentOS 7/8(systemd),以及你是想开机进图形界面自动跑还是终端自动跑

下面按常见场景给你说明。


一、CentOS 7 / 8(systemd,推荐)

方式 1:作为系统服务开机运行(适合服务器)

如果你希望开机后 在某个 tty 上自动运行 cmatrix

1. 创建 systemd 服务

vi /etc/systemd/system/cmatrix.service

内容示例(在 tty2 上运行):

[Unit]
Description=cmatrix autostart
After=getty.target

[Service]
Type=simple
ExecStart=/usr/bin/cmatrix
StandardInput=tty
TTYPath=/dev/tty2
Restart=always

[Install]
WantedBy=multi-user.target

2. 重载并启用

systemctl daemon-reload
systemctl enable cmatrix
systemctl start cmatrix

开机后按 Ctrl+Alt+F2 就能看到 cmatrix。


方式 2:用户登录后自动运行(推荐个人使用)

如果你是自己登录系统后才想看 cmatrix:

vi ~/.bash_profile

加入:

if [ "$TERM" = "linux" ]; then
    cmatrix
fi

或简单点:

echo "cmatrix" >> ~/.bash_profile

⚠ 注意:这会在每次登录终端时运行,不适合 root 生产环境。


二、CentOS 6(init.d)

vi /etc/init.d/cmatrix
#!/bin/bash
# chkconfig: 2345 90 10
# description: cmatrix autostart

case "$1" in
start)
    /usr/bin/cmatrix &
    ;;
*)
    echo "Usage: $0 start"
    exit 1
esac
chmod +x /etc/init.d/cmatrix
chkconfig cmatrix on

三、图形界面(GNOME)开机启动

如果你是 桌面版 CentOS

  1. 打开终端
  2. 设置 → 开机启动程序
  3. 添加命令:cmatrix

或:

cp /usr/share/applications/cmatrix.desktop ~/.config/autostart/

四、常见问题

  • cmatrix: command not found
    先安装:
    yum install cmatrix -y
    
  • ❌ 虚拟机看不到效果
    确保在 物理 tty本地终端,不是 SSH

如果你告诉我:

  • CentOS 版本
  • 是否是桌面版
  • 是否用于 root 服务器

我可以给你最合适的一条命令方案

0