The so-called Linux services are applications running in the background of the system, and can provide some local system or network functions.

1. Classification of Linux services:

There are two main categories: services installed by default in RPM packages and services installed in source packages

The RPM package is a compiled software package that is installed in the default location of the system and can be identified by service management commands. These services can be divided into two types: one is an independent service that can be started by itself, such as Apache and FTP services. The other is the service based on the super daemon xinetd. The service cannot be started independently and needs to be invoked by xinetd.

The source code package is open source. The installation speed is slow and error prone after compilation and installation, but it is highly customizable. It is installed in a specified location (usually /usr/local/), and service management commands cannot be directly identified.

2. Service management of RPM package installed by default:

2.1. RPM package default installation directory:

D / : stores the startup scripts of all independent services in the same directory as /etc/rc.d/init.d/. You can use either directory.

/etc/sysconfig/ : stores the initialization environment configuration file of the service.

/etc/file: stores the configuration file of the service.

/etc/xinetd.conf/ : configuration file of the super daemon process xinetd.

/etc/xinetd.d/ : stores startup scripts for xinetd services.

/var/lib/ : default data storage directory. For example, the data of the mysql service installed by default in the RPM package is stored in the /var/lib/mysql.directory.

/var/log/ : the default log storage directory. For example, HTTPD service logs installed by default in RPM packages are stored in the /var/log/httpd/ directory.

2.2 Startup management of independent services:

Linux the default using the/etc/init. D/independent service name start | stop | restart | the status of independent service start, stop, restart, view state, as follows:

Red hat series system can use the service independent service name start | stop | restart | status to start, stop, restart, independent service to check the status, You can also use the service –status-all command to view the startup status of all individual services. The proprietary commands of other Linux distributions are different and will not be described here.

2.3 Self-start management of independent services:

Automatic startup means that services restart after the system restarts. There are two common Settings for self-booting:

1) can use the chkconfig command – level run level Independent service name on | off, as follows:

chkconfig --level 23456 redis on
 
chkconfig --level 6 redis off
Copy the code

You can run the chkconfig –list command to view all services installed by default and the self-start status of the RPM package.

2) by modifying the/etc/rc. D/rc. Local or/etc/rc. The local files, to join the service startup command, as follows: (the source code package installation service applies, so proposal unified set from the start the service in this mode. Note that it is independent of chkconfig and does not affect chkconfig –list changes)

#! /bin/bash ...... /etc/init.d/redis startCopy the code

2.4 Xinetd service-based startup management:

The xinetd super daemon process is not installed in the system by default.

yum -y install xinetd
Copy the code

After the installation is successful, run the chkconfig –list command to view the xinetd service:

For xinetd-based services, modify the configuration file of the service, for example, the Telnet service. Change disable to no in the /etc/xinetd.d/ Telnet file, and then restart the xinetd service. Run the service xinetd restart command.

2.5 Xinetd service-based self-start management:

Through the chkconfig service name on | off command to set the start switch, based on the xinetd service, need not specify – level, such as:

chkconfig telnet on
Copy the code

3, source package installation service management

3.1 Start management of source package service

To install the apache service in /usr/local/, run the following command:

/usr/local/apache2/bin/apachectl start | stop | restart
Copy the code

3.2 Self-start management of source package services

/etc/rc.d/rc.local /rc.d/rc.local /etc/rc.d/rc.local

#! /bin/bash ...... Touch the/var/lock/subsys/local # example: since the launch of add source package installation of apache service to/usr/local/apache2 / bin/apachectl startCopy the code