良许Linux教程网 干货合集 Linux 下systemctl详解

Linux 下systemctl详解

systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程,尽可能更多进程并发启动,下面良许教程网为大家详细讲解一下Linux 下systemctl。

systemctl 常用 命令

Systemd的版本

 systemd --version

systemd和systemctl的二进制文件和库的安装位置

 # whereis systemd 
 ​
 systemd: /usr/lib/systemd /etc/systemd /usr/share/systemd /usr/share/man/man1/systemd.1.gz
 ​
 # whereis systemctl
 ​
 systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz

列出所有可用的单位

 # systemctl list-unit-files
 ​
 UNIT FILE                                   STATE   
 ​
 proc-sys-fs-binfmt_misc.automount           static  
 ​
 dev-hugepages.mount                         static  
 ​
 dev-mqueue.mount                            static  
 ​
 proc-sys-fs-binfmt_misc.mount               static  
 ​
 sys-fs-fuse-connections.mount               static  
 ​
 sys-kernel-config.mount                     static  
 ​
 sys-kernel-debug.mount                      static  
 ​
 tmp.mount                                   disabled
 ​
 brandbot.path                               disabled
 ​
 .....

列出所有运行单元

 # systemctl list-units
 ​
 UNIT                                        LOAD   ACTIVE SUB       DESCRIPTION
 ​
 proc-sys-fs-binfmt_misc.automount           loaded active waiting   Arbitrary Executable File Formats File Syste
 ​
 sys-devices-pc...0-1:0:0:0-block-sr0.device loaded active plugged   VBOX_CD-ROM
 ​
 sys-devices-pc...:00:03.0-net-enp0s3.device loaded active plugged   PRO/1000 MT Desktop Adapter
 ​
 sys-devices-pc...00:05.0-sound-card0.device loaded active plugged   82801AA AC'97 Audio Controller
 ​
 sys-devices-pc...:0:0-block-sda-sda1.device loaded active plugged   VBOX_HARDDISK
 ​
 sys-devices-pc...:0:0-block-sda-sda2.device loaded active plugged   LVM PV Qzyo3l-qYaL-uRUa-Cjuk-pljo-qKtX-VgBQ8
 ​
 sys-devices-pc...0-2:0:0:0-block-sda.device loaded active plugged   VBOX_HARDDISK
 ​
 sys-devices-pl...erial8250-tty-ttyS0.device loaded active plugged   /sys/devices/platform/serial8250/tty/ttyS0
 ​
 sys-devices-pl...erial8250-tty-ttyS1.device loaded active plugged   /sys/devices/platform/serial8250/tty/ttyS1
 ​
 sys-devices-pl...erial8250-tty-ttyS2.device loaded active plugged   /sys/devices/platform/serial8250/tty/ttyS2
 ​
 sys-devices-pl...erial8250-tty-ttyS3.device loaded active plugged   /sys/devices/platform/serial8250/tty/ttyS3
 ​
 sys-devices-virtual-block-dm\x2d0.device    loaded active plugged   /sys/devices/virtual/block/dm-0
 ​
 sys-devices-virtual-block-dm\x2d1.device    loaded active plugged   /sys/devices/virtual/block/dm-1
 ​
 sys-module-configfs.device                  loaded active plugged   /sys/module/configfs
 ​
 ...

检查单元是否启用?

 [root@10 ~]# systemctl is-enabled kubelet
 ​
 enabled

检查单元或服务是否正在运行?

 [root@10 ~]# systemctl status kubelet -l
 ​
 ● kubelet.service - kubelet: The Kubernetes Node Agent
 ​
    Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
 ​
   Drop-In: /etc/systemd/system/kubelet.service.d
 ​
            └─10-kubeadm.conf
 ​
    Active: active (running) since Sat 2019-11-16 02:33:56 CST; 1 weeks 1 days ago
 ​
      Docs: https://kubernetes.io/docs/
 ​
  Main PID: 566971 (kubelet)
 ​
    Memory: 90.4M
 ​
    CGroup: /system.slice/kubelet.service
 ​
            └─566971 /usr/bin/kubelet 
 ​
 --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf 
 ​
 --kubeconfig=/etc/kubernetes/kubelet.conf 
 ​
 --config=/var/lib/kubelet/config.yaml 
 ​
 --cgroup-driver=cgroupfs 
 ​
 --network-plugin=cni 
 ​
 --pod-infra-container-image=10.10.101.175/k8s-deploy/pause:3.1 
 ​
 --system-reserved=memory=782Mi 
 ​
 --system-reserved-cgroup=/system.slice

如何在Linux中启动,重新启动,停止,重新加载和检查服务(httpd.service)的状态

 # systemctl start httpd.service
 ​
 # systemctl restart httpd.service
 ​
 # systemctl stop httpd.service
 ​
 # systemctl reload httpd.service
 ​
 # systemctl status httpd.service

如何在引导时激活服务并启用或禁用服务(系统引导时自动启动服务)

 # systemctl is-active httpd.service
 ​
 # systemctl enable httpd.service
 ​
 # systemctl disable httpd.service

以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你!

137e00002230ad9f26e78-265x300

本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部