Usage of chkconfig under Linux, mysqld boot from boot

Source: Internet
Author: User
Tags stop script

Usage of chkconfig under Linux, mysqld boot from boot

Use syntax:

chkconfig[--add][--del][--list][system service] or chkconfig[--level< Class Code >][system service][on/off/reset]

Parameter usage:

--add: Adds the specified system service, allows the CHKCONFIG directive to manage it, and simultaneously adds the relevant data to the system-initiated narrative file.

--del: Deletes the specified system service, is no longer managed by the Chkconfig directive, and deletes the relevant data in the system-initiated narrative file.

--level< Class Code: Specifies which execution level the read system service is to open or close. Examples of Use:

Chkconfig--list List of all system services

Chkconfig--add httpd Add httpd Service

Chkconfig--del httpd Delete httpd service

Chkconfig--level httpd 2345 on httpd is on when the operation level is 2, 3, 4, 5. The Chkconfig command provides an easy way to set the runlevel of a service. For example, to set up a MySQL server to run at run Level 3 and 4, you must first add MySQL as a service managed by Chkconfig:

Chkconfig--add MySQL

Now, we set the service to "on" at levels 3 and 5

chkconfig--level MySQL on at other levels set to OFF

chkconfig--level 01246 mysql off in order to confirm that your configuration has been modified correctly, we can list the runlevel that the service will run as follows:

#chkconfig--list MySQL

MySQL 0:off 1:off 2:off 3:on 4:off5:on 6:off

Linux Boot chkconfig command detailed (let MySQL, Apache boot)

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.

Chkconfig Syntax:

chkconfig       [--add]       [--del]     [--list]      [System Services]  
chkconfig       [--level/levels]      [Class Code]       [System Services]      [on/off/reset] 
 
Syntax Explanation:

chkconfig when no arguments are run, the usage is displayed. 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 there can be only one startup script or stop script for each run level. 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 health 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 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/ETC/RC[0-6].D.
chkconfig     [--level|levels]     [run-level]    system Services       [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, which you can annotate with \ cross-line.

For example, Random.init contains three rows:

# chkconfig:2345 20 80
# description:saves and restores system entropy pool for \
# higher quality random number generation.

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:


The code is as follows:

$chkconfig--list

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


The code is as follows:

$chkconfig--list vsftpd

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


Copy Code

The code is as follows:

$chkconfig--level vsftpd off

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


The code is as follows:

$chkconfig--level 235 vsftpd on

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


The code is as follows:

Chkconfig--level 235 vsftpd Restart

5. Close some of the services you don't need:

If you do not have a printer:


The code is as follows:

$chkconfig--level 235 Cups off

If you do not have a LAN:


The code is as follows:

$chkconfig--level 235 SMB off

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


The code is as follows:

$chkconfig--level 235 sshd off

If you do not need a scheduled task:


The code is as follows:

$chkconfig--level 235 Crond off

If you do not need to add new hardware:


The code is as follows:

$chkconfig--level 235 Kudzu off

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


The code is as follows:

$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:


The code is as follows:

Chkconfig--add mysqld

To run the command:

The code is as follows:

Chkconfig--level 345 mysqld on

Restart can

How to install the source code, how to let the software boot, to Apache as an 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:


The code is as follows:


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
Ln-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:


The code is as follows:


#!/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 startup command can be/server/apache/bin/apachectl start directly written to the/etc/rc.d/rc.local file, to enable the start-up purpose!


This article is from the "small White love life" blog, please be sure to keep this source http://sf1314.blog.51cto.com/13295031/1970836

Usage of chkconfig under Linux, mysqld boot from boot

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.