systemd
주요 명령어
systemd
를 위한 주요 명령어는 다음과 같습니다.
- systemctl
- systemd-analyze
- systemd-cgls
- systemd-cgtop
- systemd-loginctl
systemctl
존재하는 전체 서비스 목록을 출력해 줍니다.
$ systemctl
...
ipmi.service loaded active exited IPMI Driver
ipmievd.service loaded failed failed Ipmievd Daemon
irqbalance.service loaded active running irqbalance daemon
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
kubelet.service loaded active running kubelet: The Kubernetes Node Agent
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
network.service loaded failed failed LSB: Bring up/down networking
noms_nsight.service loaded active exited SYSV: noms_nsight
noms_nsight_jp.service loaded active exited SYSV: noms_nsight
nscd.service loaded active running Name Service Cache Daemon
ntpdate.service loaded active exited Set time via NTP
prov2-line-agent.service loaded active running PROV2 agent
rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg
rhel-domainname.service loaded active exited Read and set NIS domainname from /etc/sysconfig/network
rhel-import-state.service loaded active exited Import network configuration from initramfs
rhel-readonly.service loaded active exited Configure read-only root support
...
변경한 서비스 설정 정보를 데몬에 반영합니다.
$ systemctl daemon-reload
서비스를 활성화합니다.
$ systemctl enable [서비스명]
서비스를 비활성화합니다.
$ systemctl disable [서비스명]
서비스 활성화 여부를 출력해 줍니다.
$ systemctl is-enabled [서비스명]
enabled
서비스를 시작합니다.
$ systemctl start [서비스명]
서비스를 종료합니다.
$ systemctl stop [서비스명]
서비스를 재시작합니다.
$ systemctl restart [서비스명]
서비스를 갱신합니다.
$ systemctl reload [서비스명]
- 서비스 현재 동작 여부를 출력해 줍니다.
$ systemctl is-active [서비스명] active
- 서비스의 자세한 상태를 출력해 줍니다.
$ systemctl status -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 Wed 2018-12-26 14:14:53 JST; 5 months 21 days ago Docs: https://kubernetes.io/docs/ Main PID: 77429 (kubelet) Tasks: 24 Memory: 68.2M CGroup: /system.slice/kubelet.service └─77429 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=cgroupfs --cni-bin-dir=/opt/cni/bin --cni-conf-dir=/etc/cni/net.d --network-plugin=cni
서비스 이름과 활성화 여부를 출력해 줍니다.
$ systemctl list-unit-files
...
initrd-udevadm-cleanup-db.service static
ip6tables.service disabled
ipmi.service enabled
ipmievd.service enabled
iprdump.service disabled
iprinit.service disabled
iprupdate.service disabled
ipsec.service disabled
iptables.service enabled
irqbalance.service enabled
kdump.service masked
kmod-static-nodes.service static
kpatch.service disabled
kubelet.service enabled
libstoragemgmt.service masked
lm_sensors.service masked
...
부팅시 실패한 서비스 목록을 출력해 줍니다.
$ systemctl --failed
UNIT LOAD ACTIVE SUB DESCRIPTION
ipmievd.service loaded failed failed Ipmievd Daemon
network.service loaded failed failed LSB: Bring up/down networking
systemd-tmpfiles-clean.service loaded failed failed Cleanup of Temporary Directories
systemd-tmpfiles-setup.service loaded failed failed Create Volatile Files and Directories
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
4 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
systemd-analyze
systemd-analyze
명령어는 분석 정보를 출력해 줍니다.
$ systemd-analyze
Startup finished in 862ms (kernel) + 868ms (initrd) + 1min 4.908s (userspace) = 1min 6.639s
$ systemd-analyze blame
50.457s unbound-anchor.service
30.003s iaas-pm-bootup.service
7.705s cloud-final.service
7.102s cloud-init.service
3.270s ntpdate.service
2.743s network.service
1.252s docker.service
640ms cloud-init-local.service
369ms cloud-config.service
345ms lvm2-monitor.service
313ms systemd-udev-settle.service
251ms dev-vda2.device
183ms prov2-line-agent.service
141ms snmpd.service
124ms sshd-keygen.service
111ms hostagent_kr.service
111ms hostagent_jp_line.service
90ms systemd-vconsole-setup.service
51ms rc-local.service
...
critical-chain
을 이용하면, 시간을 많이 소요한 서비스의 실행과 대기에 대해서 체인형태로 출력할 수 있습니다.
$ 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 @34.062s
└─iaas-pm-bootup.service @4.056s +30.003s
└─basic.target @623ms
└─sockets.target @623ms
└─dbus.socket @623ms
└─sysinit.target @622ms
└─systemd-update-utmp.service @617ms +5ms
└─systemd-remount-fs.service @183ms +13ms
└─systemd-fsck-root.service @584542y 2w 2d 20h 1min 49.069s +11ms
└─systemd-journald.socket
└─-.slice
systemd-cgls
systemd-cgls
명령어는 현재 cgroup
에 대한 정보를 타입별로 출력해줍니다.
$ systemd-cgls
├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
├─kubepods
│ └─burstable
│ ├─podfc4890ab91dfb8b8a630043af37f52d8
│ │ ├─dc2312d450abd72c1490775e615fbf41abbef49bb4ccdc6a9d9d8bb7ec880724
│ │ │ └─40435 kube-apiserver --apiserver-count=5 --authorization-mode=Node,RBAC --advertise-address=10.xx.xx.xx --allow-privileged=true --client-ca-file=/etc/kubernetes/pki/ca.crt --disable-admission-plugins=Persiste
│ │ └─5b42977c143110757f6d7ae747fbe435f878f8427d30274936eb06bb5dc21b2c
│ │ └─40405 /pause
│ ├─pod734afb7f-08db-11e9-aa26-fa1648a9a65b
│ │ ├─a76db3d9d75d1a48f3231c75b601fd6c7ad1b33ff83e054482b800b2cf6ca049
│ │ │ └─104263 /bin/node_exporter --path.procfs=/host/proc --path.sysfs=/host/sys
│ │ └─e8bffecd18687c7cb1ca90b3de906928e6af50081601203a2bab7f5fea19ae34
│ │ └─104169 /pause
│ ├─pod49e68627-08ce-11e9-837e-fa1648a9a65b
│ │ ├─dd6d53bb4036a64572e4a64f5997a87e5bfb6e5c25f453153854fca88105e54a
│ │ │ └─kube-proxy
│ │ │ └─80946 /usr/local/bin/kube-proxy --config=/var/lib/kube-proxy/config.conf
│ │ └─bc202979fd26611a1ec0ac59fd013d66dff2262da590d326dd3817ed5a56dd28
│ │ └─80907 /pause
│ ├─pod45de6e05-08ce-11e9-837e-fa1648a9a65b
│ │ ├─3881a2163345cf5b6f9c6bca07e2f36394fe6a0ee3a13a33a3f12e9669385a52
│ │ │ └─80804 /opt/bin/flanneld --ip-masq --kube-subnet-mgr --iface=private --iface=bond0 --iface=eth0
│ │ └─a8b41a45c4e3cf278d3841e67914c81382bc4b536f6b86183c3a2eed4f059377
│ │ └─80713 /pause
│ ├─pod705e7ce1217a37349a5567101e60165d
│ │ ├─51d6579bb1d26c0868908077434fe519377b67ba5bd81530bd3d0c3ad1369260
│ │ │ └─82155 kube-scheduler --address=127.0.0.1 --kubeconfig=/etc/kubernetes/scheduler.conf --leader-elect=true
│ │ └─dfc5ef7ff3565013fd50361c2a848010916fe4246dbd6c190df740068648c510
│ │ └─77628 /pause
...
systemd-cgtop
systemd-cgtop
명령어는 흔히 알고 있는 top
명령어 처럼, cgroup에 대하여 CPU, Memory, I/O에 대한 결과를 출력해 줍니다.
Path Tasks %CPU Memory Input/s Output/s
/ 88 20.9 3.2G - -
/system.slice - 13.7 1.0G - -
/system.slice/kubelet.service 1 13.1 68.8M - -
/kubepods - 2.6 556.8M - -
/kubepods/burstable - 2.6 554.9M - -
/user.slice 3 2.2 1.0G - -
/kubepods/burstable/podfc4890ab91dfb8b8a630043af37f52d8 - 1.7 462.5M - -
/kubepods/burstable/pod705e7ce1217a37349a5567101e60165d - 0.6 19.9M - -
/system.slice/docker.service 14 0.4 376.4M - -
/system.slice/xinetd.service 2 0.3 1.2M - -
/kubepods/burstable/pod49e68627-08ce-11e9-837e-fa1648a9a65b - 0.2 17.1M - -
/system.slice/prov2-line-agent.service 3 0.0 115.4M - -
/kubepods/besteffort - - 1.9M - -
/kubepods/burstable/pod39ece0064784892be959367697d0d16b - - 15.1M - -
/kubepods/burstable/pod45de6e05-08ce-11e9-837e-fa1648a9a65b - - 18.3M - -
/kubepods/burstable/pod734afb7f-08db-11e9-aa26-fa1648a9a65b - - 19.8M - -
/system.slice/atd.service 1 - - - -
/system.slice/chronyd.service 1 - 4.0K - -
/system.slice/crond.service 1 - 1.1M - -
/system.slice/dbus.service 1 - 496.0K - -
/system.slice/irqbalance.service 1 - 8.0K - -
/system.slice/lvm2-lvmetad.service