Linux常用指令05systemd

1次阅读

共计 1143 个字符,预计需要花费 3 分钟才能阅读完成。

systemd

即 system deamon,是 Linux 下的 init 软件,绝大多数的开源不同发行版的 linux 都支持,包括 redhat、ubuntu、centos 等。systemd 是一组指令的集合,其中最主要的是 systemctl 命令

1. systemctl 主命令

1.1 常用命令

systemctl 是 system 的主命令,用与管理系统和服务;
man systemctl 查看 systemctl 的帮助文档

  • systemctl reboot 重启
  • systemctl poweroff 关闭系统、切断电源
  • systemctl halt CPU 停止工作
  • systemctl start httpd.service 启动 httpd 服务
  • systemctl stop httpd.service 关闭服务
  • systemctl restart httpd.service 重启服务
  • systemctl kill httpd.service 关闭 httpd 服务下的所有子进程
  • systemctl enable httpd.service 开机启动 httpd
  • systemctl disable httpd.service 禁止开机启动 httpd
  • 修改某服务配置文件

    1. systemctl daemon-reload 重新加载配置
    2. systemctl restart httpd.service 重启才能生效

1.2 unit 的认知

unit 概念:systemd 可以管理所有的系统资源。不同的资源统称为 unit 单位

  1. unit 一共分为 12 类

    1. service 系统服务
    2. target 多个 unit 构成的一个组
    3. device 硬件设备
    4. mount 文件系统的挂载点
    5. automount 自动挂载点
    6. path 文件或路径
    7. scope 不是由 systemd 启动的外部进程
    8. slice 进程组
    9. snapshot 快照
    10. socket 进程间的通信的 socket
    11. swap swap 文件
    12. timer 定时器
  2. unit 相关的命令

    • systemctl list-units 列出正在运行的 unit
    • systemctl list-units --type=service 列出所有正在运行、类型为 service 的服务
    • systemctl list-units --all 列出所有的 unit,包没有找到配置文件或启动失败的
    • systemctl list-units --failed 列出所有加载失败的服务
    • systemctl list-units --all --state=inactive 列出所有没有运行的 unit

2. systemd-analyze 查看启动耗时

3. hostnamectl 查看和设置主机信息

  • hostnamectl set-hostname [newhostname] 设置主机名

4. localectl 查看和设置本地化信息

5. timedatectl 查看和设置当前时区

6. loginctl 查看当前登录用户

正文完
 0