Centos7 executes service status mysqld error The service command supports only basic LSB actions xxxxxx

Scene description

When executing the service status mysqld command under CentOS 7, the following error appears:

[root@test ~]# service iptables save
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

Cause of the above problem

Starting from CentOS 7.x, CentOS began to use systemd service instead of daemon. The original management system startup and management system services related commands are all replaced by systemctl commands. The service command retains very few uses, most of the commands must be used instead of the systemctl command.

In RHEL 7 and CentOS 7, firewalld was introduced to manage iptables.

 Detailed systemctl command

1. The original service command is compared with the systemctl command

daemon command systemctl command Description
service [service] start systemctl start [unit type] Start service
service [service] stop systemctl stop [unit type] Out of service
service [service] restart systemctl restart [unit type] Out of service

In addition, the two systemctl parameters do not correspond to the service command parameters

status :参数来查看服务运行情况
reload :重新加载服务,加载更新后的配置文件(并不是所有服务都支持这个参数,比如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 is compared with the systemctl command

2.1. Set startup/no startup

daemon command systemctl command Description
chkconfig [service] on systemctl enable [unit type] Set the service to start
chkconfig [service] off systemctl disable [unit type] Device service prohibits startup

Application examples:

#停止cup电源管理服务
systemctl stop cups.service
#禁止cups服务开机启动
systemctl disable cups.service
#查看cups服务状态
systemctl status cups.service
#重新设置cups服务开机启动
systemctl enable cups.service

2.2. View all services on the system
Command format:

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

Detailed parameters:

command

list-units: List all activated units according to unit. Add -all to list the unstarted units;
list-unit-files: list the startup files based on the startup files in /usr/lib/systemd/system/

–type=TYPE

Unit type, mainly service, socket, target

Application examples:

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 all service types of units
systemctl list-units –type=service –all |grep cpu List the services of the 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 if the service is running
systemctl is-enable [unit type] Check whether the service is set to start on boot
systemctl mask [unit type] Cancel designated service]
systemctl unmask [unit type] Cancellation of designated 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. Comparison of init command and systemctl command

init command systemctl command Description
init 0 systemctl poweroff System shutdown
init 6 systemctl reboot Restart

Other commands related to switch machine:

systemctl command Description
systemctl suspend Enter sleep mode
systemctl hibernate Enter sleep mode
systemctl rescue Force into rescue mode
systemctl emergency Forced to enter emergency rescue mode

5. Set the system operation level

5.1 Correspondence table of operation level

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 ttys.

5.2. Set the run level
Command format:

systemctl [command] [unit.target]

Detailed parameters:

command:

get-default: get the current target
set-default: set the specified target as the default run level
isolate: switch to the specified run level

unit.target: is the run level listed in the 5.1 table

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 Without restarting, switch to run level mulit-user
systemctl isolate graphical.target Switch to the graphical interface without restarting

6. Use systemctl to analyze the dependencies of each service

Command format:

systemctl list-dependencies [unit] [–reverse]

--Reverse is used to check which unit uses this unit

Application examples:

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

#查看当前运行级别target(mult-user)启动了哪些服务
[root@www ~]# systemctl list-dependencies
default.target
├─abrt-ccpp.service
├─abrt-oops.service
├─vsftpd.service
├─basic.target
│ ├─alsa-restore.service
│ ├─alsa-state.service
.....(中间省略).....
│ ├─sockets.target
│ │ ├─avahi-daemon.socket
│ │ ├─dbus.socket
.....(中间省略).....
│ ├─sysinit.target
│ │ ├─dev-hugepages.mount
│ │ ├─dev-mqueue.mount
.....(中间省略).....
│ └─timers.target
│   └─systemd-tmpfiles-clean.timer
├─getty.target
│ └─[email protected]
└─remote-fs.target

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

7. Turn off network services

When using systemctl to close network services, there are some special
needs to close unit.servce and unit.socket at the same time

Use systemctl to view the opened sshd service

[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

可以看到系统同时开启了sshd.service和sshd.socket , 如果只闭关了sshd.service那么sshd.socket还在监听网络,在网络上有要求连接sshd时就会启动sshd.service。因此如果想完全关闭sshd服务的话,需要同时停用sshd.service和sshd.socket。

systemctl stop sshd.service
systemctl stop sshd.socket
systemctl disable sshd.service sshd.socket

由于centos 7.x默认没有安装net-tools���因此无法使用netstat 来查看主机开发的商品。需要通过yum安装来获得该工具包:

 yum -y install net-tools

查看是否关闭22端口

netstat -lnp |grep sshd

8、关闭防火墙firewall

Centos 7.x 中取消了iptables, 用firewall取而代之。要关闭防火墙并禁止开机启动服务使用下面的命令:

systemctl stop firewalld.service
systemctl disable firewalld.service

Guess you like

Origin blog.csdn.net/zhouzhiwengang/article/details/112365806