Linux service starts automatically at boot

1. Startup level
1. Check the default startup level of the linux system
cat /etc/inittab
id:3:initdefault: ##You can see that the default is three
2. Check whether a service is started at each startup level
[root@localhost ~] # chkconfig --list nfs
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
3. There are 7 boot
levels :
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
detailed explanation of each run level:
0 means shutdown, the machine is shut down.
1 is single-user mode, similar to the safe mode under Win9x.
2 is multi-user mode, but no NFS support.
3 is full multi-user mode and is the standard run level.
4 Generally not used, in some special cases it can be used to do some things. For example, when the laptop's battery runs out, you can switch to this mode to make some settings.
5 is X11, into the X Window system.
6 for reboot, run init 6 and the machine will reboot.
0 and 6 are generally not used;

2. chkconfig
description: all services of linux are under /etc/init.d/, but /etc/init.d is linked to /etc/rc.d/init.d and
       also /etc/ rc[0-6].d are all linked to the corresponding /etc/rc.d/rc[0-6].d, and services in rc[0-6].d of different startup levels are linked /etc/rc.d/rc[0-6].d Corresponding services under etc/init.d

1. The chkconfig command is mainly used to update (start or stop) and query the run-level information of system services. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symlink.
  Syntax:
    chkconfig --list [name]
    chkconfig --add name
    chkconfig --del name
    chkconfig [--level levels] name
    chkconfig [--level levels] name
    When chkconfig is run with no arguments, display usage. If you add a service name, then check if the service is started in the current runlevel. If yes, return true, otherwise return false. If on, off or reset is specified after the service name, chkconfi will change the startup information for the specified service. on and off refer to the service being started and stopped, respectively, and reset refers to resetting the service's startup information, regardless of what the init script in question specifies. The on and off switches are only valid for run levels 2, 3, 4, and 5 by default, but reset can be valid for all run levels.
    The --level option can specify the runlevel to view instead of the current runlevel.
    It should be noted that for each runlevel, there can only be one start script or stop script. When switching runlevels, init will not restart services that have already been started, nor will it stop services that have been stopped again.
2. chkconfig --list : Displays the running status information (on or off) of all run-level system services. If name is specified, then only the status of the specified service at different runlevels is displayed.
    chkconfig --add name: Add a new service. chkconfig ensures that each runlevel has a start (S) or kill (K) entry. If missing, it will be created automatically from the default init script.
    chkconfig --del name: Delete the service and delete the related symbolic link from /etc/rc[0-6].d.
    chkconfig [--level levels] name : Sets whether a service should be started, stopped or reset at the specified runlevel. For example, to stop the nfs service at runlevels 3, 4, and 5, the command is as follows:
    chkconfig --level 345 nfs off

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326397998&siteId=291194637