Linux系统服务管理

       在 Linux 系统中,服务(或者进程)的管理通常使用如下工具:

1. Systemd

Systemd 是现代 Linux 发行版中用于管理系统和服务的默认工具。它用于启动和管理服务、处理系统日志等。

  • 查看服务状态
    systemctl status <服务名>

    例如,查看 nginx 服务的状态:

    systemctl status nginx 
  • 启动服务
    systemctl start <服务名>

    启动 nginx 服务:

    systemctl start nginx 
  • 停止服务
    systemctl stop <服务名>

    停止 nginx 服务:

    systemctl stop nginx 
  • 重启服务
    systemctl restart <服务名>

    重启 nginx 服务:

    systemctl restart nginx 
  • 启用服务开机自启
    systemctl enable <服务名>

    启用 nginx 服务开机自启:

    systemctl enable nginx 
  • 禁用服务开机自启
    systemctl disable <服务名>

    禁用 nginx 服务开机自启:

    systemctl disable nginx 
  • 查看所有服务的状态
    systemctl list-units --type=service

2. Service 命令

        在一些较老的 Linux 发行版中,service 命令用于管理服务。虽然新系统推荐使用 systemd,但在一些发行版中 service 命令仍然存在,作为 systemctl 的前端。

  • 查看服务状态

    service <服务名> status 
  • 启动服务

    service <服务名> start 
  • 停止服务

    service <服务名> stop 
  • 重启服务

    service <服务名> restart 

3. Init.d 脚本

        在更老的 Linux 发行版中,/etc/init.d/ 目录包含了服务启动脚本。这些脚本通常通过 service 命令调用,但在某些系统中,仍然可以直接使用。

例如:

/etc/init.d/nginx start /etc/init.d/nginx stop 

4. 查看进程

除了管理服务,查看服务或进程是否正在运行也非常重要。可以使用以下命令来查找服务或进程:

  • 查看服务的进程

    ps aux | grep <服务名> 
  • 查看进程状态

    top 
  • 查看所有运行的服务

    systemctl list-units --type=service 

总结

  • 现代 Linux 系统:使用 systemdsystemctl 命令。
  • 较旧系统:使用 serviceinit.d 脚本。

你可能感兴趣的:(Linux,国产化,信管通,linux,运维,服务器)