练习 15:系统启动:运行级别,/etc/init.d,rcconf,update-rc.d
来源:互联网 发布:打车软件盈利模式 编辑:程序博客网 时间:2024/05/23 01:21
首先我会给出一个典型的系统启动过程的概述:
你 按电源开关(或启动虚拟机) 现在计算机获得控制权 控制权传给了 BIOSBIOS 执行硬件特定的任务 执行开机自检(POST),测试你的硬件 检测安装的硬件,如硬盘,内存类型和数量,... 通过将初始值写入其内存来初始化硬件 找到一个启动设备,通常是一个硬盘 读取并执行位于此磁盘开头的 MBR(主引导记录) 控制权现在传给了 MBRMBR MBR 寻找并执行 GRUB(多重操作系统启动管理器) 控制权现在传给了 GRUBGRUB 查找可用的文件系统 查找并读取其配置文件,来了解: 系统位于哪里 启动什么系统 执行什么其他的操作 执行 Linux 内核,Linux 操作系统的主要部分 控制权现在传给了 Linux 内核Linux 内核 查找并加载 initrd,这是初始的 ram 磁盘 initrd 包含必要驱动程序,允许真实文件系统的访问和挂载 挂载文件系统,它在 GRUB 配置文件中指定。 执行`/sbin/init`,一个启动所有其他程序的特殊程序 控制权现在传给了 initinit 查看`etc/inittab`来确定所需的运行级别 加载适合此运行级别的所有程序 加载来自`/etc/rc.d/rc2.d/`的所有程序,因为 2 是默认的 Debian 运行级别 启动 SSH 和 TTY,以便你可以连接到你的计算机 启动现在完成了你 使用 SSH 连接到你的计算机 SSH 守护进程为你执行 bash shell 你现在可以输入东西 你再次获得控制权
现在我们只对“init”和“运行级别”阶段感兴趣,所以我将总结一下,系统如何启动并自动启动一些程序。首先,有一些术语:
- 守护进程 - 一直运行在后台的程序。这意味着它不在乎你是否登录系统,通常你不需要手动启动它,因为它在计算机启动时自动启动。
- 运行级别 - 系统运行模式。基本上,这只是一个数字,提供给
init
程序,它知道哪些守护程序与每个数字相关联,并根据需要启动并停止这些守护程序。
在 Debian 中有以下运行级别:
但是init
怎么知道的?好吧,这是用于它的特殊目录。
user1@vm1:/etc$ find /etc -type d -name 'rc*' 2>/dev/null | sort/etc/rc0.d/etc/rc1.d/etc/rc2.d/etc/rc3.d/etc/rc4.d/etc/rc5.d/etc/rc6.d/etc/rcS.d
你可能能猜到,每个数字和S
对应表中的运行级别。让我们列出其中一个目录,它在正常启动中启动所有所需的守护进程。
user1@vm1:/etc$ ls -al /etc/rc2.d | awk '{printf "%-15.15s %-3.3s %s\n",$9,$10,$11}'...READMES14portmap -> ../init.d/portmapS15nfs-common -> ../init.d/nfs-commonS17rsyslog -> ../init.d/rsyslogS17sudo -> ../init.d/sudoS18acpid -> ../init.d/acpidS18atd -> ../init.d/atdS18cron -> ../init.d/cronS18exim4 -> ../init.d/exim4S18ssh -> ../init.d/sshS20bootlogs -> ../init.d/bootlogsS21rc.local -> ../init.d/rc.localS21rmnologin -> ../init.d/rmnologinS21stop-bootlog -> ../init.d/stop-bootlogd
如你所见,此目录中的文件只是实际启动脚本的符号链接。我们来看看其中一个链接:S18ssh→../init.d/ssh
。这是关于这个文件的事情:
- 它是一个
./init.d/ssh
文件的链接 - 它以
S
开始,意味着“启动”。Debian 启动系统中使用的每个脚本至少有 2 个参数,“启动”和“停止”。现在我们可以说,当我们的系统切换到运行级别 2 时,该脚本将使用动作“启动”来执行 。 - 它有一个数字 18。
rc
目录中的脚本以字典序执行,所以现在我们明白,在启动ssh
之前 ,系统启动portmap
,nfs-common
,rsyslog
和sudo
。rsyslog
是一个系统日志守护程序,特别是ssh
想要记录谁在什么时候访问系统,所以在启动之前需要运行rsyslog
。
现在,你将学习如何列出启用的服务(守护程序),以及启用和禁用服务(守护程序)。
这样做
1: sudo aptitude install rcconf 2: ls -al /etc/rc2.d 3: sudo rcconf --list 4: sudo update-rc.d exim4 disable 5: ls -al /etc/rc2.d 6: sudo rcconf --list 7: sudo update-rc.d exim4 enable 8: ls -al /etc/rc2.d 9: sudo rcconf --list
你会看到什么
user1@vm1:/var/log$ sudo aptitude install rcconfThe following NEW packages will be installed: rcconf0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.Need to get 0 B/23.9 kB of archives. After unpacking 135 kB will be used.Selecting previously deselected package rcconf.(Reading database ... 24239 files and directories currently installed.)Unpacking rcconf (from .../archives/rcconf_2.5_all.deb) ...Processing triggers for man-db ...Setting up rcconf (2.5) ...user1@vm1:/etc$ ls -al /etc/rc2.dtotal 12drwxr-xr-x 2 root root 4096 Jun 27 11:42 .drwxr-xr-x 68 root root 4096 Jun 25 18:43 ..-rw-r--r-- 1 root root 677 Mar 27 05:50 READMElrwxrwxrwx 1 root root 17 Jun 4 11:53 S14portmap -> ../init.d/portmaplrwxrwxrwx 1 root root 20 Jun 4 11:53 S15nfs-common -> ../init.d/nfs-commonlrwxrwxrwx 1 root root 17 Jun 4 11:53 S17rsyslog -> ../init.d/rsysloglrwxrwxrwx 1 root root 14 Jun 15 19:02 S17sudo -> ../init.d/sudolrwxrwxrwx 1 root root 15 Jun 4 11:53 S18acpid -> ../init.d/acpidlrwxrwxrwx 1 root root 13 Jun 4 11:53 S18atd -> ../init.d/atdlrwxrwxrwx 1 root root 14 Jun 4 11:53 S18cron -> ../init.d/cronlrwxrwxrwx 1 root root 15 Jun 27 11:42 S18exim4 -> ../init.d/exim4lrwxrwxrwx 1 root root 13 Jun 4 11:53 S18ssh -> ../init.d/sshlrwxrwxrwx 1 root root 18 Jun 4 11:53 S20bootlogs -> ../init.d/bootlogslrwxrwxrwx 1 root root 18 Jun 4 11:53 S21rc.local -> ../init.d/rc.locallrwxrwxrwx 1 root root 19 Jun 4 11:53 S21rmnologin -> ../init.d/rmnologinlrwxrwxrwx 1 root root 23 Jun 4 11:53 S21stop-bootlogd -> ../init.d/stop-bootlogduser1@vm1:/etc$ sudo rcconf --listrsyslog onssh onbootlogs onportmap onsudo onnfs-common onudev onconsole-setup onkbd onexim4 onkeyboard-setup onacpid oncron onatd onprocps onmodule-init-tools onuser1@vm1:/etc$ sudo update-rc.d exim4 disableupdate-rc.d: using dependency based boot sequencinginsserv: warning: current start runlevel(s) (empty) of script `exim4' overwrites defaults (2 3 4 5).insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `exim4' overwrites defaults (0 1 6).user1@vm1:/etc$ ls -al /etc/rc2.dtotal 12drwxr-xr-x 2 root root 4096 Jun 27 11:43 .drwxr-xr-x 68 root root 4096 Jun 25 18:43 ..lrwxrwxrwx 1 root root 15 Jun 27 11:43 K01exim4 -> ../init.d/exim4-rw-r--r-- 1 root root 677 Mar 27 05:50 READMElrwxrwxrwx 1 root root 17 Jun 4 11:53 S14portmap -> ../init.d/portmaplrwxrwxrwx 1 root root 20 Jun 4 11:53 S15nfs-common -> ../init.d/nfs-commonlrwxrwxrwx 1 root root 17 Jun 4 11:53 S17rsyslog -> ../init.d/rsysloglrwxrwxrwx 1 root root 14 Jun 15 19:02 S17sudo -> ../init.d/sudolrwxrwxrwx 1 root root 15 Jun 4 11:53 S18acpid -> ../init.d/acpidlrwxrwxrwx 1 root root 13 Jun 4 11:53 S18atd -> ../init.d/atdlrwxrwxrwx 1 root root 14 Jun 4 11:53 S18cron -> ../init.d/cronlrwxrwxrwx 1 root root 13 Jun 4 11:53 S18ssh -> ../init.d/sshlrwxrwxrwx 1 root root 18 Jun 4 11:53 S20bootlogs -> ../init.d/bootlogslrwxrwxrwx 1 root root 18 Jun 4 11:53 S21rc.local -> ../init.d/rc.locallrwxrwxrwx 1 root root 19 Jun 4 11:53 S21rmnologin -> ../init.d/rmnologinlrwxrwxrwx 1 root root 23 Jun 4 11:53 S21stop-bootlogd -> ../init.d/stop-bootlogduser1@vm1:/etc$ sudo rcconf --listrsyslog onssh onbootlogs onportmap onsudo onnfs-common onudev onconsole-setup onkbd onkeyboard-setup onacpid oncron onatd onprocps onmodule-init-tools onexim4 offuser1@vm1:/etc$ sudo update-rc.d exim4 enableupdate-rc.d: using dependency based boot sequencinguser1@vm1:/etc$ ls -al /etc/rc2.dtotal 12drwxr-xr-x 2 root root 4096 Jun 27 11:43 .drwxr-xr-x 68 root root 4096 Jun 25 18:43 ..-rw-r--r-- 1 root root 677 Mar 27 05:50 READMElrwxrwxrwx 1 root root 17 Jun 4 11:53 S14portmap -> ../init.d/portmaplrwxrwxrwx 1 root root 20 Jun 4 11:53 S15nfs-common -> ../init.d/nfs-commonlrwxrwxrwx 1 root root 17 Jun 4 11:53 S17rsyslog -> ../init.d/rsysloglrwxrwxrwx 1 root root 14 Jun 15 19:02 S17sudo -> ../init.d/sudolrwxrwxrwx 1 root root 15 Jun 4 11:53 S18acpid -> ../init.d/acpidlrwxrwxrwx 1 root root 13 Jun 4 11:53 S18atd -> ../init.d/atdlrwxrwxrwx 1 root root 14 Jun 4 11:53 S18cron -> ../init.d/cronlrwxrwxrwx 1 root root 15 Jun 27 11:43 S18exim4 -> ../init.d/exim4lrwxrwxrwx 1 root root 13 Jun 4 11:53 S18ssh -> ../init.d/sshlrwxrwxrwx 1 root root 18 Jun 4 11:53 S20bootlogs -> ../init.d/bootlogslrwxrwxrwx 1 root root 18 Jun 4 11:53 S21rc.local -> ../init.d/rc.locallrwxrwxrwx 1 root root 19 Jun 4 11:53 S21rmnologin -> ../init.d/rmnologinlrwxrwxrwx 1 root root 23 Jun 4 11:53 S21stop-bootlogd -> ../init.d/stop-bootlogduser1@vm1:/etc$ sudo rcconf --listrsyslog onssh onbootlogs onportmap onsudo onnfs-common onudev onconsole-setup onkbd onexim4 onkeyboard-setup onacpid oncron onatd onprocps onmodule-init-tools onuser1@vm1:/etc$
解释
- 安装
rcconf
包,让你轻松管理运行级别。 - 打印包含运行级别 2 的启动脚本的目录。现在启用了邮件服务器
exim4
。 - 仅仅打印出相同运行级别的服务。请注意,由于它们被视为系统服务,因此存在多个未显示的服务。
rcconf –list –expert
会把它们全部列出,以及更多的驻留在不同的运行级别上的服务。 - 禁用邮件服务器
exim4
的自动启动。 - 打印出包括运行级别 2 的启动脚本的目录。
exim4
启动脚本现在从S18exim4
重命名为K01exim4
。这意味着exim4
进入此级别时已停止(被杀死)。如果exim4
开始没有运行,就没有任何反应。 - 打印运行级别 2 的服务。服务
exim4
现在已关闭。 - 开启
exim4
的自动启动。 - 再次打印包含运行级别 2 的启动脚本的目录,
exim4
再次启动。 - 打印运行级别 2 的服务。
exim4
的状态变更为已启动,和预期一样。
阅读全文
0 0
- 练习 15:系统启动:运行级别,/etc/init.d,rcconf,update-rc.d
- linxu系统引导&运行级别&chkconfig&/etc/rc/init.d&/etc/rc/rc*.d
- /etc/rc.d/init.d内容分析
- /etc/rc.d/init.d/leds
- linux /etc/init.d/ rc*.d 详解
- /etc/rc.d/init.d/ssh
- /etc/rc.local 与 /etc/init.d
- Debian系统启动脚本详解-update-rc.d
- /etc/rc.d/rc与/etc/rc.d/init.d的关系介绍
- 理解Linux系统/etc/init.d目录和/etc/rc.local脚本(开机运行)
- /etc/rc.d/与/etc/rc.d/init.d的关系 (转)
- /etc/rc.d/init.d 和 /etc/rc.d目录介绍
- /etc/rc.d/init.d和/etc/init.d 联系区别
- /etc/rc.d/init.d和/etc/init.d 联系区别
- /etc/rc.d/init.d和/etc/init.d 联系区别
- /etc/init.d和/etc/rc.d/init.d的关系
- /etc/rc.d/init.d和/etc/init.d 联系区别
- /etc/rc.d/init.d和/etc/init.d 联系区别
- 二维码生成
- 【面向JS--变量和常量】
- 如何修改在Screen Pinning Test中长按“返回”按钮取消固定屏幕?
- weex run android时报错:Environment variable $ANDROID_HOME not found !
- 死锁
- 练习 15:系统启动:运行级别,/etc/init.d,rcconf,update-rc.d
- ABAP开发Smartform实例
- 安裝 Installation of Torch7, Cuda, Cudnn, Nvidia Driver with GTX1070
- 在线压缩图片
- HTML--表单
- 网狐荣耀版棋牌教程之一开发环境搭建
- 内核新的ioctl方式---- unlocked_ioctl和compat_ioctl
- 1、跨平台开发——分类
- 你不得不看的北京Python培训班排名