概述
Linux 系统服务有时也称为守护程序,是在Linux启动时自动加载并在Linux退出时自动停止的系统任务。
在本文中,良许将为大家介绍如何列出 Linux 系统里所有运行的服务,以及如何检查某个服务的当前状态。
Centos/RHEL 7.X 的 systemd 系统服务查看
CentOS 7.x开始,CentOS开始使用 systemd 服务来代替 daemon ,原来管理系统启动和管理系统服务的相关命令全部由 systemctl 命令来代替。
systemctl list-unit-files
命令的输出结果如下:

查看所有运行着的 systemd 服务可以运行以下命令:
systemctl | more
命令的输出结果如下:

除此之外,你还可以使用以下命令:
systemctl list-units --type service
命令的输出结果如下:

如果你想要在结果里搜索某个特定的服务,可以使用管道及 grep 命令。
systemctl | grep "apache2"
命令的输出结果如下:

使用 netstat 命令查看系统服务
Netstat 命令是用来检查活动的网络连接、接口统计分析,以及路由表状态。这个命令在所有的 Linux 发行版都可用,我们接下来就用它来查看系统服务。
查看服务及它们所监听的端口:
netstat -pnltu
命令的输出结果如下:

通过系统服务配置文件查看系统服务
服务的配置文件是 /etc/services 是一个 ASCII 文件,它包含了一系列的用户程序可能用到的服务。在这个文件里,包括了服务名称,端口号,所使用的协议,以及一些别名。
对于这个文件,我们可以使用任意的文本工具查看,比如 vim :
vim /etc/services
命令的输出结果如下:

查看 systemd 服务状态
在一些新版的 Linux 系统,已经有些用 systemd 来取代 init 进程了。在这种系统里,如何去查看系统服务呢?我们可以使用以下语法:
systemctl status service_name
比如说,查看你系统上的 OpenSSH 是否在运行,可以运行:
systemctl status sshd
命令的输出结果如下:

或者,你也可以使用以下命令格式去查看某个服务是否正在运行:
systemctl is-active service_name
如果使用这条命令的话,实现上面那个例子对应的命令为:
systemctl is-active sshd
命令的输出结果如下:

同时,你也可以查看一个服务是否已经被使能了,可以使用以下命令:
systemctl is-enabled service_name
比如,检查 OpenSSH 服务是否已经使能,可能输入以下命令:
systemctl is-enabled sshd
命令的输出结果如下:

早期版本的服务状态查看
其实也不能说早期,现在依然还有很多这样的系统,上面跑着 SysV init 进程。对于这种系统,查看服务状态的命令为:
service service_name status
还是查看 OpenSSH 状态的例子,对应的命令为:
service sshd status
命令的输出结果如下:

你也可以使用以下命令来查看所有的服务状态:
chkconfig --list
命令的输出结果如下:

最后
以上就是精明往事为你收集整理的centos io 查看程序_查看 Linux 系统服务的 5 大方法Centos/RHEL 7.X 的 systemd 系统服务查看使用 netstat 命令查看系统服务通过系统服务配置文件查看系统服务查看 systemd 服务状态早期版本的服务状态查看的全部内容,希望文章能够帮你解决centos io 查看程序_查看 Linux 系统服务的 5 大方法Centos/RHEL 7.X 的 systemd 系统服务查看使用 netstat 命令查看系统服务通过系统服务配置文件查看系统服务查看 systemd 服务状态早期版本的服务状态查看所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复