How to control the running state of the service? How to switch different levels of operation?
service control
ntsysv
- Imitating graphical interactive interface, centralized configuration of various service startup status
level 35: Manage services at the specified runlevel, not just at the current runlevel.
[root@localhost ~]# ntsysv --level 35
systemctl
- System CTL {Options} name. service
start:Start
Stop: stop
[root@localhost ~]# systemctl start httpd.service [root@localhost ~]# systemctl stop httpd.service
restart: restart, stop first, start again
Reload: reload the configuration file and do not completely stop and start the service
[root@localhost ~]# systemctl restart httpd.service [root@localhost ~]# systemctl reload httpd.service
status:
is-active: Start successfully
is-failed: Failed to start
[root@localhost ~]# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2019-08-27 17:31:39 CST; 40s ago Docs: man:httpd(8) man:apachectl(8) Process: 8833 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS) Main PID: 8821 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─8821 /usr/sbin/httpd -DFOREGROUND ├─8835 /usr/sbin/httpd -DFOREGROUND ├─8836 /usr/sbin/httpd -DFOREGROUND ├─8837 /usr/sbin/httpd -DFOREGROUND ├─8838 /usr/sbin/httpd -DFOREGROUND └─8839 /usr/sbin/httpd -DFOREGROUND Aug 27 17:31:39 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... Aug 27 17:31:39 localhost.localdomain httpd[8821]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.l...s message Aug 27 17:31:39 localhost.localdomain systemd[1]: Started The Apache HTTP Server. Aug 27 17:31:45 localhost.localdomain httpd[8833]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.l...s message Aug 27 17:31:45 localhost.localdomain systemd[1]: Reloaded The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl is-active httpd.service active [root@localhost ~]# systemctl is-failed httpd.service active
enable: boot-up self-start
Disabled: Turn off and boot up automatically
is-enabled: Start-up or not
[root@localhost ~]# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@localhost ~]# systemctl disable httpd.service Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service. [root@localhost ~]# systemctl is-enabled httpd.service disabled
list-dependencies: View dependencies
[root@localhost ~]# systemctl list-dependencies httpd.service httpd.service ● ├─-.mount ● ├─system.slice ● └─basic.target ● ├─microcode.service ● ├─rhel-autorelabel-mark.service ● ├─rhel-autorelabel.service ● ├─rhel-configure.service ● ├─rhel-dmesg.service ● ├─rhel-loadmodules.service ● ├─selinux-policy-migrate-local-changes@targeted.service ● ├─paths.target ● ├─slices.target ● │ ├─-.slice ● │ └─system.slice ● ├─sockets.target ● │ ├─dbus.socket ● │ ├─dm-event.socket ● │ ├─systemd-initctl.socket ● │ ├─systemd-journald.socket ● │ ├─systemd-shutdownd.socket ● │ ├─systemd-udevd-control.socket ● │ └─systemd-udevd-kernel.socket ● ├─sysinit.target ● │ ├─dev-hugepages.mount ● │ ├─dev-mqueue.mount ● │ ├─kmod-static-nodes.service ● │ ├─lvm2-lvmetad.socket ● │ ├─lvm2-lvmpolld.socket ● │ ├─lvm2-monitor.service ● │ ├─plymouth-read-write.service ● │ ├─plymouth-start.service ● │ ├─proc-sys-fs-binfmt_misc.automount ● │ ├─sys-fs-fuse-connections.mount ● │ ├─sys-kernel-config.mount ● │ ├─sys-kernel-debug.mount ● │ ├─systemd-ask-password-console.path ● │ ├─systemd-binfmt.service ● │ ├─systemd-firstboot.service ● │ ├─systemd-hwdb-update.service ● │ ├─systemd-journal-catalog-update.service ● │ ├─systemd-journal-flush.service ● │ ├─systemd-journald.service ● │ ├─systemd-machine-id-commit.service ● │ ├─systemd-modules-load.service ● │ ├─systemd-random-seed.service ● │ ├─systemd-sysctl.service ● │ ├─systemd-tmpfiles-setup-dev.service ● │ ├─systemd-tmpfiles-setup.service ● │ ├─systemd-udev-trigger.service ● │ ├─systemd-udevd.service ● │ ├─systemd-update-done.service ● │ ├─systemd-update-utmp.service ● │ ├─systemd-vconsole-setup.service ● │ ├─cryptsetup.target ● │ ├─local-fs.target ● │ │ ├─-.mount ● │ │ ├─boot.mount ● │ │ ├─rhel-import-state.service ● │ │ ├─rhel-readonly.service ● │ │ └─systemd-remount-fs.service ● │ └─swap.target ● │ └─dev-mapper-centos\x2dswap.swap ● └─timers.target ● └─systemd-tmpfiles-clean.timer
mask: masking service
unmak: Unmasking
- Mainly used for conflicting services, after shielding, it will not be started by other system D units, nor can it be started manually. For example, iptables and firewalld are conflicting.
[root@localhost ~]# systemctl mask firewalld.service Created symlink from /etc/systemd/system/firewalld.service to /dev/null. [root@localhost ~]# systemctl unmask firewalld.service Removed symlink /etc/systemd/system/firewalld.service.
Operation level
runlevel
- Display the running level of the system
[root@localhost ~]# runlevel N 5
Switching Multiuser Mode
Two methods:
[root@localhost ~]# init 3
[root@localhost ~]# systemctl isolate multi-user.target
Switching Graphical Interface
Two methods:
[root@localhost ~]# init 5
[root@localhost ~]# systemctl isolate graphical.target
Boot default target
1. View the default startup target
[root@localhost ~]# systemctl get-default graphical.target
2. Switching the default startup target, there are two ways:
[root@localhost ~]# systemctl set-default multi-user.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@localhost ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
3. View the default startup target
[root@localhost ~]# systemctl get-default multi-user.target