Introduction to Systemd, how to start using systemd in RHEL 7 or Centos 7 ?
With introduction or RHEL7 or CentOS 7, we have a new concept introduced known as systemd.
Personally i don’t liked the new concept as its a little bit complex to understand at first.
However once you understand its versatile functions, you will start loving this utility.
1. View systemd or systemctl version
$ systemctl --version systemd 219 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
2. Analyze Boot process
a. Get boot time
$ systemd-analyze Startup finished in 1.826s (kernel) + 2.866s (initrd) + 59.178s (userspace) = 1min 3.871s
b. Get time taken by each services during boot.
$ systemd-analyze blame 41.618s kdump.service 21.120s network-libvirt-restart.service 7.470s ossec-hids.service 7.095s NetworkManager-wait-online.service 6.032s network.service 5.731s hp-ams.service 1.897s tuned.service 1.682s postfix.service 1.002s plymouth-quit-wait.service 932ms snmpd.service 927ms dev-mapper-vg01\x2droot.device 886ms openvswitch.service 886ms lvm2-monitor.service 786ms libvirtd.service 751ms sssd.service 736ms polkit.service 721ms plymouth-quit.service 650ms var-lib-nfs-rpc_pipefs.mount 629ms iptables.service 621ms microcode.service 612ms netcf-transaction.service 597ms sysstat.service 587ms gssproxy.service 580ms ntpd.service 541ms systemd-machined.service 419ms boot.mount 360ms ngs.mount 301ms NetworkManager.service 280ms var.mount 273ms lvm2-pvscan@8:3.service 145ms dev-mapper-vg01\x2dswap.swap 143ms ksm.service 127ms rhel-dmesg.service 126ms systemd-vconsole-setup.service 121ms rpc-statd-notify.service 117ms ip6tables.service 109ms xinetd.service 109ms systemd-tmpfiles-setup-dev.service 108ms lldpd.service 107ms iscsi-shutdown.service 102ms systemd-udevd.service 95ms systemd-user-sessions.service 87ms rhel-loadmodules.service 83ms systemd-random-seed.service 81ms systemd-udev-trigger.service 75ms systemd-tmpfiles-setup.service 72ms boot-efi.mount 70ms rhel-import-state.service 69ms systemd-journal-flush.service 64ms kmod-static-nodes.service
c. Time taken during boot by different units.
$ 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 @24.916s └─ossec-hids.service @17.444s +7.470s └─network-online.target @17.414s └─network.target @17.345s └─NetworkManager.service @3.038s +301ms └─netcf-transaction.service @2.236s +612ms └─basic.target @2.229s └─sockets.target @2.229s └─virtlogd-admin.socket @20.048s └─sysinit.target @2.227s └─systemd-update-utmp.service @2.184s +42ms └─systemd-tmpfiles-setup.service @2.107s +75ms └─rhel-import-state.service @2.036s +70ms └─local-fs.target @2.027s └─ngs.mount @1.696s +360ms └─dev-mapper-vg01\x2dngs.device @1.695s
3. Analyze critical chain for a particular service.
$ systemd-analyze critical-chain crond.service 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. crond.service @18.298s └─systemd-user-sessions.service @17.562s +95ms └─remote-fs.target @17.558s └─remote-fs-pre.target @17.558s └─iscsi-shutdown.service @17.448s +107ms └─network.target @17.345s └─NetworkManager.service @3.038s +301ms └─netcf-transaction.service @2.236s +612ms └─basic.target @2.229s └─sockets.target @2.229s └─virtlogd-admin.socket @20.048s └─sysinit.target @2.227s └─systemd-update-utmp.service @2.184s +42ms └─systemd-tmpfiles-setup.service @2.107s +75ms └─rhel-import-state.service @2.036s +70ms └─local-fs.target @2.027s └─ngs.mount @1.696s +360ms └─dev-mapper-vg01\x2dngs.device @1.695s
4. List dependencies
a. Of complete system
$ systemctl list-dependencies default.target ● ├─brandbot.path ● ├─crond.service ● ├─dbus.service ● ├─epic.service ● ├─hp-ams.service ● ├─httpd.service ● ├─irqbalance.service ● ├─kdump.service ● ├─ksm.service ● ├─ksmtuned.service ● ├─libvirtd.service ● ├─lldpd.service ● ├─mdmonitor.service ● ├─netcf-transaction.service
b. Of a particular service
$ systemctl list-dependencies crond.service crond.service ● ├─system.slice ● └─basic.target ● ├─ip6tables.service ● ├─iptables.service ● ├─microcode.service ● ├─rhel-dmesg.service ● ├─selinux-policy-migrate-local-changes@targeted.service ● ├─paths.target ● ├─slices.target ● │ ├─-.slice ● │ └─system.slice ● ├─sockets.target ● │ ├─dbus.socket ● │ ├─dm-event.socket ● │ ├─iscsid.socket ● │ ├─iscsiuio.socket ● │ ├─rpcbind.socket ● │ ├─systemd-initctl.socket ● │ ├─systemd-journald.socket ● │ ├─systemd-shutdownd.socket ● │ ├─systemd-udevd-control.socket ● │ ├─systemd-udevd-kernel.socket ● │ └─virtlogd.socket ● ├─sysinit.target ● │ ├─dev-hugepages.mount ● │ ├─dev-mqueue.mount ● │ ├─iscsi.service ● │ ├─kmod-static-nodes.service ● │ ├─lvm2-lvmetad.socket
5. Get Service Details
$ systemctl show crond Type=simple Restart=no NotifyAccess=none RestartUSec=100ms TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s WatchdogUSec=0 WatchdogTimestamp=Thu 2019-02-14 06:42:43 GMT WatchdogTimestampMonotonic=22991309 StartLimitInterval=10000000 StartLimitBurst=5 StartLimitAction=none FailureAction=none PermissionsStartOnly=no The units required by a particular service and vice versa. $ systemctl show crond | grep -i requires Requires=basic.target $ systemctl show crond | grep -i wants Wants=system.slice $
6. Log Analysis
a. View all
bash-4.2# journalctl -- Logs begin at Thu 2019-02-14 06:42:22 GMT, end at Thu 2019-03-07 20:06:45 GMT. -- Feb 14 06:42:22 ngelinux systemd-journal[277]: Runtime journal is using 8.0M (max allowed 3.1G, trying to leave 4.0G free of 31.3G available → cur Feb 14 06:42:22 ngelinux kernel: Initializing cgroup subsys cpuset Feb 14 06:42:22 ngelinux kernel: Initializing cgroup subsys cpu Feb 14 06:42:22 ngelinux kernel: Initializing cgroup subsys cpuacct Feb 14 06:42:22 ngelinux kernel: Linux version 3.10.0-957.1.3.el7.x86_64 (mockbuild@x86-ol7-builder-03.us.oracle.com) (gcc version 4.8.5 20150623 Feb 14 06:42:22 ngelinux kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-957.1.3.el7.x86_64 root=/dev/mapper/vg01-root ro rd.lvm.lv=vg01/swap con Feb 14 06:42:22 ngelinux kernel: e820: BIOS-provided physical RAM map: Feb 14 06:42:22 ngelinux kernel: BIOS-e820: [mem 0x0000000000000000-0x0000000000092fff] usable Feb 14 06:42:22 ngelinux kernel: BIOS-e820: [mem 0x0000000000093000-0x0000000000093fff] reserved Feb 14 06:42:22 ngelinux kernel: BIOS-e820: [mem 0x0000000000094000-0x000000000009ffff] usable
b. View logs of a particular service.
bash-4.2# journalctl /sbin/crond -- No entries -- bash-4.2#
c. View logs of a particular unit.
bash-4.2# journalctl --unit=chronyd -- No entries -- bash-4.2#
d. Logs since last boot:
bash-4.2# journalctl -b -- Logs begin at Thu 2019-02-14 06:42:22 GMT, end at Thu 2019-03-07 20:17:51 GMT. -- Feb 14 06:42:22 ngelinux systemd-journal[277]: Runtime journal is using 8.0M (max allowed 3.1G, trying to leave 4.0G free of 31.3G available → cur Feb 14 06:42:22 ngelinux kernel: Initializing cgroup subsys cpuset Feb 14 06:42:22 ngelinux kernel: Initializing cgroup subsys cpu Feb 14 06:42:22 ngelinux kernel: Initializing cgroup subsys cpuacct Feb 14 06:42:22 ngelinux kernel: Linux version 3.10.0-957.1.3.el7.x86_64 (mockbuild@x86-ol7-builder-03.us.oracle.com) (gcc version 4.8.5 20150623 Feb 14 06:42:22 ngelinux kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-957.1.3.el7.x86_64 root=/dev/mapper/vg01-root ro rd.lvm.lv=vg01/swap con Feb 14 06:42:22 ngelinux kernel: e820: BIOS-provided physical RAM map: Feb 14 06:42:22 ngelinux kernel: BIOS-e820: [mem 0x0000000000000000-0x0000000000092fff] usable Feb 14 06:42:22 ngelinux kernel: BIOS-e820: [mem 0x0000000000093000-0x0000000000093fff] reserved
e. View disk space taken by journal logs.
bash-4.2# journalctl --disk-usage Archived and active journals take up 200.0M on disk. bash-4.2#

