zoukankan      html  css  js  c++  java
  • 管理开机启动:systemd

    一、CentOS7 systemd 介绍

    在 CentOS7 中,使用 systemd 来管理其他服务是否开机启动,systemctl 是 systemd 服务的命令行工具

    [root@localhost ~]$ systemctl start httpd.service         # 启动服务
    [root@localhost ~]$ systemctl stop httpd.service          # 关闭服务
    [root@localhost ~]$ systemctl restart httpd.service       # 重启服务
    [root@localhost ~]$ systemctl status httpd.service        # 查看服务状态
    [root@localhost ~]$ systemctl is-enabled httpd.service    # 查看指定的服务是否开机启动
    [root@localhost ~]$ systemctl enable httpd.service        # 设置指定的服务开机启动
    [root@localhost ~]$ systemctl disable httpd.service       # 设置指定的服务开机不启动

    二、CentOS7 unit 介绍

    (1) CentOS7 中新增了 unit(单元)的概念,它是系统所有资源的统称,不同的资源称为不同的 unit(单元)
    (2) 常见的 unit 有:Service Unit ( 系统服务 ) 、Device Unit ( 硬件设备 ) 、Path Unit ( 文件或路径 ) 等等
    (3) Systemd 用来管理这些单元,它保存了系统服务、硬件设备、挂载点等单元的配置文件,并能够处理不同单元之间的依赖关系
    (4) 单元的状态:active 、inactive 、activing 、deactiving ,分别表示正在运行 、已经停止运行 、正在启动 、正在停止

    [root@localhost ~]$ systemctl list-units                        # 列出正在运行的unit
    [root@localhost ~]$ systemctl list-units --all                  # 列出所有状态的unit
    [root@localhost ~]$ systemctl list-units --all --state=active   # 列出指定状态的unit
    [root@localhost ~]$ systemctl list-units --type=service         # 列出指定类型的unit

    三、CentOS7 target 介绍

    (1) target 其实就是一组 unit 组合,CentOS7 的 target 相当于 CentOS6 的 runlevel ( 运行级别 ) ,启动一个 target,就相当于启动多个 unit
    (2) 一个 service 属于一种类型的 unit ,多个 unit 可以组成一个 target ,一个 target 包含了多个 service

    [root@localhost ~]$ ll /usr/lib/systemd/system/
    lrwxrwxrwx. 1 root root   15 1月  15 10:39 runlevel0.target -> poweroff.target
    lrwxrwxrwx. 1 root root   13 1月  15 10:39 runlevel1.target -> rescue.target
    lrwxrwxrwx. 1 root root   17 1月  15 10:39 runlevel2.target -> multi-user.target
    lrwxrwxrwx. 1 root root   17 1月  15 10:39 runlevel3.target -> multi-user.target
    lrwxrwxrwx. 1 root root   17 1月  15 10:39 runlevel4.target -> multi-user.target
    lrwxrwxrwx. 1 root root   16 1月  15 10:39 runlevel5.target -> graphical.target
    lrwxrwxrwx. 1 root root   13 1月  15 10:39 runlevel6.target -> reboot.target
    [root@localhost ~]$ systemctl get-default                            # 查看当前系统默认的target
    [root@localhost ~]$ systemctl list-unit-files --type=target          # 列出所有target
    [root@localhost ~]$ systemctl list-dependencies multi-user.target    # 查看指定target下有哪些unit

        

          

  • 相关阅读:
    Compoer的应用
    memcache的简单使用示例
    windows下安装Memcached服务器,PHP的memcache扩展
    jQuery跨域
    git常用基本命令
    Linux常用命令总结
    修改MySQL数据库密码
    Linux配置LNMP环境(三)配置MySQL
    django之多表查询与创建
    django之单表操作
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10312496.html
Copyright © 2011-2022 走看看