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 脚本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值