systemctl

systemctl是一个systemd工具,Systemd是一个系统管理守护进程、工具和库的集合
systemd作为父守护进程运行(PID = 1)
systemd与init进程的区别
它与init进程的主要差别如下。
(1)默认的 RunLevel(在/etc/inittab文件设置)现在被默认的 Target 取代,位置是/etc/systemd/system/default.target,通常符号链接到graphical.target(图形界面)或者multi-user.target(多用户命令行)。
(2)启动脚本的位置,以前是/etc/init.d目录,符号链接到不同的 RunLevel 目录 (比如/etc/rc3.d、/etc/rc5.d等),现在则存放在/lib/systemd/system和/etc/systemd/system目录。
(3)配置文件的位置,以前init进程的配置文件是/etc/inittab,各种服务的配置文件存放在/etc/sysconfig目录。现在的配置文件主要存放在/lib/systemd目录,在/etc/systemd目录里面的修改可以覆盖原始设置。


基础命令

查看systemd版本:systemd --version
查看systemd的二进制文件和库的安装位置:whereis systemd
查看\systemctl的二进制文件和库的安装位置:whereis systemctl
分析systemd启动过程: systemd-analyze
分析每个进程在引导时花费的时间:systemd-analyze blame
分析启动时的关键链: systemd-analyze critical-chain
按层次列出控制组:systemd-cgls
根据CPU,内存,输入和输出列出控制组:systemd-cgtop
列出所有运行单元:systemctl list-units
列出所有失败的单元:systemctl --failed


list-unit-files

在/usr/lib/systemd/system/目录下包含四种类型文件.mount,.service,.target,.wants
列出所有可用的单元:systemctl list-unit-files
列出所有mount:systemctl list-unit-files --type=mount
列出所有socket:systemctl list-unit-files --type=socket
列出所有service:systemctl list-unit-files --type=service


service

systemctl会根据/usr/lib/systemd/system/下的service启动相应的进程

列出所有service:systemctl list-unit-files --type=service
分析service的关键链:systemd-analyze critical-chain httpd.service
获取service的依赖项列表:systemctl list-dependencies httpd.service
service启动,重启,停止…

# systemctl start httpd.service   //启动
# systemctl restart httpd.service //重启
# systemctl stop httpd.service    //停止
# systemctl reload httpd.service  //重新加载
# systemctl status httpd.service  //状态
# systemctl enable httpd.service  //启用
# systemctl disable httpd.service //禁止
# systemctl is-enabled httpd.service //是否启用
# systemctl mask httpd.service     //屏蔽服务
# systemctl unmask httpd.service     //取消屏蔽服务
# systemctl show httpd             //检查service详细信息

获取service当前cpu份额:systemctl show -p CPUShares httpd.service
将service的cpu份额限制为2000:systemctl set-property httpd.service CPUShares=2000
注意:为服务设置CPUShare时,会创建一个名为service的目录(httpd.service.d),其中包含一个包含CPUShare Limit信息的文件90-CPUShares.conf


创建一个新的service

  1. add /lib/systemd/system/af_watchdog.service
    watchdog_daemon是service要启动的程序,af_recovery.sh是watchdog_daemon执行的脚本
    [Unit]
    Description=Little Kernel Watchdog

    [Service]
    Type=simple
    ExecStart=/usr/sbin/watchdog_daemon -f /usr/local/share/af_watchdog/af_recovery.sh
    Restart=on-failure
    RestartSec=3s

    [Install]
    WantedBy=multi-user.target
  1. execute command to enable af_watchdog by systemctl
    systemctl enable af_watchdog.service
    systemctl start af_watchdog.service
    systemctl staus af_watchdog.service

参考文章

  1. systemctl
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luckywang1103

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值