温馨提示×

centos如何开机自启cmatrix

小樊
46
2026-09-27 04:42:55
栏目: 智能运维

在 CentOS 中让 cmatrix 开机自启,常见有几种方式,取决于你使用的是 CentOS 6(init) 还是 CentOS 7/8(systemd)。下面分别说明。


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

1. 确认 cmatrix 已安装

which cmatrix

如果没有:

yum install cmatrix -y

2. 创建 systemd 服务(用于终端开机运行)

⚠️ 注意:cmatrix 是终端程序,不能在无登录环境下直接显示,通常需要 getty 或 tty 登录后运行。

示例:在 tty1 开机自动运行 cmatrix

创建服务文件:

vim /etc/systemd/system/cmatrix.service

内容如下:

[Unit]
Description=CMatrix on tty1
After=getty.target

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

[Install]
WantedBy=multi-user.target

3. 启用开机自启

systemctl daemon-reload
systemctl enable cmatrix.service

重启后,在 tty1(Ctrl+Alt+F1) 会自动运行 cmatrix。


二、CentOS 6(init.d)

1. 创建启动脚本

vim /etc/init.d/cmatrix

内容:

#!/bin/bash
# chkconfig: 2345 99 01
# description: cmatrix autostart

case "$1" in
start)
    /usr/bin/cmatrix &
    ;;
stop)
    pkill cmatrix
    ;;
*)
    echo "Usage: $0 {start|stop}"
    exit 1
    ;;
esac
exit 0

2. 添加执行权限并开机自启

chmod +x /etc/init.d/cmatrix
chkconfig cmatrix on

三、仅当前用户登录后自动运行(最简单)

如果你只是想 登录后自动跑 cmatrix(不严格算“开机”):

echo "cmatrix" >> ~/.bashrc

或

echo "cmatrix" >> ~/.profile

四、常见问题说明

  • ❌ cmatrix 不能在纯后台服务中显示图形
  • ✅ 必须在 tty / 终端 中运行
  • ✅ systemd 方式最接近“开机自启”

如果你能告诉我:

  • CentOS 版本
  • 是否服务器(无桌面)/ 有桌面
  • 是否想全屏开机就显示 cmatrix

我可以给你更精确的方案。

0 踩