当前位置:网站首页>Cluster control management

Cluster control management

2022-06-24 12:03:00 Hua Weiyun

Current Linux  There are two mainstream init The way : One is widely spread System V initialization, It comes from Unix And it is still used by all kinds of Linux  Adopted by ; The other is proposed in recent years Upstart The way , Based on the event mechanism , All services of the system , Tasks are event driven . as far as I am concerned , At present, there are Ubuntu(6.10 and later),Fedora(9.10 and later),Debian(optional). Although Upstart There are not many distributions of , But it is designed to replace the old style System V initialization.

Sort out as knowledge , I will now summarize the initialization processes of these two methods , This is also for the convenience of sorting out ideas :

I was looking for Linux System init You can always see relevant information about the process inittab The figure of , But in my Ubuntu There is no such file on , Only later did I know that  Upstart The way of Ubuntu There was no inittab Of this file . In the old style System V initialization in ,/etc/inittab It's a very important document .init The first thing to look for after the process is started !inittab Responsible for initializing the system , Set up the system runlevel Ji Jin   Enter each runlevel Corresponding to the command to be executed . Assuming the current inittab The default value set in runlevle yes 5, be init Will run /etc/init.d/rc 5 command , This command will traverse and execute according to the dependencies of system services /etc/rc5.d The script in the / Program . Get into /etc/rc5.d You can find that the files in the directory are all to /etc /init.d/ Under the corresponding script / Soft links to programs . With S The beginning means to start , With K The beginning is stop . also S/K The last two digits represent the starting sequence of the service ( Determined by service dependencies ).

that Upstart job What is it like ? We know ,System V initializaiton In order to runlevel At the core , Based on the dependencies between services init The way , But in Upstart job,runlevel Although it also has an impact on service startup, it is not the key .Upstart job It's event driven , Start of system services 、 Stop and so on are all determined by events , In turn, , Start of system services 、 Stopping can also be used as an event source to trigger other services . And events don't have to be generated internally , Users can manually type start/stop [Service] Generate an event to start / Termination of services .man upstart-evnets see upstart job Events defined , You can find ,runlevel It is also treated as an event ( because runlevel A change of events ), And so on, and so forth  startup,started,filesystem wait . How does the system service know when it should start , When did it end ? The answer is /etc /init in ( yes , we have distros May be in /etc/event.d). Get into /etc/init Take a look at the table of contents , Are configuration files of system services , Or say , yes job definition files.( actually Upstart init It only needs /etc/init Such a directory , Unlike System V init,“ Turn and wipe feet ” It takes many turns to reach the destination , It is inferior to the former in performance ). Open any file , such as cron.conf:

# cron - regular background program processing daemon

# cron is a standard UNIX program that runs user-specified programs at

# periodic scheduled times

description “regular background program processing daemon”

start on runlevel [2345]

stop on runlevel [!2345]

expect fork

respawn

exec cron

I believe the sharp procedural apes have found :start on runlevel [2345];stop on runlevel [!2345]

you 're right , The configuration file is used to set when the service is started , When to terminate .

In fact, it's not just at the beginning of system startup , The service can be started or stopped by sending events at any time when the system is running . This is Upstart job One of the advantages of , Except for system initialization , It can also play a role in the system operation phase . by comparison System V initialization The configuration file in the mode is generally only used in the system initialization phase , Of course, during the system operation phase, we can pass /etc/init.d/Service start/stop/otherCommand To operate the service , But obviously not as good as Upstart The way is simple and clear .

good , Introduction after System V initialization and Upstart, So now we can introduce Ubuntu init System initialization process . I mentioned it earlier Ubuntu It uses Upstart The way of initialization, It's not all , in consideration of 6.10 Previous versions used System V init And the need for certain services ,Ubuntu The compatibility mode is adopted , namely : In the system, there are System V-style Services started , Also have Upstart Services started . If you're using Ubuntu14.04( I am currently PC System on ), Then you can see that there are several directories in the system :

/etc/init

