[步骤] Linux 开机自启 (通过 chkconfig 实现)

案例一:添加一个受 chkconfig 管理的服务(脚本)

1.1 编写一个脚本

# vim /etc/init.d/start.sh

创建以下内容:

#!/bin/bash
systemctl start httpd

# chkconfig: 345 85 15
# description: This is a script of starting httpd

(补充:chkconfig:后面的 3 个含义为 httpd 的级别为 3、4 和 5,启动序号为 85,关闭序号为 15)

1.2 给脚本添加执行权限

# chmod +x /etc/init.d/start.sh

1.3 将脚本添加到 chkconfig 中

# chkconfig --add start.sh

1.4 显示刚刚添加到 chkconfig 的应用

# chkconfig --list

案例二:通过 chkconfig 管理一个服务或脚本

2.1 设定 start.sh 在 3 和 5 等级为 on

# chkconfig --level 35 start.sh on

2.2 设定 start.sh 在各等级为 on,“各等级”包括 2、3、4、5 等级

# chkconfig start.sh on

2.3 设定 start.sh 在各等级为 off,“各等级”包括 2、3、4、5 等级

# chkconfig start.sh off

[内容] Linux 运行级别的设置 (切换命令行模式和图形界面模式)

内容一:显示运行级别

1.1 显示正在使用的运行级别

# who -r

1.2 显示系统重启后会进入的运行级别

# systemctl get-default

内容二:设置运行级别的命令格式

2.1 命令行设置运行级别的命令格式

# systemctl <command> <unit.target>

2.2 设置运行级别命令的参数

2.2.1 command 参数选项

1) get-default 显示默认运行的 target(重启后默认进入的运行级别)
2) set-default 设置指定的 target 为默认的运行级别(重启后默认进入的运行级别)
3 isolate 切换到指定的运行级别(立刻切换到指定的运行级别)

2.2.2 unit.target 参数选项

1) multi-user.target 普通的命令行模式
2) graphical.target 图形界面模式

内容四:快捷键设置运行级别的方法

1) 同时按下 “ctrl” 键和 “f2” 键,将当前屏幕切换到图形界面
2) 同时按下 “ctrl” 键和 “f3” 键,将当前屏幕切换到第一个命令行界面
3) 同时按下 “ctrl” 键和 “f4” 键,将当前屏幕切换到第二个命令行界面
4) 同时按下 “ctrl” 键和 “f5” 键,将当前屏幕切换到第三个命令行界面
5) 同时按下 “ctrl” 键和 “f6” 键,将当前屏幕切换到第四个命令行界面

内容五:设置运行级别的案例

5.1 显示默认运行的 target(系统重启后会默认进入的运行级别)

# systemctl get-default

5.2 设置默认运行级别为普通的命令行模式

# systemctl set-default multi-user.target 

5.3 在不重启情况下,立刻切换到普通的命令行模式

# systemctl isolate multi-user.target

5.4 在不重启情况下,立刻切换到普通的命令行模式

# init 3

5.5 在不重启的情况下,立刻切换到图形界面模式

# systemctl isolate graphical.target

5.6 在不重启的情况下,立刻切换到图形界面模式

# init 5

[步骤] openSUSE & SLE 开机自启

内容一:openSUSE & SLE 开机设置文档介绍

1) /etc/init.d/boot.local
2) /etc/init.d/halt.local
3) /etc/init.d/before.local
4) /etc/init.d/after.local


补充:
1) 其中的 boot.local 是在刚开机时,在所有其他的程序执行前执行的文件
2) 其中的 after.local 是在刚开机后,在所有其他的程序执行后执行的文件

(注意:上面第三和第四个档案默认是不存在的,可以自己创建一个, 就像写个 shell 一样很简单)

内容二:设置 openSUSE & SLE 开机自启命令的案例

2.1 创建 after.local 文件

# vim /etc/init.d/after.local

创建以下内容:

sudo systemctl restart httpd

(补充:这里以开机自启 httpd 程序为例)

2.2 给 after.local 文件执行权限

# chmod u+x /etc/init.d/after.local

[内容] 软件源的设置 (openSUSE 版) (非官方版)

步骤一:禁用所有原有的软件源

# zypper mr -da

步骤二:添加阿里的 openSUSE 软件源

# sudo zypper ar -fc https://mirrors.aliyun.com/opensuse/distribution/leap/15.0/repo/oss openSUSE-Aliyun-OSS
# sudo zypper ar -fc https://mirrors.aliyun.com/opensuse/distribution/leap/15.0/repo/non-oss openSUSE-Aliyun-NON-OSS
# sudo zypper ar -fc https://mirrors.aliyun.com/opensuse/update/leap/15.0/oss openSUSE-Aliyun-UPDATE-OSS
# sudo zypper ar -fc https://mirrors.aliyun.com/opensuse/update/leap/15.0/non-oss openSUSE-Aliyun-UPDATE-NON-OSS


补充:
1) 命令中最后一个参数为每这个源指定了一个别称
2) 这里以添加 openSUSE 15.0 版本的 oss、non-oss、update 和 update-now-oss 库为例

步骤三:刷新所有处于 enable 状态的软件源

# zypper ref

[步骤] Linux 图形桌面的安装 (GNOME 版) (Rocky Linux & RHEL & Fedora 版)

步骤一:系统环境要求

服务器系统要配置好可用的软件源

步骤二:显示 Rocky Linux & RHEL & Fedora 可安装的软件包组

# yum grouplist

或者:

# dnf group list

步骤三:安装图形桌面

如果是 Rocky Linux & RHEL:

# yum groupinstall "Server with GUI"

或者:

# dnf group install -y "Server with GUI"

如果是 Fedora:

# dnf install @gnome

或者:

# yum groupinstall "GNOME"

或者:

# dnf group install -y "GNOME"

步骤四:设置开机启动图形桌面

# systemctl set-default graphical.target

步骤五:进入图形桌面

# startx

或者:

# init 5