linux operating modes: runlevel startup items and services

linux operating system to boot up since started to go through several different stages, these stages is called runlevel, Similarly, when linux operating system shutdown also experienced several other different runlevel, here we are ready to explain in detail runlevel, and show you some tips to make your linux system to avoid unnecessary re-start. . 

runlevel can be considered a system state, the image that you can think runlevel bit like Microsoft windows operating system in Normal, safemode, and the Command prompt only. Into each runlevel need to activate or deactivate the appropriate range of services (services), these services (services) to initialize the script placed in the directory /etc/rc.d/rc?.d/ way or / etc / rc ?. D (? behalf runlevel corresponding number) below . .

In most linux distributions, there are usually eight runlevel ..

The System State runlevel
0 the Halt The System
# 0 - off (do not put initdefault set to 0)
. 1 Single User MODE #. 1 - Single-user mode
2 Basic MODE Multi User # 2 - Multi-user, without the NFS
. 3 the Multi User MODE #. 3 - full multi-user mode (normal operating level)

# 4 - not used
. 5 the GUI with the Multi User MODE #. 5 - X11 (Xwindow)
. 6 the Reboot The System
S, S Single User MODE
.
# 6 - Restart (do not put initdefault is set to 6-- put you black out the linux initdefault 0 or 6 can be considered a denial of service attack Oh!)

 

 

Most of the default linux desktop runlevel is 5, when the user login is a graphical interface, and most of the server version of linux system default runlevel is 3, when the user logs character interface, runlevel 2 in addition to 1 and Debugging rarely used, runlevel s S, and not directly to users, but to prepare for the Single user mode. ..

linux operating mode than the windows startup mode advantage is that: you can use the tool to switch runlevel .init you now use when the system is idle, in addition, you have to switch your unconsciously when you shut down or boot linux system runlevel, system shutdown process needs to invoke runlevel (0 or 6) to close all the running processes. !

Displays the current operating mode .

When just getting started, you may be curious about previously and currently being used in the operation mode, runlevel command can be used to display the information:
$ / sbin / runlevel
3 5
output runlevel command shows that the first operating mode is 3, and now the operating mode is 5.
. 


Switching the operating mode using the telinit command (root user):
$ / sbin / telinit
Typically, the purpose of switching the operation mode is to restart the process in some applications, such as XFree86, the operating mode is switched to from 3 to 5 and the associated terminating all XFree86 process, and then run the mode switch to 5, XFree86 can be very clean start. Before doing these tasks, make sure that all work under XFree86 have been saved, with the root user:
$ / sbin / telinit 3
$ / sbin / telinit 5
After you type the command, your screen may show some of the services to start or stop Information.
.

Join start the service in operation mode ..

To join a start service in one mode of operation, the service must first create a new startup script, then place it in /etc/rc.d/init.d or /etc/init.d / (depending on your version of linux have the different), the startup script to be associated with the operation mode together, you need this directory operation mode establish symbolic link with the startup script the next /etc/rc.d/init.d/, the file name prefix is usually SXX, XX is a number that number is used to control the operating mode of the startup sequence and services. Script execution order is ascending according to the size of the figures executed, the smaller the number is first performed, the following is added to a specific example of the service start mode of operation:
$ CP MyService /etc/rc.d/init.d/
$ LN - s /etc/rc.d/init.d/myservice /etc/rc3.d/S99myservice

Thus, the next time to start runlevel 3, MyService starts automatically.


Start with a runlevel

You can develop your own startup enters runlevel, if your system is using lilo, in the corresponding part of the start command:
LILO: Linux 5
If you are using GRUB, when you start you can hold down the e key enter the setup mode, the respective position display:
Kernel / vmlinuz the root RO = / dev / hda1. 5

 

Application Settings:

 

under linux setup program (service) several ways to boot from the start

1,
this is the most commonly used

rcconf:

 

sudo apt-get install rcconf

 

root run: rcconf

 

More full of: sysv-rc-conf

 

sudo apt-get install sysv-rc-conf

 

Run: sysv-rc-conf

This is very simple to change, as shown below:

 

2,

 

/Etc/rc0.d ~ /etc/rc6.d direct change and under what /etc/rcS.d, S indicates the beginning of the start, K ​​does not start at the beginning of the representation,

For example: vsftpd want to close the boot automatically activated, simply sudo mv /etc/rc2.d/S20vsftpd /etc/rc2.d/K20vsftpd it. 

The intention is to use this command mv rename function.

 

3, chkconfig , this method redhat, Debian which more commonly used, method 1 is relatively simple in fedora and ubuntu inside, but to learn about this method is good.

But in ubuntu redhat this command is not easy to use, always wrong.

Forget it, or look directly inside redhat chkconfig usage of it.

1,chkconfig --level [0123456] [service name] [on|off]

chkconfig --level 23 dhcp3-server off ----设定dhcp server服务在level2,3下关闭.

2,chkconfig --list 查看服务的自动开启状态

3,chkconfig --add 增加一个服务给chkconfig来管理,但是该服务必须在/etc/init.d内 .

例子,

1,gedit /etc/init.d/test

chkconfig:[runlevels] [start number] [stop number]

chkconfig: 23 80 70

其中start number 代表S80test

stop number 代表K70test

2,chkconfig --add test

3,chkconfig --list test

test 0:off 1:off 2:on 3:on 4:off 5:off 6:off

4,check /etc/rc.d/下的档案

find /etc/rc.d -type l | grep 'test' |sort

/etc/rc.d/rc0.d/K70test

/etc/rc.d/rc1.d/K70test

/etc/rc.d/rc2.d/S80test

/etc/rc.d/re3.d/S80test

 

/etc/rc.d/rc4.d/K70test

 

/etc/rc.d/rc5.d/K70test

 

/etc/rc.d/rc6.d/K70test

 

/etc/rc.d/rc7.d/K70test

 

 

 

 

-type l代表“连接文件”

 

 

4,chkconfig --del 删除一个给chkconfig管理的服务

5,显示目前run level 2为启动的服务

chkconfig --list | grep '3:on'

 

 

 

如果以上方法在Ubuntu 10.04中不起作用 ,例如mysql 和 vsftpd在按照上面设置后仍会开机启动

Then you need to do some of the following tasks:

Enter / etc / init / directory

cp /etc/init/

You will find that there are mysql.conf and vsftpd.conf file

Good is that these two files need minor modifications

In the beginning of the file has

ON Start (! filesystem and NET-Device-up IFACE = LO)
STOP ON runlevel [XXXX]    #XXXX level is represented as runlevel: 2345 represents 2,3,4,5 runlevel

In my vsftpd.conf is

ON runlevel STOP [! 2345] # represents not start in runlevel non-2,3,4,5

Here is the crux of the problem, our system is the default boot to runlevel 2

So we can change it to

ON the runlevel STOP [0126] # of course, not be the case, but should include at least 2

 

Reproduced in: https: //my.oschina.net/dake/blog/196630

Guess you like

Origin blog.csdn.net/weixin_34037515/article/details/91508372