当前位置:   article > 正文

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

关闭selinux

目录

一.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)下载好服务

  1. [root@sulibao ~]# yum install -y httpd
  2. Updating Subscription Management repositories.
  3. Unable to read consumer identity
  4. This system is not registered with an entitlement server. You can use subscription-manager to register.
  5. Last metadata expiration check: 14:01:12 ago on Wed 11 Jan 2023 09:53:23 PM CST.
  6. Package httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64 is already installed.
  7. Dependencies resolved.
  8. Nothing to do.
  9. Complete!

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

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

2.启动服务

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

  1. [root@sulibao ~]# systemctl start httpd
  2. [root@sulibao ~]# systemctl status httpd
  3. ● httpd.service - The Apache HTTP Server
  4. Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
  5. Active: active (running) since Thu 2023-01-12 11:58:03 CST; 11s ago
  6. Docs: man:httpd.service(8)
  7. Main PID: 8291 (httpd)
  8. Status: "Started, listening on: port 80"
  9. Tasks: 213 (limit: 65651)
  10. Memory: 55.4M
  11. CGroup: /system.slice/httpd.service
  12. ├─8291 /usr/sbin/httpd -DFOREGROUND
  13. ├─8307 /usr/sbin/httpd -DFOREGROUND
  14. ├─8308 /usr/sbin/httpd -DFOREGROUND
  15. ├─8309 /usr/sbin/httpd -DFOREGROUND
  16. └─8322 /usr/sbin/httpd -DFOREGROUND
  17. Jan 12 11:57:52 sulibao systemd[1]: Starting The Apache HTTP Server...
  18. Jan 12 11:58:03 sulibao httpd[8291]: AH00558: httpd: Could not reliably determi>
  19. Jan 12 11:58:03 sulibao systemd[1]: Started The Apache HTTP Server.
  20. Jan 12 11:58:13 sulibao httpd[8291]: Server configured, listening on: port 80
  21. //显示你所做的操作

(2)开机自启动systemctl enable httpd

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

3.重启服务

systemctl restart httpd

[root@sulibao ~]# systemctl restart httpd

4.停止服务

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

  1. [root@sulibao ~]# systemctl stop httpd
  2. [root@sulibao ~]# systemctl status httpd
  3. ● httpd.service - The Apache HTTP Server
  4. Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
  5. Active: inactive (dead) since Thu 2023-01-12 12:03:50 CST; 10s ago
  6. Docs: man:httpd.service(8)
  7. Process: 8615 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, s>
  8. Main PID: 8615 (code=exited, status=0/SUCCESS)
  9. Status: "Running, listening on: port 80"
  10. Jan 12 12:02:02 sulibao systemd[1]: Starting The Apache HTTP Server...
  11. Jan 12 12:02:17 sulibao httpd[8615]: AH00558: httpd: Could not reliably determi>
  12. Jan 12 12:02:17 sulibao systemd[1]: Started The Apache HTTP Server.
  13. Jan 12 12:02:27 sulibao httpd[8615]: Server configured, listening on: port 80
  14. Jan 12 12:03:49 sulibao systemd[1]: Stopping The Apache HTTP Server...
  15. Jan 12 12:03:50 sulibao systemd[1]: httpd.service: Succeeded.
  16. Jan 12 12:03:50 sulibao systemd[1]: Stopped The Apache HTTP Server.

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

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

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

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

二.SElinux关闭

1.临时关闭

使用setenforce 0命令临时关闭SElinux

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

查看状态是否关闭

  1. [root@sulibao ~]# getenforce
  2. Disabled

2.永久关闭

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

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

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

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

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

  1. [root@sulibao ~]# getenforce
  2. Disabled

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

1.查看防火墙状态

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

  1. [root@sulibao ~]# systemctl status firewalld
  2. ● firewalld.service - firewalld - dynamic firewall daemon
  3. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
  4. Active: inactive (dead)
  5. Docs: man:firewalld(1)
  6. [root@sulibao ~]# systemctl restart firewalld
  7. [root@sulibao ~]# systemctl status firewalld
  8. ● firewalld.service - firewalld - dynamic firewall daemon
  9. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
  10. Active: active (running) since Fri 2023-01-06 13:32:07 CST; 2s ago
  11. Docs: man:firewalld(1)
  12. Main PID: 28795 (firewalld)
  13. Tasks: 2
  14. CGroup: /system.slice/firewalld.service
  15. └─28795 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
  16. Jan 06 13:32:06 sulibao systemd[1]: Starting firewalld - dynamic firewall daemon...
  17. Jan 06 13:32:07 sulibao systemd[1]: Started firewalld - dynamic firewall daemon.
  18. 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.
  19. Hint: Some lines were ellipsized, use -l to show in full.

2.关闭防火墙

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

systemctl disable firewalld     禁用,永久关闭

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

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

  1. [root@sulibao ~]# systemctl status firewalld
  2. ● firewalld.service - firewalld - dynamic firewall daemon
  3. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
  4. Active: inactive (dead)
  5. Docs: man:firewalld(1)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/208703?site
推荐阅读
相关标签
  

闽ICP备14008679号