admin 管理员组

文章数量: 1184232

0x00 启动项

1、关于目录/etc/init.d/

目录 /etc/init.d/ 中包含了许多系统服务的启动和停止脚本。

该目录下 存放实际的服务脚本文件

使用 /etc/init.d/ 目录下的脚本,需要root权限

你可以使用以下命令来运行脚本

/etc/init.d/command 选项
#选项参数↓
start           #启动
stop            #停止
reload          #加载
restart         #重启
force-reload    #强制加载

而大多数情况下 都是使用 start | stop | restart 这三个参数

实际上 /etc/init.d/ 是软链接,实际链接到 /etc/rc.d/init.d/

你可以通过以下命令验证

[root@localhost /]# ll /etc/init.d
lrwxrwxrwx. 1 root root 11 Feb 22 20:34 /etc/init.d -> rc.d/init.d

[root@localhost /]# ls -ld /etc/init.d
lrwxrwxrwx. 1 root root 11 Feb 22 20:34 /etc/init.d -> rc.d/init.d

建立方法

[root@localhost /]# ln -s /etc/rc.d/init.d /etc/init.d

2、关于目录 /etc/rc.d/

Linux 的每个运行级别,在 /etc/rc.d/ 下都有一个子目录分别是rc0.d,rc1.d ...... rc6.d

而这些子目录下存放的都是链接到 /etc/rc.d/init.d/ 目录下部分脚本链接文件

/etc/rc.d/rc2.d/S10network 有些什么意义?↓

  • /etc/rc.d/rc2.d/ :这是存放运行级别2的初始化脚本和服务的目录路径。在不同的Linux发行版中,此路径可能会略有不同。

  • S10network :这是文件的名称。它由三个部分组成:一个字符( S K )、两个数字和一个描述性的名称。

    • 第一个字符表示脚本的类型。在这种情况下, S 表示启动脚本(start), K 表示停止脚本(kill)。

    • 两个数字表示脚本的执行顺序。数字越小,脚本越早执行。在这里, 10 表示此脚本在同一目录中的其他脚本之前执行。

    • network 是一个描述性的名称,表示此脚本与网络相关。

3、关于文件 /etc/rc.local

/etc/rc.local 是一个在Linux系统启动时自动执行的脚本文件。它通常用于在系统启动过程中执行一些自定义的命令或脚本。

当系统引导到特定运行级别时, /etc/rc.local 会被执行。它位于 /etc 目录下,通常是一个普通文本文件,可以使用文本编辑器进行编辑。

/etc/rc.local 是软链接于 /etc/rc.d/rc.local

/etc/rc.local 文件中,您可以添加任意的命令或脚本,这些命令和脚本会在系统启动时按顺序执行。您可以在其中执行各种自定义操作,例如启动特定的服务、设置环境变量、挂载文件系统等。

rc.local 文件长下面这样

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
/usr/local/phpstudy/system/phpstudyctl -start #小皮启动项

4、关于 /etc/init.d/ 与 /etc/systemd/system/

service 文件是使用 systemd 作为初始化程序的 Linux 系统才有的服务文件,叫“服务配置单元文件”,用来取代旧初始化系统中的脚本文件,但是他们可能会同时存在系统中

如果同时存在的话,在目录 /etc/init.d/ 下的脚本文件的优先级会高于目录 /etc/systemd/system/ 下的 service 文件

5、 关于service命令

service 命令的封装实际上是对底层的服务管理工具(如 systemctl service init.d 脚本等)的简化和统一接口

格式: service xxx start|stop|restart

6、关于init配置文件 /etc/inittab

这是 init 程序的配置文件,系统的运行级别就是在 /etc/inittab 文件里指定,所谓“运行级”就是操作系统当前正在运行的功能级别。这个级别从1 到6 ,具有不同的功能。

7、关于旧版本的init配置目录 /etc/init/

在一些旧版本的Ubuntu操作系统中, /etc/init/ 目录是用来存放Upstart(一种早期的初始化系统)的配置文件的位置。Upstart是一种替代传统SysV初始化系统的方式,它通过配置文件来管理系统的启动和服务。

8、如何把脚本文件添加到启动项中去

等更新。。。

本文标签: 系统启动 系统 关于