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

The usage of chkconfig Command in Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the relevant knowledge of "how to use the chkconfig command under the Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Chkconfig command can be used to check and set up various services of the system.

Use syntax:

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

Parameter usage:

-- add à adds the specified system service to allow the chkconfig instruction to manage it, and at the same time adds relevant data to the narrative file started by the system.

-- del à deletes the specified system service and is no longer managed by the chkconfig instruction, and deletes the relevant data in the narrative file started by the system.

-- level à specifies at which execution level the read system service will be turned on or off.

Examples of use:

Chkconfig-list lists all system services

Chkconfig-add httpd adds httpd services

Chkconfig-del httpd deletes the httpd service

Chkconfig-level httpd 2345 on makes httpd on at runtime levels 2, 3, 4, and 5.

The chkconfig command provides an easy way to set the run level of a service. For example, to set up the MySQL server to run at runlevels 3 and 4, you must first add MySQL as a service managed by chkconfig:

The code is as follows:

Chkconfig-add mysql

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

The code is as follows:

Chkconfig-level 35 mysql on

Set to off at other levels

The code is as follows:

Chkconfig-level 01246 mysql off

To make sure that your configuration has been modified correctly, we can list the running levels at which the service will run, as shown below:

The code is as follows:

# chkconfig-list mysql

Mysql 0:off 1:off 2:off 3:on 4:off 5:on 6:off

The Chkconfig command is used to set, view, or change the configuration of a service that starts automatically on boot. Here are seven practical examples to illustrate the use of the Chkconfig command.

1. Check the startup item status of the service system with Shell script

When you execute the chkconfig command with only the service name, it returns true if the service has been configured to the system startup item. The following code snippet is used to check whether a service has been configured to boot.

The code is as follows:

# vi check.sh

Chkconfig network & & echo "Network service is configured"

Chkconfig junk & & echo "Junk service is configured"

The code is as follows:

#. / check.sh

Network service is configured

You can also specify to check whether the service is configured to the specified runtime level.

The code is as follows:

# vi check1.sh

Chkconfig network-level 3 & & echo "Network service is configured for level 3"

Chkconfig network-level 1 & & echo "Network service is configured for level 1"

The code is as follows:

#. / check1.sh

Network service is configured for level 3

2. View the status of the startup items of the current service system

The-list option is used to display the status of the system startup items for all current services.

The code is as follows:

# chkconfig-list

Abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off

Acpid 0:off 1:off 2:off 3:off 4:off 5:off 6:off

Atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off

...

You can use grep filtering to display services with specified criteria.

The following command indicates that only services at run level 3 are displayed.

The code is as follows:

Chkconfig-- list | grep 3:on

The following command indicates that only the startup status of the network service is displayed.

The code is as follows:

Chkconfig-- list | grep network

3. Add a new service to the startup item

Use the-add option to add a specified service to the list of system startup services.

The following example shows how to add a new service, such as iptables, to the list of services that need to be booted. The "chkconfig-add" command also automatically turns on runlevels 2, 3, 4 and 5, as follows:

The code is as follows:

# chkconfig-- list | grep iptables

# chkconfig-add iptables

# chkconfig-- list | grep iptables

Iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

4. Remove a service from the list of system startup items

The following example shows that ip6tables has been configured to the startup item.

The code is as follows:

# chkconfig-- list | grep ip6tables

Ip6tables 0:off 1:off 2:off 3:on 4:off 5:off 6:off

Use the-del option to remove it from the startup list.

The code is as follows:

# chkconfig-del ip6tables

# chkconfig-- list | grep ip6tables

5. Turn the selected runlevel on or off for the service

Sometimes you may not want to remove the entire service from the startup list, but you may just want to turn off the specified runtime.

The following example is shutting down run-level 5. 0 for nfserver services.

The code is as follows:

# chkconfig-- level 5 nfsserver off

You can also turn off multiple runlevels at the same time, below is to turn off runlevels 3 and 5.

The code is as follows:

# chkconfig-- level 35 nfsserver off

6. Script files in the rc.d subdirectory

Whenever you use the chkconfig command to add or remove a service, it performs certain actions in the / etc/ rc.d subdirectory.

When the chkconfig-add command is executed, it creates a matching link file in the corresponding rc directory to start and stop the service.

When the chkconfig-del command is executed, it removes the corresponding symbolic link in the corresponding rc directory.

The following example shows that the xinetd service has runlevels 3 and 5 turned on, so xinetd will have two files in the rc3.d directory and two files in the rc5.d directory. Files that begin with K are used when shutting down (K for kill). Files that start with S are powered on (S stands for start).

The code is as follows:

# chkconfig-- list | grep xinetd

Xinetd 0:off 1:off 2:off 3:on 4:off 5:on 6:off

Xinetd based services:

The code is as follows:

# cd / etc/rc.d/rc3.d

# ls | grep xinetd

K08xinetd

S14xinetd

The code is as follows:

# cd / etc/rc.d/rc5.d

# ls | grep xinetd

K08xinetd

S14xinetd

7. Add operation to change the rcx.d directory

When you add a new service through the chkconfig command, the default runtime automatically turns on the service and creates files in the corresponding rcx directory.

For example, if the nfsserver service is not in the startup items list, then the nfsserver service has no files in the / etc/rc.d/rc*.d directory.

The code is as follows:

# chkconfig-- list | grep nfsserver

Nfsserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off

The code is as follows:

# ls / etc/rc.d/rc3.d | grep nfsserver

# ls / etc/rc.d/rc5.d | grep nfsserver

After you add the nfsserver service, you will see symbolic links in these directories.

The code is as follows:

# chkconfig-add nfsserver

Nfsserver 0:off 1:off 2:off 3:on 4:off 5:on 6:off

The code is as follows:

# cd / etc/rc.d/rc3.d

# ls-l | grep nfsserver

Lrwxrwxrwx 1 root root 12 2011-06-18 00:52 K08nfsserver->.. / nfsserver

Lrwxrwxrwx 1 root root 12 2011-06-18 00:52 S14nfsserver->.. / nfsserver

The code is as follows:

# cd / etc/rc.d/rc5.d

# ls-l | grep nfsserver

Lrwxrwxrwx 1 root root 12 2011-06-18 00:52 K08nfsserver->.. / nfsserver

Lrwxrwxrwx 1 root root 12 2011-06-18 00:52 S14nfsserver->.. / nfsserver

When you use the-del or-level option to turn off the service, the corresponding symbolic link file in the rcx.d directory will be deleted.

The code is as follows:

# chkconfig-- level 5 nfsserver off

# ls / etc/rc.d/rc5.d | grep nfsserver

This is the end of the content of "how to use the chkconfig command under the Linux system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Servers

Wechat

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

12
Report