Use Centos7 systemctl and centos7systemctl

Source: Internet
Author: User
Tags openssh server

Use Centos7 systemctl and centos7systemctl

Starting from CentOS 7.x, CentOS began to use the systemd service to replace daemon. 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]

Restart service

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

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

Example:

# Start a network service

Systemctl start network. service

# Stopping Network Services

Systemctl stop network. service

# Restarting Network Services

Systemctl restart network. service

# Viewing network service status

Systemctl status network. serivce

2. Comparison between the original chkconfig command and the systemctl command 2.1. Set boot start/not start

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 cup Power Management Service

Systemctl stop cups. service

# Disable startup of cups service

Systemctl disable cups. service

# Viewing the cups service status

Systemctl status cups. service

# Resetting startup of cups service

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 used to list the unstarted units.-list-unit-files: lists the startup files based on the startup files in/usr/lib/systemd/system /.

-Type = TYPE-unit type, mainly including service, socket, and 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]

Deregister a specified service

Systemctl unmask [unit type]

Cancels the cancellation of a specified service

Example:

# Check whether the network service is started

Systemctl is-active network. service

# Check whether the network service is set to boot

Systemctl is-enable network. service

# Stop the cups service

Systemctl stop cups. service

# Log out of the cups service

Systemctl mask cups. service

# Viewing the cups service status

Systemctl status cups. service

# Canceling 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 table for system running level 5.1 and running 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] unzip unit.tar get]

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-default

Multi-user.target

# View the services started by target (mult-user) at the current running level [root @ www ~] # Systemctl list-dependencies

Default.tar get

├-Abrt-ccpp.service

├-Abrt-oops.service

├ ── Vsftpd. service

├─Basic.tar get

│ ─-Alsa-restore.service

│ ─-Alsa-state.service

... (Omitted in the middle ).....

│ ├─Ets.tar get

│ ─-Avahi-daemon.socket

│ ─ ── Summary. socket

... (Omitted in the middle ).....

│ ├─Sysinit.tar get

│ ─-Dev-hugepages.mount

│ ─-Dev-mqueue.mount

... (Omitted in the middle ).....

│ Pull timers.tar get

│ ─-Systemd-tmpfiles-clean.timer

Registry.getty.tar get

│ ─-Getty@tty1.service

└─Remote-fs.tar get

# View which targets reference the current running-level target [root @ www ~] # Systemctl list-dependencies -- reverse

Default.tar get

└─Graphical.tar get

7. Disable Network Services

When you use systemctl to disable network services, You need to disable unit. servce and unit. socket at the same time.

Use systemctl to view the sshd service enabled

[Root @ www system] # systemctl list-units -- all | grep sshd

Sshd-keygen.service loaded inactive dead OpenSSH Server Key Generation

Sshd. service loaded active running OpenSSH server daemon

Sshd. 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. service

Systemctl stop sshd. socket

Systemctl 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. service

Systemctl disable firewalld. service

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.