bash-4.2# journalctl -p err
— Logs begin at Thu 2019-02-14 06:42:22 GMT, end at Thu 2019-03-07 20:17:51 GMT. —
Feb 14 06:42:22 ngelinux kernel: [Firmware Bug]: the BIOS has corrupted hw-PMU resources (MSR 38d is 330)
Feb 14 06:42:22 ngelinux kernel: i8042: Can’t read CTR while initializing i8042
Feb 14 06:42:23 ngelinux systemd-udevd[439]: could not find module by name=’ipmi_si’
Feb 14 06:42:23 ngelinux systemd-udevd[439]: could not find module by name=’ipmi_devintf’
Feb 14 06:42:23 ngelinux systemd-udevd[439]: could not find module by name=’ipmi_msghandler’
Feb 14 06:42:26 ngelinux kernel: power_meter ACPI000D:00: Ignoring unsafe software power cap!
Feb 14 06:42:30 ngelinux ntpd_intres[8518]: host name not found: us-east-1.ntp.ngelinux.com
Feb 14 06:42:30 ngelinux ntpd_intres[8518]: host name not found: us-east-2.ntp.ngelinux.com
Feb 14 06:42:30 ngelinux ntpd_intres[8518]: host name not found: us-east-3.ntp.ngelinux.com
Feb 14 06:42:30 ngelinux ntpd_intres[8518]: host name not found: us-east-4.ntp.ngelinux.com
Feb 14 06:42:30 ngelinux ntpd_intres[8518]: host name not found: time.ngelinux.com
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux kernel: hpilo 0000:01:00.2: Open could not dequeue a packet
Feb 14 06:42:43 ngelinux systemd[1]: Failed to start The Apache HTTP Server.
Feb 14 06:42:44 ngelinux systemd[1]: Failed to start The Apache HTTP Server.
Feb 14 06:42:44 ngelinux systemd[1]: Failed to start The Apache HTTP Server.
Feb 14 06:42:44 ngelinux systemd[1]: Failed to start The Apache HTTP Server.
Feb 14 06:42:45 ngelinux systemd[1]: Failed to start The Apache HTTP Server.
Feb 14 06:42:45 ngelinux systemd[1]: Failed to start The Apache HTTP Server.
Feb 14 06:42:53 ngelinux kernel: kvm [11591]: vcpu0 disabled perfctr wrmsr: 0xc2 data 0xffff
Feb 21 06:41:38 ngelinux kernel: kvm [11591]: vcpu0 disabled perfctr wrmsr: 0xc2 data 0xffff
bash-4.2#