Linux system provides a variety of system services (such as process management, log, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, Web hosting, data storage, file transfers, domain name resolution (using DNS), Dynamic IP address assignment (use DHCP), and so on). Technically, a service or a group of processes (commonly referred to as daemon) runs continuously in the background, waiting for a request (in particular a request from the client). Linux supports different approach to managing service (start, stop, restart, start automatically when the system starts, etc.), usually through the process or service manager. Most modern Linux distributions now use the same process manager: systemd. Systemd is the Linux system and service manager; alternatives to the init process, compatible with SysV and LSB init scripts, systemctl command is the primary tool for managing the systemd. In this guide, we will show how all of the following services are running under the systemd in Linux. In Linux SystemD following a service is running when you run without any parameters systemctl command, it displays a list of all systemd unit loaded (for more information about systemd unit, please read the systemd documentation), including the service, and display their status (is active)
systemct
To list all the services that are loaded on the system (whether it is active, running, quit or failure, use the list-units and sub-command --type switch, the value of service.
systemctl list-units --type=service
或者
systemctl --type=service
To list all loaded but active service, including service and have withdrawn the service is running, you can add --state option, its value is active, as shown below.
systemctl list-units --type=service --state=active
或者
systemctl --type=service --state=active
If you want to quickly view all the services that are running (that is, all loaded and running services), run the following command.
systemctl list-units --type=service --state=running
或者
systemctl --type=service --state=running
If you regularly use a command, you can create an alias command in ~ / .bashrc file
~ vim / .bashrc
add the following Alias running_services = ' systemctl List-Service Units --type = = running --state '
reload look at this file, can take effect immediately
source .bashrc
To determine the daemon program process is listening on the port, you can use netstat or ss tool, as shown. Flags -l which means print all the listening socket, -t displays all TCP connections, -u represent all UDP connections, -n means print digital port number (rather than the application name), - p represents the display name of the application.
netstat -ltup | grep mysqld.service
或者 ss -ltup | grep zabbix_agentd
The fifth column shows the socket: local address: port. In this case, the process zabbix_agentd is listening on port 10050. Also, if your server is running a firewall service, which controls how to block or allow traffic from or from a selected service or port, you can use the ufw firewall-cmd or command to list open ports in the firewall service, or (depending on on the Linux distribution you are using), as shown below.
firewall-cmd --list-services [FirewallD] firewall-cmd --list-ports sudo ufw status [UFW Firewall]
Summarize so far on the case! In this guide, we demonstrate how to view the running services under systemd under Linux. We also describe how to view and port services or open ports in the firewall system to check how the service is listening.
Original Address: https: //mp.weixin.qq.com/s/OzZ2hLTRM5zsT-p6WlVWdA