The Chkconfig command is used primarily to update (start or stop) and to query run-level information for system services. Keep in mind that Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection.
Use syntax:
Chkconfig [--add][--del][--list][System Services] or Chkconfig [--level < rank code >][system Services][on/off/reset]
Chkconfig Displays the usage when no parameters are running. If you add a service name, check to see if the service is starting at the current run level. Returns true if it is, or false. If On,off or reset is specified after the service name, CHKCONFI changes the startup information for the specified service. On and off means that the service is started and stopped, and reset refers to resetting the service's startup information, regardless of what the initialization script for the problem specifies. On and off switches, the system defaults to run-level 3,4,5 only, but reset can be valid for all run levels.
Parameter usage:
--add adds the specified system service, allows the chkconfig instruction to manage it, and adds the relevant data to the system-initiated narrative file.
--del deletes the specified system service, is no longer managed by the Chkconfig command, and deletes the relevant data in the system-initiated narration file.
--level < grade code > specifies which execution level the system service should be opened or closed.
Level 0 means: the shutdown
Level 1: Single user mode
Level 2 means: Multi-user command-line mode with no network connection
Level 3 means: Multi-user command-line mode with network connections
Level 4 indicates: Not available
Level 5 means: Multi-user mode with graphical interface
Level 6 indicates: reboot
It is necessary to note that the level option can specify the run levels to view, not necessarily the current run level. For each run level, there can be only one startup script or stop script. When the run level is switched, Init does not restart the service that has started, nor does it stop the service that has stopped.
Chkconfig--list [name]: Displays the running status information (on or off) for all run-level system services. If name is specified, only the state of the specified service at a different run level is displayed.
Chkconfig--add Name: Add a new service. Chkconfig ensure that each run level has a start (S) or Kill (K) entry. If it is missing, it is automatically created from the default init script.
Chkconfig--del Name: Deletes the service and deletes the associated symbol connection from/ETC/RC[0-6].D.
Chkconfig [--level Levels] Name: Sets whether a service is started, stopped, or reset at the specified run level.
Run-level files:
Each service managed by Chkconfig needs to be annotated with two or more lines of script under the corresponding INIT.D. The first line tells Chkconfig the run level of the default boot and the priority of start and stop. If a service does not start at any run level by default, then use-instead of run level. The second line describes the service, and you can use a cross row annotation.
For example, Random.init contains three lines:
# chkconfig:2345 20 80
# description:saves and restores system entropy pool for
# higher quality random number generation.
Use Example:
1, list the system all service starts the situation
Chkconfig--list
2. Increase HTTPD Service
Chkconfig--add httpd
3. Delete httpd Service
Chkconfig--del httpd
4, set the httpd at the run level of 2, 3, 4, 5 is the status of On (open)
Chkconfig--level httpd 2345 on
5, List the MYSQLD service setup situation
Chkconfig--list mysqld
6, set the mysqld in Level 3 and 5 for the boot run service,--level 35 indicates that the operation is only performed at level 3 and 5, on is started, off is off
Chkconfig--level mysqld on
7, set the mysqld in each level is on, "each level" includes 2, 3, 4, 5 grade
Chkconfig mysqld on
How to add a service:
1. Service scripts must be stored in the/etc/ini.d/directory;
2.chkconfig--add ServiceName
Add this service to the Chkconfig tool Services list, at which point the service is given a k/s entry in the/ETC/RC.D/RCN.D;
3.chkconfig--level mysqld on
Modify the default boot level for the service.
below will say some practical application of things, original + focus. Hey
I have been in the application of this situation, when the system started to report a large number of failed to connect MySQL error, the problem is that the MySQL database has not been started when it has started some need to connect the MySQL database services. This way we have to modify the boot sequence to put the services that need to be connected to the MySQL database until the MySQL service is started. So we have to modify the startup script. It's usually under the/ETC/RC.D/INIT.D. This is mainly the section, as follows:
# chkconfig:345 99 01
# Description:nagios Network Monitor
#
# File:nagios
One of the things we want to change is: # chkconfig:345 99 01.
345 99 01
What exactly do these three sets of numbers mean?
345 represents the boot level of the system. That means the system starts the Nagios service at 345 boot level.
99 01 represents the startup level of the application, which is the service when the system starts.
345 If this set of numbers appears in the startup script, it is equivalent to executing the chkconfig--add Nagios as we performed the Chkconfig--add Nagios and Chkconfig--level 345 on two commands.
Practice, as shown in figure:
Perform Chkconfig--add npcd as shown in the figure:
Only the Chkconfig--add NPCD was executed, and the result 345 state was on. Which is actually equivalent to executing two commands. Here you can directly perform the service NPCD start.
If this group of data is not present or appears-it means that after performing the Chkconfig--add NPCD must perform the Chkcofnig--level 345 nagios on this command before we can perform service Nagios start
Practice:
Perform chkconfig--add NPCD
See, all the states are off. Then we have to perform chkconfig--level 345 npcd on before we can execute the service npcd start command.
Let's do a comparison with httpd and Nagios to see if the number is large, start or close first, or start or close with a small number. Practice the truth.
The priority of the httpd is shown in the figure (only appears in the HTTP startup script-as we've already mentioned before):
The priority of the Nagios is shown in the figure (Nagios in the preceding 345 set of values):
99 This set of numbers is the start of the system when the service starts the priority---the smaller the number, the higher the priority, that is, when the starting value of the smaller the more first start. As shown in the figure:
01 This set of values is when the system shuts down the priority of the service---the smaller the number, the higher the priority, that is, closed when the number of the smaller the more closed first. As shown in the figure:
Practice confirms that the smaller the number, the more it starts and shuts down first.
Understanding this, it is quite easy to deal with the problem, or do not know how to modify the start order of the service. Oh