Linux/centos Service Installation/uninstallation, boot start chkconfig command Details | How to get mysql, Apache boot?

Source: Internet
Author: User
Tags stop script

Chkconfig

Chkconfig are often used when operating on the command line. It makes it easy to set up and query system services at different run levels. This can be mastered well, with proficiency, you can easily manage your start-up services.

Note: Remember that Chkconfig does not automatically disable or activate a service immediately, it simply changes the symbolic connection.

Grammar:

    • Chkconfig [--add] [--del] [--list] [System Services]
    • Chkconfig [--level/levels] [Level code] [system service] [On/off/reset]

Grammatical explanations :

Chkconfig displays usage when no parameters are run. If the service name is added, check that the service is started at the current run level. If yes, returns TRUE, otherwise false is returned. If On,off or reset is specified after the service name, CHKCONFI will change the startup information for the specified service. On and off refers to the service being started and stopped, and reset refers to the boot information of the reset service, regardless of what is specified by the problematic initialization script. On and off switches, the system is only valid for run-level 3,4,5 by default, but reset can be valid for all run levels.

-The-level option allows you to specify the run level you want to view, not necessarily the current run level.

It is necessary to note that for each run level, there can be only one startup script or stop script. When you switch the run level, Init does not restart the service that is already started, nor does it stop the service that has stopped.

Chkconfig--list: Displays the running status information (on or off) of 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 one is missing, it is automatically created from the default init script.

Chkconfig--del Name: Deletes the service and removes the associated symbolic connection from the/ETC/RC[0-6].D.

Chkconfig [--level|levels] [Run level] system service [On|off|reset]: Sets whether a service is started, stopped, or reset at the specified run level.

For example, to stop the NFS service at the 3,4,5 run level, the command is as follows:

Chkconfig   --level   345   NFS   off

Run-level files:

Each service managed by Chkconfig needs to add two or more lines of comments to the script under the corresponding init.d .

The first line tells Chkconfig the run level of the default startup and the priority of start and stop. If a service does not start at any run level by default, use-instead of run-level.

The second line describes the service and can be commented on across lines.

For example,random.init contains three rows:

# chkconfig:2345 # description:saves and restores system entropy pool for # higher quality random number Gen Eration.

Add a description of the operational level concept of the Linux system:

The Linux OS divides the operating environment into the following 7 levels, i.e.
0: Turn off the machine
1: Single user mode (single user, no network)
2: Multi-user mode without network support (multiuser, no network)
3: Multi-user mode with network support (multi-user, network)
4: reserved, not used
5: Network support with X-window support multi-user mode (multi-user, network, X-window interface)
6: Reboot the system, that is,
restart

Linux has a variety of operating levels, the common is multi-user 2,3,4,5, many people know that 5 is the level of running X-windows, and 0 is shutdown. Changes to the run level can be toggled with the init command. For example, if you want to maintain the system into a single-user state, you can use init1 to switch. During the switching process of Linux running level, the system will automatically find files corresponding to the /etc/rc[0-6].d of K and S under the directory of Run level, and execute these scripts in the following numerical order. The maintenance of these scripts is a tedious thing, Linux provides the chkconfig command to update and query system services at different run levels.

Example:

1. View the status of each service in various levels of execution:

$chkconfig    --list

2. List the startup status of the system service VSFTPD at each execution level:

$chkconfig   --list      vsftpd

3. At execution level 3, 5 o'clock, turn off the VSFTPD system service:

$chkconfig    --level   vsftpd    off

4. When performing level 2,3,5, turn on the VSFTPD system service:

$chkconfig    --level      235      vsftpd      on

4.1. When performing level 2,3,5, restart the VSFTPD system service:

Chkconfig    --level     235    vsftpd     Restart

5. Close some services you do not need: If you do not have a printer:

$chkconfig  --level  235  cups  off

If you do not have a LAN:

$chkconfig  --level  235  SMB  off

If you do not require a remote user to log on:

$chkconfig  --level  235  sshd  off

If you do not need a scheduled task:

$chkconfig  --level  235  Crond  off

If you do not need to add new hardware:

$chkconfig  --level  235  kudzu  off

To view the process status for a particular system service, such as httpd:

$chkconfig  --list | grep httpd

1, how to add a service?

First, the service script must be stored in the /etc/ini.d/ directory;

Second, you need to use Chkconfig––add servicename to add this service to the list of Chkconfig tool services, where the service is given k/s entry in /etc/rc.d/rcn.d . Finally, you can modify the default boot level of the service by the method that is taught above.

2. How to start MySQL automatically under Linux?

First, ensure that the /etc/rc.d/init.d/mysqld exists, if the service mysqld start can be started normally, indicating the existence of services

(Note: If installed in rpm , the service will be automatically registered in the /etc/rc.d/init.d directory). To run the command:

Chkconfig--add mysqld

To run the command:

Chkconfig--level 345 mysqld on

Restart can

How is Source Installation , how to get the software to boot up to Apache for example?

Apache services are installed under Linux (by downloading binaries for economic compilation and installation, not RPM packages), Apache service startup command:

/server/apache/bin/apachectl start .  Let the Apache service run below RunLevel 3. The command is as follows:

Touch/etc/rc.d/init.d/apachevi/etc/rc.d/init.d/apachechown-r Root/etc/rc.d/init.d/apachechmod 700/etc/rc.d/ Init.d/apacheln-s/etc/rc.d/init.d/apache/etc/rc.d/rc3.d/s60apache   #S is the shorthand for start, the start, the K is the shorthand for kill, the representative is closed. 60 numbers represent the order in which they are started.

Contents of Apache:

#!/bin/bash

#Start httpd service/server/apache/bin/apachectl Start

At this point the Apache service can be automatically started at run Level 3 at random. (Note: When the /etc/rc.d/init.d/apache file is created, you can actually combine the chkconfig to adjust the startup service accordingly.) )

In addition, the start command can also be/server/apache/bin/apachectl StartWrite directly/etc/rc.d/rc.localfile, to achieve the purpose of booting up!

Extended reading:

Linux boot process detailed (Inittab, Rc.sysinit, RCX.D, rc.local)

The relationship between/ETC/RC.D/RC and/ETC/RC.D/INIT.D

Linux boot chkconfig Command details | How to get mysql, Apache boot?

"Summary"/etc/rc.d/rc.local and/etc/profile. bash_profile. bashrc File Execution order

Linux/centos Service Installation/uninstallation, boot start chkconfig command Details | How to get mysql, Apache boot?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.