• Centos 服务的常用命令


    Centos 6(以下均以httpd服务为例)

      开启服务:

        service httpd start

      关闭服务:

        service httpd stop

      服务状态:

        service httpd status

      开机服务自启动

        chkconfig httpd on

      开机服务禁止启动

        chkconfig httpd off 

    Centos 7 (httpd 就行了,默认后缀会补充.service)

      开启服务:

        systemctl start httpd

      关闭服务:

        systemctl stop httpd

      服务状态

        systemctl status httpd

      同时开启多个服务

        systemctl start httpd nginx

    勿启动服务,用于多个功能差不多的服务,但是又不能删除的服务,以防不知情人员误启动导致相同端口服务冲突。

      禁止自动和手动启动服务

        systemctl mask httpd.service

    systemctl 依赖服务没启动,也是可与启动该服务的,centos 6 就不行,需要手动去启动该服务

      取消禁止

        systemctl unmask httpd.service

     查看服务当前激活与否的状态,不显示其他多余的信息(可用于脚本判断)

        systemctl is-active httpd

     查看所有已经激活的服务: (|表示二选一都可以)

        systemctl list-units --type|-t service

     查看服务是否开机自启:
        systemctl is-enabled name.service
    其它命令:
      查看服务的依赖关系:
        systemctl list-dependencies name.service
      杀掉进程:
        systemctl kill httpd

       查看所有服务:(|表示二选一都可以)
        systemctl list-units --type service --all|-a
          oaded Unit    配置文件已处理
          active(running)   一次或多次持续处理的运行
          active(exited)    成功完成一次性的配置
          active(waiting)    运行中,等待一个事件
          inactive       不运行
          enabled       开机启动
          disabled       开机不启动
          static          开机不启动,但可被另一个启用的服务激活

    显示所有单元状态
      systemctl 或 systemctl list-units
    只显示服务单元的状态
      systemctl --type=service
    显示sshd服务单元
      systemctl –l status sshd.service
    验证sshd服务当前是否活动
      systemctl is-active sshd
    启动,停止和重启sshd服务
      systemctl start sshd.service
      systemctl stop sshd.service
      systemctl restart sshd.service

    重新加载配置
      systemctl reload sshd.service
    列出活动状态的所有服务单元
      systemctl list-units --type=service
    列出所有服务单元
      systemctl list-units --type=service --all
    查看服务单元的启用和禁用状态
      systemctl list-unit-files --type=service
    列出失败的服务
      systemctl --failed --type=service

    列出依赖的单元
      systemctl list-dependencies sshd
    验证sshd服务是否开机启动
      systemctl is-enabled sshd
    禁用network,使之不能自动启动,但手动可以
      systemctl disable network
    启用network
      systemctl enable network
    禁用network,使之不能手动或自动启动
      systemctl mask network
    启用network
      systemctl unmask network

    注:systemctl 仅仅能支持systemctl控制的服务,例如开机自动启动httpd服务,通过systemctl status httpd 看到的不一定是准确的信息

  • 相关阅读:
    Spring-Boot:多种配置注入方式
    Spring-Boot:Profile简单示例
    Spring-Boot:拦截器注解范例
    Docker:镜像的迁移
    YARN的内存和CPU配置
    Spark On YARN内存分配
    Spark配置参数
    linux_密钥
    分布式架构高可用架构篇_04_Keepalived+Nginx实现高可用Web负载均衡
    PythonDay01
  • 原文地址:https://www.cnblogs.com/alexlv/p/13431865.html
Copyright © 2020-2023  润新知