Linux service (service overview, view service, service management)

  Like the Windows system, the Linux system also has a variety of services. Some services are used to manage computers, such as dbusmessage bus services for communication between applications, services for connecting Bluetooth devices, bluetoothetc.; another part of services is dedicated to the server's external affairs, such as middleware Apache, databases, MySQLetc. In this section, we will get to know Linux services and learn about service management methods.

Service Classification

Service

  According to the installation method, services in Linux are mainly divided into services installed by default by the rpm package manager (some Linux distributions, such as Debian, etc. use the apt package manager) and services installed using source code packages (third-party services). The services installed by the rpm package manager can be divided into independent services and services based on the xinetdnetwork daemon service program according to the mode of action . The general service is independent service.

 Independent service

  Independent services are directly deployed in memory and respond directly to requests. The advantage is that it responds quickly, but the disadvantage is that it occupies more system resources when starting more services, and it xinetdis less safe than that.

 Xinetd-based services

xinetdAs a service, the network daemon service itself is also independently deployed directly in the memory and can manage a series of services. User requests will be xinetdforwarded to the corresponding service for processing through the process. The advantage is that the service takes up less system resources and xinetdis protected by a certain protection mechanism. It can protect the server from certain network attacks (DDOS, etc.).

Service start and self start

 Service start

  Service start/stop describes the current state of a service (same as Windows service), start means that the service is running and can provide related functions; stop means that the service is not currently running, and you need to start the service before you can use its functions

 Service starts automatically

  Whether the service starts automatically describes the startup type of a service (same as automatic/manual in Windows). Self-starting enables the service to start when the system is initialized.

View installed services

  There are two main ways to view the installed services, through file query and through command query

 Query by file

  You can view the installed services through the default location of the source package installation ( note that it is the default location, if you have additional settings, you need to view it in another location ). The default location is /usr/localthat the rpm package is installed in the default location, which is not convenient to view and generally uses -eoptions Uninstall (manual deletion is more cumbersome)

 Query by command

  Newer Linux distributions uniformly use systemctlcommands to view system-related content, and view information such as services and status. The syntax:

systemctl list-units #查看当前内存中的资源(UNIT)
systemctl list-unit-files #查看所有资源(包括在文件中未加载的)
systemctl list-units --type=TYPE #查看指定类型的资源
#其中TYPE为下面列表中的UNIT类型

Among them, UNIT(resources) includes all aspects of the system, the following is UNIT classification 1

Type Description
service service
device Hardware device file
mount Device mount point
automount Automatic device mount point
path Path resource
scope Non- systemddaemonic external process
slice Process group
socket Communication socket
swap Swap partition file
timer Timer

  You can also use servicecommands to view services, and you can only view services installed by non-source code packages

service #不加参数,查看服务列表;具体其他管理命令在下一节会讲到

  When the service command starts the service, check /etc/init.dthe service startup configuration in the directory, check the service status and make the startup action.

  Some (older) Linux distributions use chkconfigcommands to view the services installed by the RPM package

chkconfig --list

Source code package service management

 Start/stop of source package installation service

  The service installed through the source package is mainly started/stopped by calling the source package startup script through the absolute path (or environment variable) (see the installation instructions of the source package for the specific path or search according to the custom path). There may be some differences in the start/stop methods of different source code packages. For details, please check the description file of the source code package.

Example: Start the apache2service installed through the default path of the source package

/usr/local/apache2/bin/apachestl start|stop

  If you need to use the service command to start the service , you can link the service startup script to the /etc/init.ddirectory. The servicecommand starts the service by viewing the directory, so the link can also be started.


  1. Reference blog: https://www.cnblogs.com/zwcry/p/9602756.html ↩︎

Guess you like

Origin blog.csdn.net/Zheng__Huang/article/details/108113491