Linux boot chkconfig let mysql, Apache boot

Source: Internet
Author: User
Tags reset stop script


Chkconfig

Chkconfig is used frequently on command line operations. It makes it easy to set up and query system services at different run levels. This can be well mastered, with proficiency, you can easily manage your startup service.

Note: Keep in mind that Chkconfig is not an immediate automatic prohibition or activation of a service, it simply changes the symbolic connection.

Grammar:

Chkconfig [--add] [--del] [--list] [System Services]
Chkconfig [--level/levels] [rating code] [System Services] [On/off/reset]
Syntax Explanation:

Chkconfig when no parameters are running, display usage. 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.

-The-level option can specify the run level to view, not necessarily the current run level.

It should be explained that there can be only one startup script or stop script for each run level. 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: Displays 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: Adds 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] [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 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 # description:saves and restores system entropy pool for # higher quality random number Generatio N.
Add an introduction to the running level concept of Linux systems:

The Linux OS divides the operating environment into the following 7 levels, 0: Shutdown 1: Single user mode (single user, no network) 2: Multiuser mode without network support (multiuser, no network) 3: Multiuser mode with network support (multiuser, with network) 4: reserved, unused 5: The network support has the X-window support the multi-user mode (multi-user, has the network, the X-window interface) 6: Reboots the system, namely reboots
Linux has a variety of operating levels, common is multi-user 2,3,4,5, many people know that 5 is the level of running X-windows, and 0 is off the machine. Changes to the run level can be toggled through the init command. For example, suppose you want to maintain the system into Single-user state, then you can use INIT1 to switch. In the Linux run-level switching process, the system will automatically look for the corresponding run-level directory/ETC/RC[0-6].D of K and S files, in the following numerical order, execute these scripts. The maintenance of these scripts is a tedious task, and Linux provides the chkconfig command to update and query system services at different runtime levels.

Example:

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

$chkconfig--list

2. List system service VSFTPD at each execution level:

$chkconfig--list vsftpd

3. At executive Level 3, 5 o'clock, shut down the VSFTPD system service:

$chkconfig--level vsftpd off

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

$chkconfig--level 235 vsftpd on

4.1. Restart the VSFTPD system service when performing level 2,3,5:

Chkconfig--level 235 vsftpd Restart

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

$chkconfig--level 235 Cups off

If you do not have a local area network:

$chkconfig--level 235 SMB off

If the remote user is not required 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

View the process status of a specific 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 tools services, where the service is given a k/s entry in the/ETC/RC.D/RCN.D. Finally, you can modify the default boot level of the service by the method above.

2, how to automatically start MySQL under Linux?

First of all, ensure that/etc/rc.d/init.d/mysqld exist, if the service mysqld start can start normally, indicating that services exist

(Note: If the RPM is installed, the corresponding service will automatically be 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

Reboot can

How is the source code installation, how to let the software boot, to Apache as an example?

The Apache service is installed under Linux (by downloading the binaries to compile the installation rather than the RPM package), and the Apache Service launch command:

Touch/etc/rc.d/init.d/apache
Vi/etc/rc.d/init.d/apache
Chown-r Root/etc/rc.d/init.d/apache
chmod 700/etc/rc.d/init.d/apache
The Ln-s/etc/rc.d/init.d/apache/etc/rc.d/rc3.d/s60apache #S is a shorthand for start, a representative startup, a shorthand for kill, and a representative shutdown. 60 numbers represent the order in which they are started.

The contents of Apache:

#Start httpd Service
/server/apache/bin/apachectl start

The Apache service can then be automatically started at run Level 3 at random. (Note: When the/etc/rc.d/init.d/apache file is created, it can actually be combined with chkconfig to adjust the start service accordingly.) )

In addition, you can also start the command/server/apache/bin/apachectl start directly into the/etc/rc.d/rc.local file, to achieve the purpose of starting the 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.