Systemctl User Guide: Comparison between CentOS 7.x systemd and CentOS 6.x daemon

Source: Internet
Author: User
Tags openssh server

Systemctl User Guide: Comparison between CentOS 7.x systemd and CentOS 6.x daemon

Starting from CentOS 7.x, CentOS began to use the systemd service to replace daemon. The commands related to the management system startup and management system services were all replaced by the systemctl command.

1. Comparison between original service commands and systemctl commands
Daemon command Systemctl command Description
Service [service] start Systemctl start [unit type] Start the service
Service [service] stop Systemctl stop [unit type] Stop Service
Service [service] restart Systemctl restart [unit type] Stop Service

In addition, the two systemctl parameters do not match the service command parameters.

Status: parameter to view the service running status reload: reload the service, load the updated configuration file (not all services support this parameter, such as network. service)

Example:

# Start network service systemctl start network. service # stop network service systemctl stop network. service # restart network service systemctl restart network. service # view network service status systemctl status network. serivce
2. Comparison between the original chkconfig command and the systemctl command

2.1 set startup/no startup

Daemon command Systemctl command Description
Chkconfig [SERVICE] on Systemctl enable [unit type] Set Service Startup
Chkconfig [SERVICE] off Systemctl disable [unit type] Disable device Service Startup

Example:

# Stop the CPU power management service systemctl stop cups. service # disable the cups service from starting systemctl disable cups. service # view the status of the cups service systemctl status cups. service # reset the cups service to start systemctl enable cups. service

2.2 view all services on the System
Command Format:

systemctl [command] [–type=TYPE] [–all]

Parameters:

Command

List-units: lists all started units based on the unit. -All is added to list the units not started;
List-unit-files: list the startup files based on the startup files in/usr/lib/systemd/system /.

-Type = TYPE

Unit type, mainly including service, socket, target

Example:

Systemctl command Description
Systemctl List all system services
Systemctl list-units List all startup units
Systemctl list-unit-files List all startup files
Systemctl list-units-type = service-all List units of all service types
Systemctl list-units-type = service-all | grep cpu List services with cpu power management mechanism
Systemctl list-units-type = target-all List all targets
3. Special usage of systemctl
Systemctl command Description
Systemctl is-active [unit type] Check whether the service is running
Systemctl is-enable [unit type] Check whether the service is set to boot
Systemctl mask [unit type] Deregistering a specified service]
Systemctl unmask [unit type] Cancels the cancellation of a specified service

Example:

# Check whether the network service starts the systemctl is-active network. service # Check whether the network service is set to start systemctl is-enable network. service # stop cups service systemctl stop cups. service # log out of the cups service systemctl mask cups. service # view the status of the cups service systemctl status cups. service # cancel the cancellation of the cups service systemctl unmask cups. service
4. Comparison between the init command and the systemctl command
Init command Systemctl command Description
Init 0 Systemctl poweroff System Shutdown
Init 6 Systemctl reboot Restart

Other commands related to the on/off server:

Systemctl command Description
Systemctl suspend Enter sleep mode
Systemctl hibernate Enter sleep mode
Systemctl rescue Force enter rescue mode
Systemctl emergency Forced access to emergency rescue mode
5. Set the system running level

5.1. Table of Operation Level

Init level Systemctl target
0 Shutdown.tar get
1 Emergency.tar get
2 Rescure.tar get
3 Multi-user.target
4 None
5 Graphical.tar get
6 None

Getty.tar get is used to set the number of tty.

5.2 set the running level
Command Format:

systemctl [command] [unit.target]

Parameters:

Command:

Get-default: get the current target
Set-default: set the specified target to the default running level.
Isolate: switch to the specified running level

Unit.tar get: The running level listed in table 5.1

Systemctl command Description
Systemctl get-default Obtain the current running level
Systemctl set-default multi-user.target Set the default running level to muyun-user.
Systemctl isolate multi-user.target Switch to the muyun-user running level without restarting.
Systemctl isolate graphical.tar get Switch to the graphic interface without restarting
6. Use systemctl to analyze dependencies between services

Command Format:

systemctl list-dependencies [unit] [–reverse]

-Reverse is used to check which unit is used.

Example:

# Obtain the target [root @ www ~] at the current running level # Systemctl get-defaultmulti-user.target # view the services started by the current run-level target (mult-user) [root @ www ~] # Systemctl restart get │ ─ ── alsa-restore.service │ ─ ── alsa-state.service ..... (omitted in the middle )..... │ ├─ets.tar get │ ─ ── avahi-daemon.socket │ ── ↓. socket ..... (omitted in the middle )..... │ unzip sysinit.tar get │ ── dev-hugepages.mount │ ── dev-mqueue.mount ..... (omitted in the middle )..... │ unzip timers.tar get │ unzip systemd-tmpfiles-clean.timer?#getty.tar get │ unzip-gett Y@tty1.service‑policremote-fs.tar get # Check which targets reference the current running-level target [root @ www ~] # Systemctl list-dependencies --reversedefault.target?#graphical.tar get
7. Disable Network Services

When you use systemctl to disable network services, there are some special issues.
Both unit. servce and unit. socket must be disabled.

Use systemctl to view the sshd service enabled

[root@www system]#  systemctl list-units --all | grep sshdsshd-keygen.service loaded inactive dead        OpenSSH Server Key Generationsshd.service        loaded active   running     OpenSSH server daemonsshd.socket         loaded inactive dead        OpenSSH Server Socket

We can see that sshd is enabled at the same time. service and sshd. socket, if only sshd is closed. service so sshd. the socket is still listening to the network. sshd will be started when there is a requirement to connect to sshd on the network. service. Therefore, if you want to completely disable the sshd service, you need to disable both sshd. service and sshd. socket.

systemctl stop sshd.servicesystemctl stop sshd.socketsystemctl disable sshd.service sshd.socket

Net-tools is not installed in centos 7.x by default, so netstat cannot be used to view the product developed by the host. You need to install yum to obtain the Toolkit:

 yum -y install net-tools

Check whether port 22 is disabled

netstat -lnp |grep sshd
8. Disable firewall

Iptables is removed from Centos 7.x and replaced with firewall. To disable the firewall and disable Service Startup, run the following command:

systemctl stop firewalld.servicesystemctl disable firewalld.service

Full guide to systemctl commands

Usage of systemctl on CentOS 7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.