CENTOS7 Systemctl replaces service and chkconfig to achieve system management

Source: Internet
Author: User
Tags openssh server
(Linux Systemctl is a collection of system Management daemons, tools, and libraries that replaces system V, service, and Chkconfig commands)

CentOS 7.x began, CentOS began to use SYSTEMD services instead of daemon, the original management system to start and manage system services, all the relevant commands by the SYSTEMCTL command to replace. 1, the original service command and SYSTEMCTL command contrast

Daemon Command systemctl Command Description
Service [Services] Start Systemctl start [Unit type] Start a service
Service [Services] Stop Systemctl stop [Unit type] Stop Service
Service [Services] Restart systemctl restart [Unit type] Restart Service

In addition, there are two systemctl parameters that do not correspond to the service command parameters Status: parameters to view the services running reload: Reload the service, load the updated configuration file (not all services support this parameter, such as Network.service)

Application Examples:

#启动网络服务
systemctl start network.service

#停止网络服务
systemctl stop network.service

#重启网络服务
Systemctl Restart Network.service

#查看网络服务状态
systemctl status Network.serivce
2, the original chkconfig command and systemctl command contrast 2.1. Set boot/do not start
Daemon Command systemctl Command Description
Chkconfig [Services] On SYSTEMCTL enable [unit type] Set up service boot up
Chkconfig [Services] off systemctl disable [Unit type] Device Service disables boot up

Application Examples:

#停止cup电源管理服务
systemctl Stop cups.service

#禁止cups服务开机启动
systemctl disable Cups.service

# View Cups service status
systemctl status Cups.service

#重新设置cups服务开机启动
systemctl enable Cups.service
2.2, view the system on all services

Command format:

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

Parameter detailed:

Command-list-units: Lists all the initiated unit (unit) based on unit. Plus –all will list the unit that did not start; -List-unit-files: Lists the boot files according to the boot files within/usr/lib/systemd/system/

–type=type-for unit type, main service, socket, target

Application Examples:

systemctl Command Description
Systemctl List all system services
Systemctl list-units List all startup unit
Systemctl List-unit-files List all startup files
Systemctl List-units–type=service–all List the unit for all service types
Systemctl list-units–type=service–all grep CPU List services for the CPU power management mechanism
Systemctl List-units–type=target–all List all target
3, Special use of Systemctl
systemctl Command Description
SYSTEMCTL is-active [Unit type] To see if the service is running
SYSTEMCTL is-enable [Unit type] To see if the service is set to boot
Systemctl mask [Unit type] Unregister a specified service
Systemctl unmask [Unit type] Cancel logoff of the specified service

Application Examples:

#查看网络服务是否启动
systemctl is-active network.service

#检查网络服务是否设置为开机启动
systemctl is-enable network.service

#停止cups服务
systemctl stop cups.service

#注销cups服务
systemctl mask cups.service

#查看cups服务状态
systemctl status Cups.service

#取消注销cups服务
systemctl unmask cups.service
4, init command and systemctl command contrast
init command systemctl Command Description
Init 0 Systemctl Poweroff System shutdown
Init 6 Systemctl reboot Reboot

Other commands related to the switching machine:

systemctl Command Description
Systemctl suspend Go to sleep mode
Systemctl Hibernate Enter Hibernate mode
Systemctl Rescue Forced access to rescue mode
SYSTEMCTL Emergency Forced into emergency rescue mode
5. Set the system running level 5.1. Operation level corresponding table
init level systemctl Target
0 Shutdown.target
1 Emergency.target
2 Rescure.target
3 Multi-user.target
4 No
5 Graphical.target
6 No

In addition, a getty.target is used to set the number of TTY. 5.2. Set Run level

Command format:

systemctl [command] [Unit.target]

Parameter detailed:

Command
Get-default: Gets the current target Set-default: Sets the specified target to the default run level isolate: Switch to the specified run level Unit.target: Run level listed for 5.1 tables
systemctl Command Description
Systemctl Get-default Get the current run level
Systemctl Set-default Multi-user.target Set the default run level to Mulit-user
Systemctl Isolate Multi-user.target Switch to run level mulit-user under no reboot
Systemctl Isolate Graphical.target In the case of no reboot, switch to the graphical interface
6. Use Systemctl to analyze the dependencies before each service

Command format:

SYSTEMCTL list-dependencies [Unit] [–reverse]

–reverse is used to check to find which unit uses this unit.

Application Examples:

#获得当前运行级别的target
[root@www ~]# systemctl get-default
multi-user.target

#查看当前运行级别target (mult-user) What services are started
[root@www ~]# systemctl list-dependencies
default.target ├─abrt-ccpp.service
├─abrt-oops.service
├─vsftpd.service
├─basic.target
│├─alsa-restore.service
│ ├─alsa-state.service .....
(omitted in the middle)
... │├─sockets.target
││├─avahi-daemon.socket
││├─dbus.socket
... (omitted in the middle)
... │├─sysinit.target
││├─dev-hugepages.mount
││├─dev-mqueue.mount
... (omitted in the middle)
... │└─timers.target
│   └─systemd-tmpfiles-clean.timer
├─getty.target
│└─getty@tty1.service
└─remote-fs.target

#查看哪些target引用了当前运行级别的target
[root@www ~]# systemctl list-dependencies--reverse
Default.target
└─graphical.target
7. Turn off Network Service

There are some special needs to shut down UNIT.SERVCE and unit.socket while using SYSTEMCTL to turn off network services

Use Systemctl to view open Sshd services

[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

Can see the system at the same time opened the Sshd.service and Sshd.socket, if only the retreat Sshd.service then Sshd.socket is still listening to the network, on the network when the need to connect sshd will start Sshd.service. Therefore, if you want to completely shut down the SSHD service, you need to deactivate both Sshd.service and Sshd.socket.

Systemctl Stop Sshd.service
systemctl stop sshd.socket systemctl disable Sshd.service sshd.socket

Because the CentOS 7.x does not have the Net-tools installed by default, Netstat is not available to view the products developed by the host. You need to use the Yum installation to get the toolkit:

Yum-y Install Net-tools

See if 22 ports are closed

NETSTAT-LNP |grep sshd
8, shut down the firewall firewall

Centos 7.x iptables, replaced with firewall. To turn off the firewall and disable the boot boot service, use the following command:

Systemctl Stop firewalld.service
systemctl disable Firewalld.service


Original: http://blog.csdn.net/u012486840/article/details/53161574

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.