/etc/init.d

/etc/rc${runlevel}.d

As two kinds init The way each has its own characteristics /etc/init.d,/etc/rc r u n l e v e l . d Contents and / e t c / i n i t Directory in U b u n t u All of them , that U b u n t u How to achieve compatibility ? actually , U b u n t u There is no direct use of S y s t e m   V s t y l e Start the service , Need to know , U b u n t u Medium i n i t Has been replaced by U p s t a r t   i n i t , and S y s t e m   V s t y l e Our services are stored in / e t c / r c {runlevel}.d Contents and /etc/init Directory in Ubuntu All of them , that Ubuntu How to achieve compatibility ? actually ,Ubuntu There is no direct use of System V-style Start the service , Need to know ,Ubuntu Medium init Has been replaced by Upstart init, and System V-style Our services are stored in /etc/rc {runlevel}.d In the directory ,( and /etc/rc r u n l e v l e . d / The file under is to / e t c / i n i t . d The soft links ) can U p s t a r t   i n i t It doesn't directly go here to start the service . It is used to start such services through indirect calls . let me put it another way , U b u n t u Medium i n i t It doesn't run straight / e t c / i n i t . d perhaps / e t c / r c {runlevle}.d/ The file under is to /etc/init.d The soft links ) can Upstart init It doesn't directly go here to start the service . It is used to start such services through indirect calls . let me put it another way ,Ubuntu Medium init It doesn't run straight /etc/init.d perhaps /etc/rc {runlevel}.d/ And go , It takes a compromise approach , adopt /etc/init Some configuration file calls under /etc/rc${runlevel}.d/ Script in to start using the old style System V-style Service for . alas , I think it's easy to say , See the example , Look below .

Get into /etc/init Catalog (Upstart init The configuration file will be read in this directory ), You will find a few rc About the configuration file :

rc.conf

rc-sysinit.conf

rcS.conf

rc-sysinit stay startup It is started when the event occurs ,rc In system runlevel It is activated when changing ,rcS In system runlevel by S( Service startup ) When to start . In the comments of the configuration file , These files , It is Upstart init Handle System V-style The key to service .

rc-sysinit stay startup It is started when the event occurs , namely ,Upstart init Will first read rc-sysinit.conf And execute relevant configurations and scripts .rc-sysinit.conf The main task of is to set the system default runlevel, Detect the presence of /etc/inittab Or kernel command line , If exist , Then press the kernel command line >/etc/inittab> Default runlevel Set up the system in sequence  runlevel. Last , call telinit Enter the set runlevel.

Because the call telinit Entered the set runlevel,runlevel Changing events happen , here rc Service startup ( Of course, other services will also ). that , It is necessary for us to have a look rc.conf What the hell is in it . open rc.conf, Notice the last line :

exec /etc/init.d/rc $RUNLEVEL

Does it feel /etc/init.d/rc Familiar with , you 're right , stay System V initialization in ,/etc/inittab Each of runlevel The corresponding command line is set in this form .

Obviously ,/etc/init.d/rc Is called the , And it is transmitted to the system set up earlier runlevel As a parameter . and /etc/init.d/rc According to the incoming runlevel Parameter call /etc/rc${runlevel}.d/ Next script ( With S start ) To start the service , Terminate in the previous runlevel Started and currently in  runlevel Services that need to be terminated . thus ,Ubuntu Handle System V-style Is the service process becoming clear . adopt rc-sysinit and rc Indirect call /etc/init.d/rc To start System V-style service ,Ubuntu In the adoption of new Upstart init Took care of the old style System V init.

use Upstart The services started in the mode are /etc/init/ There is a configuration file of its own in the directory , Input under terminal : initctl list ( View service  ), See if the listed services are the same /etc/init/ The services under are exactly the same !

Shut down a service

#initctl stop

atd atd stop/waiting

PS: A lot of the above content is my personal understanding , The general direction should be right , But the understanding of the details is not guaranteed . Don't forget to give advice when you find out !

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241003459647.html