≡菜单

如何使用Startpar命令示例加速Linux引导过程

In a typical scenario, during the boot process, the run-level system 开始up scripts are executed 上 e-by-one.

A particular run level 开始up script will not execute until the previous script is executed completely. If a particular service during the 开始up is hanging for some reason, it might take a while before it times-out and move 上 to the next 开始up script.

Startpar实用程序用于并行运行多个运行级脚本。这有助于加快服务器的引导过程。

Startpar实用程序是sysvinit软件包的一部分。

The general syntax for the 开始par is given below:

开始par –p par –i iorate –t timeout –T global timeout –a arg prg1 prg2

startpar –p par –I iorate –t timeout –T global timeout –M boot|start|stop

The following are the various options of 开始par:

  • -p要并行运行的进程数。
  • -i更改过程块的权重系数。默认值为800。
  • -t如果未发生输出,则清空脚本缓冲区的超时。
  • -T全球超时。它用于刷新以前脚本的缓冲区输出。
  • -a要提供给所有脚本的参数。
  • -M Switch 开始par to the “make” mode.
  • -P指定先前的运行级别
  • -N指定下一个运行级别

When 开始par is executing the run-level scripts, the output of the scripts is buffered to allow for controlled writing to logging facilities.

如果其他脚本正在并行运行,则它将等待日志记录完成,然后将数据从缓冲区写入日志记录区域。 –t和–T选项用于控制自从最后一个输出被捕获到缓冲区以来的时间来清除这些缓冲区。

On my system, I have the following version fo 开始par:

# 开始par -v
startpar version 0.54

Startpar命令可以在“make” mode using –M option. In this mode, 开始par uses the following files to decide how to execute the 开始up scripts.
/etc/init.d/.depend.start
/etc/init.d/.depend.stop
/etc/init.d/.depend.boot

这里’s .depend.start文件的示例:

# cat /etc/init.d/.depend.start
TARGETS = halt fbset lvm_wait_merge_snapshot microcode.ctl earlysyslog dbus acpid random purge-kernels reboot network haldaemon boot.clock syslog ford_tso_off Sts splash_early haveged rpcbind multipathd nfs smbfs kbd irq_balancer alsasound mcelog network-remotefs sshd java.binfmt_misc clamd logd gpm ntp single atd clamav-milter canna amavis cups nscd postfix xdm cron smartd
INTERACTIVE = kbd ntp single
network: dbus
haldaemon: dbus acpid
syslog: network earlysyslog
ford_tso_off: network
Sts: network
splash_early: syslog
haveged: syslog random
rpcbind: syslog
multipathd: syslog
nfs: rpcbind
.
.
.
.
mcelog: smbfs
network-remotefs: smbfs haldaemon

在里面“make” mode, 开始par uses the .depend.start file to find which dependent services needs to be 开始ed in order to 开始 to 开始 a specific service.

在里面above ouput, when 开始par is executed with 开始 mode using 使 option, the dependent scripts are 开始ed first before the scripts are executed in parallel.

这里’s an example how the 开始par can be used in the 使 mode during system 开始up sequence,

# 开始par -p 4 -t 20 -T 3 -M 开始 -P N -R 2
D-Bus already 开始ed. Not 开始ing.
Starting acpid                    done
Re-Starting syslog services       done
Starting service at daemon        done
Starting sound driver             done
Starting cupsd                    done
Starting CRON daemon/usr/sbin/cron: can't lock /var/run/cron.pid, otherpid may be 3506: Resource temporarily unavailable
startproc:  exit status of parent of /usr/sbin/cron: 1
                                  done
Starting irqbalance                                                       unused
HAL already 开始ed. Not 开始ing.
Starting mcelog... already running                                        done
Setting up network interfaces:
    eth0      device: Intel Corporation 82545EM Gigabit Ethernet Co
    eth0      IP address: 19.86.xxx.xxx/24                                done
    eth1      device: Intel Corporation 82545EM Gigabit Ethernet Co
    eth1      IP address: 19.86.xxx.xxx/24                                done
Setting up service network  .  .  .  .  .  .  .  .  .  .                  done
Hint: you may set mandatory devices in /etc/sysconfig/network/config
Setting up (remotefs) network interfaces:
Setting up service (remotefs) network  .  .  .  .  .  .  .  .  .  .       done
Initializing random number generator                                      done
Starting smartd                                                           unused
Disabling TSO  上  all interfaces and adding ETHTOOL_OPTIONS to nic config files  done
Re-Starting syslog services              done
Starting haveged daemon                  done
failed_service="alsasound"
skipped_service="irq_balancer smartd"

在上面的示例中,使用总数为4的进程执行startpar,以并行运行,超时为20秒,全局超时为3秒,以清空缓冲区,在make模式下使用-M“start” option to indicate 开始up is being used in 开始 sequence.

This will use /etc/init.d/.depend. 开始 file to verify the scripts that are dependent 上 each other. –P is the previous run-level –N is the new runlevel.

这里’s another example to use 开始par just to execute 2 scripts in parallel, you can also define this script 上 /etc/init.d/rc to ensure these scripts gets 开始ed in parallel during system 开始up if required.

# 开始par -p 4 -t 20 -T 3 -a 开始 /etc/init.d/ypxfrd /etc/init.d/drbd
Starting rpc.ypxfrd              done
Starting DRBD resources:
.
.

Also in some Linux distros, you can setup the system to use 开始par option in /etc/init.d/rc file.

在rc文件中,只需更改值“CONCURRENCY=SHELL” to “CONCURRENCY=STARTPAR”, which should calculate the dependencies automatically and 开始 the applicable scripts in parallel.

# vi /etc/init.d/rc
CONCURRENCY=STARTPAR

如果您喜欢这篇文章,您可能还会喜欢..

  1. 50个Linux Sysadmin教程
  2. 50个最常用的Linux命令(包括示例)
  3. 排名前25位的最佳Linux性能监视和调试工具
  4. 妈妈,我找到了! – 15个实用的Linux Find命令示例
  5. Linux 101 Hacks第二版电子书 Linux 101黑客手册

Bash 101 Hacks书 Sed和Awk 101黑客手册 Nagios Core 3书 Vim 101黑客手册

{ 3 评论 … 加一 }

  • 萨卡德 2014年9月11日,上午3:57

    你好
    使用systemd对发行版有用吗?

  • 密码 2014年9月11日,晚上8:28

    这适用于哪些发行版?薄荷色’不支持它,所以我想Deb / Ubuntu可能也不支持。

    本文遗漏了很多,请具体说明这些文章。

  • 巴特 2016年5月19日,上午5:01

    哇谢谢你。一世’m与Sysvinit一起使用Linux From Scratch 7.9。
    I’我走了超越LFS路线,对现在拥有的配置以及我的配置感到非常满意’ve learned from it. I just noticed the existence of 开始par, and later doday I’m gonna 开始 trying to implement it using your information. Thanks for sharing!!

发表评论