Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use chkConfig under linux

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following together to understand the use of chkConfig under linux, I believe we will certainly benefit from reading, the text is not more refined, I hope that the use of chkConfig under linux This short content is what you want.

Usage syntax:

chkconfig[--add][--del][--list][system services] or chkconfig[--level][system services][on/off/reset]

Parameter Usage:

--add: Adds the specified system service, allowing the chkconfig directive to manage it, and adds the relevant data to the system startup description file.

--del: Delete the specified system service, no longer managed by chkconfig directive, and delete related data in the system startup description file.

--level: Specifies the execution level at which the Read System service is to be turned on or off. Examples of use:

chkconfig --list lists all system services

chkconfig --add httpd add httpd service

chkconfig --del httpd Remove httpd services

chkconfig --level httpd 2345 on Sets httpd to on at runlevels 2, 3, 4, and 5. The chkconfig command provides an easy way to set the runlevel of a service. For example, to set up MySQL Cloud Virtual Machine to run on runlevels 3 and 4, you must first add MySQL as a chkconfig-managed service:

chkconfig --add mysql

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

chkconfig --level 35 mysql on set to off on other levels

chkconfig --level 01246 mysql off To confirm that your configuration has been modified correctly, we can list the runlevels at which 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 explanation (MySQL, Apache boot)

chkconfig

chkconfig is often used for command-line operations. It can easily 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 does not automatically disable or activate a service immediately, it simply changes the symbolic link.

chkconfig Syntax:

chkconfig [--add] [--del] [--list] [System Services]

chkconfig [--level/levels] [level code] [system services] [on/off/reset]

Grammar explanation:

chkconfig shows usage when run without parameters. If you add a service name, check to see if the service is started at the current run level. If yes, return true, otherwise return false. If on, off, or reset is specified after the service name, chkconfi changes the startup information for the specified service. On and off refer to the service being started and stopped, respectively, and reset refers to resetting the startup information for the service, regardless of what the problematic initialization script specifies. On and off switches. By default, the system is only valid for runlevels 3, 4, and 5, but reset can be valid for all runlevels.

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

It should be noted that there can only be one start script or one stop script per run level. When switching runlevels, init does not restart services that have been started, nor does it stop services that have been stopped again.

chkconfig - -list: Displays health status information (on or off) for all run-level system services. If name is specified, only the status of the specified service at different runlevels is displayed.

chkconfig - -add name: adds a new service. chkconfig ensures that there is one start (S) or kill (K) entry per run level. If missing, it is automatically created from the default init script.

chkconfig - -del name: Remove the service and remove the associated symbolic links 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 a specified runlevel.

For example, to stop the nfs service at runlevels 3, 4, and 5, the command would be as follows:

chkconfig --level 345 nfs off

Run level files:

Each service managed by chkconfig requires two or more lines of comments in the script under the corresponding init.d.

The first line tells chkconfig the default startup runlevel and the startup and shutdown priorities. If a service does not start at any runlevel by default, use-instead of the runlevel.

The second line describes the service, which can be commented with\cross-line.

For example, random.init contains three lines:

# chkconfig: 2345 20 80

# description: Saves and restores system entropy pool for \

# higher quality random number generation.

An additional introduction to the run-level concept of Linux systems:

Linux OS divides the operating environment into seven levels:

0: shutdown

1: Single user mode (single user, no network)

2: Multiuser mode without network support (multiuser, no network)

3: Multi-user mode with network support (multi-user, with network)

4: Reserved, unused

5: Multi-user mode with network support and X-Window support (multi-user, network, X-Window interface)

6: Reboot the system, i.e. restart

Linux has a variety of runlevels, common is the multi-user 2, 3, 4, 5, many people know that 5 is running X-Windows level, and 0 is shutdown. Run-level changes can be switched via the init command. For example, suppose you want to maintain the system into single-user state, then you can use init1 to switch. During the Linux run-level switch, the system automatically finds files starting with K and S in the directory/etc/rc[0-6].d corresponding to the run-level, and executes these scripts in the numerical order that follows. Maintaining these scripts is a tedious task, and Linux provides the chkconfig command to update and query system services at different run-levels.

Example:

1. View the status of services at various levels of implementation:

The code is as follows:

$chkconfig --list

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

The code is as follows:

$chkconfig --list vsftpd

3. At execution level 3, 5, turn off vsftpd system services:

copy code

The code is as follows:

$chkconfig --level 35 vsftpd off

4. At execution level 2, 3, 5, start vsftpd system service:

The code is as follows:

$chkconfig --level 235 vsftpd on

4.1. Restart vsftpd system service at execution level 2, 3, 5:

The code is as follows:

chkconfig --level 235 vsftpd restart

5. Turn off services you don't need:

If there is no printer:

The code is as follows:

$chkconfig --level 235 cups off

If there is no local area network:

The code is as follows:

$chkconfig --level 235 smb off

If remote user login is not required:

The code is as follows:

$chkconfig --level 235 sshd off

If no scheduled tasks are required:

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

View the process status of a particular system service, such as httpd:

The code is as follows:

$chkconfig --list | grep httpd

How do I add a service?

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

Second, chkconfig --add servicename is needed to add this service to the chkconfig tool's list of services, where it is given the K/S entry in/etc/rc.d/rcN.d.

Finally, you can modify the default startup level of the service as taught above.

How to start MySQL automatically under Linux?

First, make sure that/etc/rc.d/init.d/mysqld exists. If service mysqld starts normally, it means that the service exists.

(Note: If installed at rpm, the corresponding service is automatically registered in the/etc/rc.d/init.d directory).

Run command:

The code is as follows:

chkconfig --add mysqld

Run command:

The code is as follows:

chkconfig --level 345 mysqld on

rebooting

How to install the source code, how to make the software boot, Apache for example?

Install apache service under linux (install by downloading binaries, not rpm packages), apache service startup command:

/server/apache/bin/apachectl start 。Let apache service run below runlevel 3. The order reads 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 short for start, stands for start, K is short for kill, stands for close. The number 60 represents the order of activation.

Apache's content:

The code is as follows:

#!/ bin/bash

#Start httpd service

/server/apache/bin/apachectl start

At this point, the apache service can be started automatically at random at runlevel 3.

(Note: After creating the/etc/rc.d/init.d/apache file, you can actually adjust the startup service accordingly in combination with chkconfig.)

In addition, you can also write the startup command/server/apache/bin/apachectl start directly to the/etc/rc.d/rc.local file to achieve the purpose of starting!

After reading this article on how to use chkConfig under linux, many readers will definitely want to know more about it. For more industry information, you can pay attention to our industry information column.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report