Linux chkconfig command detailed solution is to add services and two ways to start and shut down system services

  
        The chkconfig command is mainly used to update (start or stop) and query the runlevel information of the system service. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symbolic link.

First, the syntax of chkconfig

1, chkconfig [--add][--del][--list][system service] or chkconfig [--level <levels level code> ][System Services][on/off/reset]

2. Parameter Usage: --add Adds the specified system service, allows the chkconfig command to manage it, and adds it to the system-initiated narration file. related data. --del Deletes the specified system service, no longer managed by the chkconfig command, and deletes the relevant data in the system-initiated statement file. --level<level code> Specifies which execution level the read system service is to be turned on or off. Level 0 means: Indicates shutdown. Level 1 means: Single User Mode Level 2 means: Multi-user command line mode without network connection Level 3 means: Multi-user command line mode with network connection Level 4 means: System Reserved Level 5 means: Multi-user mode of graphical interface Level 6 means: restart 3. It should be noted that the level option can specify the run level to be viewed and not necessarily the current run level. There can only be one startup script or stop script for each run level. When switching the run level, init will not restart the already started service, nor will it stop the stopped service again.

4, chkconfig --list [name]: Display the running status information (on or off) of all running level system services. If name is specified, only the status of the specified service at different run levels is displayed. 5, chkconfig --add name: add a new service. Chkconfig ensures that each run level has a start (S) or kill (K) entry. If it is missing, it will be automatically created from the default init script. Chkconfig --del name: deletes the service and removes the associated symbolic link from /etc/rc[0-6].d. Chkconfig [--level levels] name: Set whether a service is started, stopped, or reset at the specified run level.

6, run-level files: Each service managed by chkconfig needs to add two or more lines of comments in the script under the corresponding init.d. The first line tells chkconfig the run level of the default start and the priority of start and stop. If a service is not started by default at any runlevel, use - instead of runlevel. The second line describes the service and can be commented with \\ cross-row. For example, random.init contains three lines: # chkconfig: 2345 20 80 # description: Saves and restores system entropy pool for \\ # higher quality random number generation.

Example of use: chkconfig --list #list all System service chkconfig --add httpd #add httpd service chkconfig --del httpd #delete httpd service chkconfig --level 2345 httpd on #set httpd in the case of run level 2, 3, 4, 5 are on (on The state of chkconfig --list # lists all the service startup conditions of the system chkconfig --list mysqld #list mysqld service settings chkconfig --level 35 mysqld on #Set mysqld in the level 3 and 5 for the boot service, - -level 35 means that the operation is only performed at levels 3 and 5, on means start, off means off chkconfig mysqld on #set mysqld at each level is on, "all levels" include 2, 3, 4, 5 levels

7, how to add a service: mysqld as an example (1), the service script must be stored in the /etc/init.d/directory; (2), chkconfig --add mysqld #Add service, in the chkconfig tool Service list This increases the service, so the service will be given K /S in inlet /etc/rc.d/rcN.d; (3), chkconfig --level 35 mysqld on # start to modify the default service level.

Second, the service startup /shutdown

1, system services: has been in memory, and has been running, and provides services called services;

2 The service is also a running program, then the running program is called daemons;

3. The startup scripts for these services are generally placed in: /etc/init.d

4 The service startup script in centos is placed in: /etc/rc.d/init.d and /etc/init.d is a recognized directory. In centos, /etc/init.d is a link file

5, /etc/sysconfig service initialization environment variable configuration is in this file.

6, /var/lib The database generated by each service is in this directory, the most simple to find mysql here. Use vim to open it, you can see that the database you created and the default database name generated by the system are In it!

7,

8, start/stop/restart service: /etc/init.d/serverName start/stop /restart/status

9, start/stop/Restart the service: service serverName start/stop/restart Why can I write this?

10, service is a script. He can analyze the parameters that you later release, and then get the correct service according to your parameters in /etc/init.d stop start restart

Copyright © Windows knowledge All Rights Reserved