Linux的systemctl命令详解、(永久)关闭SElinux和firewalld防火墙

目录

一.systemctl命令详解

1.查看服务状态

(1)下载好服务

(2)查看状态systemctl status httpd,active为dead为无法使用状态

2.启动服务

(1)临时启动一次systemctl start httpd,active为running已启动服务可以使用

(2)开机自启动systemctl enable httpd

3.重启服务

4.停止服务

(1)临时停止一次systemctl stop httpd,已关闭

(2)永久禁用服务systemctl disable httpd

5.重载服务,重新加载服务的配置文件,需要服务是在开启状态

二.SElinux关闭

1.临时关闭

2.永久关闭

三.关闭防火墙(firewalld服务)

1.查看防火墙状态

2.关闭防火墙


一.systemctl命令详解

1.查看服务状态

(1)下载好服务

[root@sulibao ~]# yum install -y httpd
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 14:01:12 ago on Wed 11 Jan 2023 09:53:23 PM CST.
Package httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

(2)查看状态systemctl status httpd,active为dead为无法使用状态

[root@sulibao ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
   Active: inactive (dead)
     Docs: man:httpd.service(8)

2.启动服务

(1)临时启动一次systemctl start httpd,active为running已启动服务可以使用

[root@sulibao ~]# systemctl start httpd
[root@sulibao ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
   Active: active (running) since Thu 2023-01-12 11:58:03 CST; 11s ago
     Docs: man:httpd.service(8)
 Main PID: 8291 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 65651)
   Memory: 55.4M
   CGroup: /system.slice/httpd.service
           ├─8291 /usr/sbin/httpd -DFOREGROUND
           ├─8307 /usr/sbin/httpd -DFOREGROUND
           ├─8308 /usr/sbin/httpd -DFOREGROUND
           ├─8309 /usr/sbin/httpd -DFOREGROUND
           └─8322 /usr/sbin/httpd -DFOREGROUND

Jan 12 11:57:52 sulibao systemd[1]: Starting The Apache HTTP Server...
Jan 12 11:58:03 sulibao httpd[8291]: AH00558: httpd: Could not reliably determi>
Jan 12 11:58:03 sulibao systemd[1]: Started The Apache HTTP Server.
Jan 12 11:58:13 sulibao httpd[8291]: Server configured, listening on: port 80
//显示你所做的操作

(2)开机自启动systemctl enable httpd

[root@sulibao ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
//为httpd服务创建了软链接

3.重启服务

systemctl restart httpd

[root@sulibao ~]# systemctl restart httpd

4.停止服务

(1)临时停止一次systemctl stop httpd,已关闭

[root@sulibao ~]# systemctl stop httpd
[root@sulibao ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
   Active: inactive (dead) since Thu 2023-01-12 12:03:50 CST; 10s ago
     Docs: man:httpd.service(8)
  Process: 8615 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, s>
 Main PID: 8615 (code=exited, status=0/SUCCESS)
   Status: "Running, listening on: port 80"

Jan 12 12:02:02 sulibao systemd[1]: Starting The Apache HTTP Server...
Jan 12 12:02:17 sulibao httpd[8615]: AH00558: httpd: Could not reliably determi>
Jan 12 12:02:17 sulibao systemd[1]: Started The Apache HTTP Server.
Jan 12 12:02:27 sulibao httpd[8615]: Server configured, listening on: port 80
Jan 12 12:03:49 sulibao systemd[1]: Stopping The Apache HTTP Server...
Jan 12 12:03:50 sulibao systemd[1]: httpd.service: Succeeded.
Jan 12 12:03:50 sulibao systemd[1]: Stopped The Apache HTTP Server.

(2)永久禁用服务systemctl disable httpd

[root@sulibao ~]# systemctl disable httpd
Removed /etc/systemd/system/multi-user.target.wants/httpd.service.

5.重载服务,重新加载服务的配置文件,需要服务是在开启状态

[root@sulibao ~]# systemctl reload httpd
httpd.service is not active, cannot reload.
[root@sulibao ~]# systemctl restart httpd
[root@sulibao ~]# systemctl reload httpd

二.SElinux关闭

1.临时关闭

使用setenforce 0命令临时关闭SElinux

[root@sulibao ~]# setenforce 0
setenforce: SELinux is disabled

查看状态是否关闭

[root@sulibao ~]# getenforce 
Disabled

2.永久关闭

(1)修改配置文件/etc/selinux/config

这个文件有一个链接文件是/etc/sysconfig/selinux

[root@sulibao ~]# vim /etc/selinux/config 

(2)将文件内SELINUX=XX这行改为 SELINUX=disabled或者SELINUX=permissive,然后保存退出,重启生效


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

也可以使用sed语句来更改:

sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

 (3)重启过后使用getenforce查看SElinux状态,为Disabled或permissive即可认为关闭成功

[root@sulibao ~]# getenforce 
Disabled

三.关闭防火墙(firewalld服务)

1.查看防火墙状态

systemctl status firewalld,active为running表示正在运行

[root@sulibao ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@sulibao ~]# systemctl restart firewalld
[root@sulibao ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2023-01-06 13:32:07 CST; 2s ago
     Docs: man:firewalld(1)
 Main PID: 28795 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─28795 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Jan 06 13:32:06 sulibao systemd[1]: Starting firewalld - dynamic firewall daemon...
Jan 06 13:32:07 sulibao systemd[1]: Started firewalld - dynamic firewall daemon.
Jan 06 13:32:07 sulibao firewalld[28795]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a ...ng it now.
Hint: Some lines were ellipsized, use -l to show in full.

2.关闭防火墙

systemctl stop firewalld    此次关闭,下次不关闭

systemctl disable firewalld     禁用,永久关闭

[root@sulibao ~]# systemctl stop firewalld
[root@sulibao ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

查看firewalld服务状态,active为dead,此时已经永久关闭

[root@sulibao ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

树下一少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值