Since centOS7, a command for managing services has been added – systemctl, through which the services on the system can be managed very conveniently.
Open and close the service through systemctl
The following lists the relevant options for opening and closing the service
-
start open the service
-
stop shuts down the service
-
restart restarts the service
-
status checks the service status
-
reload reloads the configuration file (without shutting down the service)
-
enable starts the service at boot
-
disable turn off self-starting at boot
Learn through the following cases
# View service operating status # systemctl status atd ● atd.service - Job pooling tools Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2020-11-07 16:20:59 CST; 3 days ago Main PID: 3002 (atd) CGroup: /system.slice/atd.service └─3002 /usr/sbin/atd -f Nov 07 16:20:59 iz8vb626ci0aehwsivxaydz systemd[1]: Started Job spooling tools. Nov 07 16:20:59 iz8vb626ci0aehwsivxaydz systemd[1]: Starting Job spooling tools...
Through the information shown above, we can get a lot of information. From the second line Loaded, enabled appears to indicate that the service starts automatically after booting. From the running of the third line, we know that the service is running.
Let’s demonstrate closing and starting services
# systemctl stop atd # systemctl start atd
About the running status of the service, in addition to the common running, dead, etc., there are some, listed below
-
active(running) is running
-
active(waiting): waiting for execution (waiting for other services to execute before executing)
-
active(exited): A service that ends normally after only one execution
-
inactive(dead): The service is not started
In addition, there are several options about whether the service is started at boot:
-
enable: start at boot
-
disable: does not start at boot
-
static: does not start automatically at boot, but can be started by other self-starting services
-
static: p>
-
mask: It will not start anyway, the service has been forcibly logged off
Observe the services on the system through systemctl
Through systemctl, you can check which services are currently running, and you can also check all the services on the system (including not started), and to view services of a certain type.
list-units lists all currently started services, if no task option is used, this option is used by default. Add -a to display all, including unstarted services
–type=TYPE lists a certain type of service
Look at the demo below
# List all running services in the system #systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automount sys-devices-pci0000:00-0000:00:03.0-virtio0-net-eth0.device loaded active plugged Virtio network device sys-devices-pci0000:00-0000:00:04.0-virtio1-virtio\x2dports-vport1p1.device loaded active plugged /sys/devices/pci0000:00/0000:00:04. ... # List the services of the service type that the system is running # systemctl --type=service UNIT LOAD ACTIVE SUB DESCRIPTION aegis.service loaded active running LSB: aegis update. aliyun.service loaded active running aliyun-assist atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service # List all services on the system, including those that are not running # systemctl -a ...
Manage different operating environments (target unit) through systemctl
In centos7, there are many target units, but here we only need to know a few commonly used target units, and the commonly used target units are listed below:
-
graphical.target graphical mode
-
multi-user.target textual mode
-
rescue.target General rescue mode
-
emergency.target emergency rescue mode
Next, let’s see how to view the default operating environment of the system. after�How to modify the operating environment.
systemctl [options] [unit.target] [option] get-default: view the system default operating environment set-default: set the system default operating environment # View the default operating environment # systemctl get-default multi-user.target # reset the new default operating environment # systemctl set-default graphical.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target. # systemctl get-default graphical.target
The above is the detailed content of linux operation and maintenance through systemctl management services. For more information, please pay attention to other related articles on 1024programmer.com!