Background: Major changes in CENTOS7 and 6
For system administrators, the system's service management is a very daily and very important work, and 7 on the basis of 6 has changed a lot, even the command is completely different. So to embrace change, learning 7 is how to manage and control the service.
A preliminary study of system and SYSTEMCTL
Systemctl is a systemd tool that is primarily responsible for controlling SYSTEMD systems and service managers.
Systemd is a collection of systems management daemons, tools, and libraries that supersede the System V initial process. The SYSTEMD feature is for centralized management and configuration of Unix-like systems.
In the Linux ecosystem, SYSTEMD is deployed in most of the standard Linux distributions, with only a few distributions yet to be deployed. SYSTEMD is usually the parent process of all other daemons, but not always.
"First Step"
View the version of SYSTEMD
# Systemctl--version
SYSTEMD 219
+pam +audit +selinux +ima-apparmor +smack +sysvinit +utmp +libcryptsetup +gcrypt +gnutls +ACL +xz-lz4-seccomp +BLKID +E Lfutils +kmod +idn
To see if a process exists
Ps-ef | grep [S]ystemd
Note: The SYSTEMD is run as a parent process (pid=1)
Analyzing the startup process of SYSTEMD
# Systemd-analyze
Startup finished in 639ms (kernel) + 931ms (INITRD) + 12.432s (userspace) = 14.003s
Analyze how long each process starts to charge
#systemd-analyze Blame
Analysis of key chains at startup
Systemd-analyze Critical-chain
Important: Systemctl accepts a service (. Service), Mount Point (. mount), socket interface (. socket), and device (. device) as a unit.
List all service availability units
Systemctl List-unit-files
(more than 200)
List all running units
Systemctl list-units
List the failed units?
Systemctl--failed
Lists whether a cell is started
# Systemctl is-enabled Crond.service
Enabled
Or
# Systemctl is-enabled Crond
Enabled
Check if a cell or service is running
# Systemctl Is-active Crond
Active
Or
# SYSTEMCTL Status Crond
This information is more detailed
############################# Control Service ############################
List all services (both enabled and disabled)
Systemctl List-unit-files--type=service
(120+)
Taking httpd as an example
Yum Install httpd
The following files are generated
/usr/lib/systemd/system/httpd.service
How to start, restart, stop, reload, and check the status of services (such as Httpd.service) in Linux
[Email protected] ~]# systemctl status httpd
Httpd.service-the Apache HTTP Server
Loaded:loaded (/usr/lib/systemd/system/httpd.service; disabled; Vendor preset:disabled)
Active: inactive (dead)
DOCS:MAN:HTTPD (8)
Man:apachectl (8)
[Email protected] ~]# systemctl start httpd
[Email protected] ~]# systemctl status httpd
Httpd.service-the Apache HTTP Server
loaded:loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:disabled)
Active: active (running) since Sun 2016-10-23 00:48:43 CST; 3s ago
DOCS:MAN:HTTPD (8)
Man:apachectl (8)
Main pid:26811 (httpd)
Status: "Processing requests ..."
CGroup:/system.slice/httpd.service
├─26811/usr/sbin/httpd-dforeground
├─26812/usr/sbin/httpd-dforeground
├─26813/usr/sbin/httpd-dforeground
├─26814/usr/sbin/httpd-dforeground
├─26815/usr/sbin/httpd-dforeground
└─26816/usr/sbin/httpd-dforeground
OCT 00:48:17 Centos7-node2 systemd[1]: Starting the Apache HTTP Server ...
OCT 00:48:33 centos7-node2 httpd[26811]: AH00558:httpd:Could not reliably determine the server ' s fully qua...ssage
OCT 00:48:43 centos7-node2 systemd[1]: Started the Apache HTTP Server.
Hint:some lines were ellipsized, use-l to show on full.
[Email protected] ~]# Systemctl Reload httpd
[Email protected] ~]# Systemctl stop httpd
Attention:
loaded:loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:disabled)
The first disabled in loader indicates whether the system boot is self-booting and is not automatic. The second one doesn't know what to do.
Active:active (running) since Sun 2016-10-23 00:48:43 CST; 3s ago
Active Indicates whether the service is running
How to activate the service and enable or disable the service at startup (that is, start the service automatically when the system starts)
[Email protected] ~]# Systemctl enable httpd
Created symlink From/etc/systemd/system/multi-user.target.wants/httpd.service to/usr/lib/systemd/system/ Httpd.service.
Disable
Systemctl disabled httpd
[Email protected] ~]# systemctl disable httpd
Removed Symlink/etc/systemd/system/multi-user.target.wants/httpd.service.
Kill the service using the SYSTEMCTL command
[Email protected] ~]# Systemctl kill httpd
[Email protected] ~]# systemctl status httpd
Httpd.service-the Apache HTTP Server
loaded:loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:disabled)
Active:failed (Result:exit-code) since Sun 2016-10-23 00:56:59 CST; 1s ago
DOCS:MAN:HTTPD (8)
Man:apachectl (8)
process:26901 execstop=/bin/kill-winch ${mainpid} (code=exited, status=1/failure)
Main pid:26869 (code=exited, status=0/success)
Status: "Total requests:0; Current requests/sec:0; Current traffic:0 b/sec "
OCT 00:51:38 Centos7-node2 systemd[1]: Starting the Apache HTTP Server ...
OCT 00:51:53 centos7-node2 httpd[26869]: AH00557:httpd:apr_sockaddr_info_get () failed for Centos7-node2
OCT 00:51:53 centos7-node2 httpd[26869]: AH00558:httpd:Could not reliably determine the server ' s fully qua...ssage
OCT 00:52:03 centos7-node2 systemd[1]: Started the Apache HTTP Server.
OCT 00:56:59 centos7-node2 kill[26901]: Kill:cannot Find Process ""
OCT 00:56:59 centos7-node2 systemd[1]: Httpd.service:control process exited, code=exited Status=1
OCT 00:56:59 centos7-node2 systemd[1]: Unit Httpd.service entered failed state.
OCT 00:56:59 centos7-node2 systemd[1]: Httpd.service failed.
Hint:some lines were ellipsized, use-l to show on full.
Note: active:failed (result:exit-code) since Sun 2016-10-23 00:56:59 CST; 1s ago
This failed says kill?
########################## use Systemctl to control and manage mount points ################ #3
[Email protected] ~]# Systemctl list-unit-files--type=mount
UNIT FILE State
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
Mount, unload, re-mount, reload system mount points and check the status of Mount points in the system
Systemctl Start Tmp.mount
Systemctl Status Tmp.mount
Systemctl Reload Tmp.mount
Activate, enable, or disable mount points at startup (automatically mounts when system starts)
# Systemctl Is-active Tmp.mount
# Systemctl Enable Tmp.mount
# systemctl Disable Tmp.mount
Masking (making it not enabled) or visible mount points in Linux
# Systemctl Mask Tmp.mount
Ln-s '/dev/null '/etc/systemd/system/tmp.mount '
# Systemctl unmask Tmp.mount
RM '/etc/systemd/system/tmp.mount '
#################### control system operating level ##################
Start the System rescue mode
# Systemctl Rescue
Broadcast message from [e-mail protected] on pts/0 (wed2015-04-2911:31:18 IST):
The system is going down to rescue mode now!
Enter emergency mode
# 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 Intodefault mode.
List The running levels currently in use
Note: Init 1 is also available
# Systemctl Get-default
Multi-user.target
Note: Who-r is also available for viewing
Start run Level 5, which is the graphics mode
# Systemctl Isolate Runlevel5.target
Or
# Systemctl Isolate Graphical.target
Start Run Level 3, which is multi-user mode (command line)
# Systemctl Isolate Runlevel3.target
Or
# Systemctl Isolate Multiuser.target
Set the default run level for multi-user mode or graphics mode
# Systemctl Set-default Runlevel3.target
# Systemctl Set-default Runlevel5.target
Restart, stop, suspend, hibernate, or bring the system into mixed sleep
# Systemctl reboot
# Systemctl Halt
# Systemctl Suspend
# Systemctl Hibernate
# Systemctl Hybrid-sleep
For those who do not know what the operating level is, explain the following.
Runlevel 0: Shutting down the system
Runlevel 1: Rescue? Maintenance Mode
Runlevel 3: Multi-user, no graphics system
Runlevel 4: Multi-user, no graphics system
Runlevel 5: Multi-user, graphical system
Runlevel 6: Close and restart the machine
Note: Init 6 can still be started in Centos7 with init 0 shutdown.
This article is from the "learning communication, the first job ops" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1864579
Commands for SYSTEMD systemctl Management Services in CENTOS7