当前位置:首页 » 硬件·内核·Shell·监测 » Systemctl
Systemctl命令
systemctl命令Systemd是一个系统管理守护进程、工具和库的集合,用于取代System 初始进程。Systemd的功能是用于集中管理和配置类UNIX系统
1. 首先检查你的系统中是否安装有systemd并确定当前安装的版本
# systemctl --version systemd 215 +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
2. 检查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
3. 检查systemd是否运行
# ps -eaf | grep [s]ystemd root 1 0 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 23 root 444 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-journald root 469 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-udevd root 555 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-logind dbus 556 1 0 16:27 ? 00:00:00 /bin/dbus-daemon --system --address=systemd: -- nofork --nopidfile --systemd-activation
4. 分析systemd启动进程
# systemd-analyze Startup finished in 487ms (kernel) + 2.776s (initrd) + 20.229s (userspace) = 23.493s
5. 分析启动时各个进程花费的时间
# systemd-analyze blame 8.565s mariadb.service 7.991s webmin.service 6.095s postfix.service 4.311s httpd.service 3.926s firewalld.service 3.780s kdump.service 3.238s tuned.service 1.712s network.service 1.394s lvm2-monitor.service 1.126s systemd-logind.service
6. 分析启动时的关键链
# systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
multi-user.target @20.222s
└─mariadb.service @11.657s +8.565s
7. 列出所有可用单元
# 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
8. 列出所有服务(包括启用的和禁用的)
# systemctl list-unit-files --type=service UNIT FILE STATE arp-ethers.service disabled auditd.service enabled autovt@.service disabled blk-availability.service disabled brandbot.service static collectd.service disabled console-getty.service disabled console-shell.service disabled cpupower.service disabled crond.service enabled dbus-org.fedoraproject.FirewallD1.service enabled
9. 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 # systemctl kill httpd # systemctl status httpd
10. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态
# systemctl start tmp.mount # systemctl stop tmp.mount # systemctl restart tmp.mount # systemctl reload tmp.mount # systemctl status tmp.mount
11.服务的CPU利用率(分配额)
#获取当前某个服务的CPU分配额
systemctl show -p CPUShares httpd.service
CPUShares=1024
#将某个服务(httpd.service)的CPU分配份额限制为2000 CPUShares/
systemctl set-property httpd.service CPUShares=2000
systemctl show -p CPUShares httpd.service
CPUShares=2000
#检查某个服务的所有配置细节
systemctl show httpd
#分析某个服务(httpd)的关键链
systemd-analyze critical-chain httpd.service
#获取某个服务(httpd)的依赖性列表
systemctl list-dependencies httpd.service
#
12.控制系统运行等级
#启动系统救援模式
systemctl rescue
Broadcast message from root@tecmint on pts/0 (Wed 2015-04-29 11:31:18 IST):
The system is going down to rescue mode NOW!
#进入紧急模式
systemctl emergency
Welcome to emergency mode! After logging in, type "journalctl -xb" to view
system logs, "systemctl reboot" to reboot, "systemctl default" to try again
to boot into default mode.
#列出当前使用的运行等级
systemctl get-default
multi-user.target