Linux云盘算 |【第一阶段】ENGINEER-DAY5

打印 上一主题 下一主题

主题 542|帖子 542|积分 1626

要内容:

SELinux、体系故障修复、HTTPD/FTP服务搭建、防火墙计谋管理、服务管理

一、SELinux安全制度

SELinux(Security-Enhanced Linux),美国NSA国家安全局主导开发,一套增强Linux体系安全的逼迫访问控制体系,集成到Linux内核(2.6及以上)中运行,RHEL7基于SELinux体系针对用户、进程、目录和文件提供了预设的掩护计谋及管理工具;


  • [ Permissives ] 宽松
  • [ Enforcing ]  逼迫
  • [ Disabled ]  彻底禁用,丧失100%
注意:任何模式酿成disabled模式,都要经历重启体系

1)SELinux切换模式:


  • 检察当前运行模式:getenforce
  • 暂时切换运行模式:setenforce 1|0     (1代表:Enforcing,0代表Permissive)
设置文件:/etc/selinux/config      //影响下一次开机,重启生效(类似/etc/hostname)
例如:
  1. [root@svr7 ~]# setenforce 1     //临时切换运行模式
  2. [root@svr7 ~]# getenforce       //查看当前运行模式
  3. Enforcing
  4. [root@svr7 ~]# setenforce 0
  5. [root@svr7 ~]# getenforce
  6. Permissive
复制代码
例如:
  1. [root@svr7 ~]# vim /etc/selinux/config    //修改配置文件
  2. [root@svr7 ~]# cat /etc/selinux/config
  3. # This file controls the state of SELinux on the system.
  4. # SELINUX= can take one of these three values:
  5. #     enforcing - SELinux security policy is enforced.
  6. #     permissive - SELinux prints warnings instead of enforcing.
  7. #     disabled - No SELinux policy is loaded.
  8. SELINUX=permissive    //修改默认区域
  9. # SELINUXTYPE= can take one of three two values:
  10. #     targeted - Targeted processes are protected,
  11. #     minimum - Modification of targeted policy. Only selected processes are protected.
  12. #     mls - Multi Level Security protection.
  13. SELINUXTYPE=targeted
复制代码

二、构建Web服务

Web服务提供一个页面内容的服务
   

  • 提供Web服务的软件:Httpd、Nginx(支持并发访问量优秀)、Tomcat(Java)
  • Http协议:超文本传输协议(httpd,d表示:daemon进程)
  • Httpd默认存放页面路径:/var/www/html/    //安装httpd软件包自动生成路径
  • 默认索引页面文件: index.html
  1)运行提供web服务步伐
提前检查软件包
  1. [root@svr7 ~]# yum -y install httpd      //安装httpd软件包
  2. [root@svr7 ~]# rpm -q httpd
  3. httpd-2.4.6-80.el7.centos.x86_64
  4.  
  5. [root@pc207 ~]# curl http://192.168.4.7   //不运行执行程序则报错
  6. curl: (7) Failed connect to 192.168.4.7:80; 拒绝连接
  7. [root@svr7 ~]# which httpd    //服务安装完软件包后要运行程序
  8. /usr/sbin/httpd
  9. [root@svr7 ~]# /usr/sbin/httpd     //绝对路径运行程序
  10.  
  11. [root@svr7 ~]# vim /var/www/html/index.html    //编写页面文件
  12. [root@svr7 ~]# cat /var/www/html/index.html
  13. <h1> hello world       //<h1>:标题字体
  14. [root@svr7 ~]# ls /var/www/html/
  15. index.html
  16. [root@svr7 ~]# curl http://192.168.4.7
  17. <h1> hello world
复制代码
利用火狐欣赏器打开:# firefox http://192.168.4.7


增补:Curl命令
Curl是常用的命令行工具,用来哀求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思(支持HTTP、HTTPS、FTP、FTPS、DICT、TELNET、LDAP、FILE等协议)
作用:支持文件上传和下载,以是是综合传输工具
格式:curl [选项...]
常用选项:
   

  • [-l]  只得到对方的响应首部信息
  • [-v]  显示一次HTTP哀求的通讯过程
  
三、构建FTP服务

FTP服务:文本传输协议,传输内容
实现FTP服务功能的软件:vsftpd
默认共享数据的主目录:/var/ftp/
1)运行提供FTP服务步伐
提前检查软件包
  1. [root@svr7 ~]# yum -y install vsftpd    //安装vsftpd软件包
  2. [root@svr7 ~]# rpm -q vsftpd
  3. vsftpd-3.0.2-22.el7.x86_64
  4.  
  5. [root@svr7 ~]# curl ftp://192.168.4.7     //不运行执行程序则报错
  6. curl: (7) Failed connect to 192.168.4.7:21; 拒绝连接
  7. [root@svr7 ~]# which vsftpd
  8. /usr/sbin/vsftpd
  9. [root@svr7 ~]# /usr/sbin/vsftpd      //绝对路径运行程序
  10.  
  11. [root@svr7 ~]# ls /var/ftp/     //查看目录内容
  12. pub
  13. [root@svr7 ~]# touch /var/ftp/1.txt      //创建文件
  14. [root@svr7 ~]# curl ftp://192.168.4.7
  15. -rw-r--r--    1 0        0               0 Mar 12 03:30 1.txt
  16. drwxr-xr-x    2 0        0               6 Aug 03  2017 pub
复制代码

四、Firewalld防火墙计谋管理

作用:隔离,严格按照计谋规则过滤入站、放行出站
防火墙类型:硬件防火墙(Huawei E800)、软件防火墙(360、卡巴斯基)
体系服务:firewalld    //开机自启
管理工具:firewall-cmd、firewall-config(图形工具)

1、预设安全地区

根据所在的网络场所区分,预设掩护规则集
   

  • [ public ]  仅允许访问本机的sshd、dhcp、ping等少数几个服务
  • [ trusted ]  允许任何访问
  • [ block ]  拒绝任何来访哀求。明确拒绝并回应
  • [ drop ]  丢弃任何来访的数据包,不给任何回应
  设置规则的位置:

  • (runtime)  运行时
  • (permanent)  永久

2、检察防火墙规则列表

列表检察操作命令:


  • 命令:firewall-cmd --list-all [--zone=地区名] //检察当前地区规则信息
  • 命令:firewall-cmd --list-all-zones //检察所有地区规则信息
  • 命令:firewall-cmd --get-zones   //检察防火墙有哪些地区
  • 命令:firewall-cmd --get-services   //检察防火墙有哪些服务
  • 命令:firewall-cmd --get-default-zone   //检察当前默认地区
例如: 
  1. [root@svr7 ~]# firewall-cmd --list-all     //查看当前区域规则信息
  2. public (active)
  3.   target: default
  4.   icmp-block-inversion: no
  5.   interfaces: eth0
  6.   sources:
  7.   services: ssh dhcpv6-client
  8.   ports:
  9.   protocols:
  10.   masquerade: no
  11.   forward-ports:
  12.   source-ports:
  13.   icmp-blocks:
  14.   rich rules:
复制代码
例如:
  1. [root@svr7 ~]# firewall-cmd --list-all-zones      //查看所有区域规则信息
  2. block
  3.   target: %%REJECT%%
  4.   icmp-block-inversion: no
  5.   interfaces:
  6.   sources:
  7.   services:
  8.   ports:
  9.   protocols:
  10.   masquerade: no
  11.   forward-ports:
  12.   source-ports:
  13.   icmp-blocks:
  14.   rich rules:
  15.  
  16. dmz
  17.   target: default
  18.   icmp-block-inversion: no
  19.   interfaces:
  20.   sources:
  21.   services: ssh
  22.   ports:
  23.   protocols:
  24.   masquerade: no
  25.   forward-ports:
  26.   source-ports:
  27.   icmp-blocks:
  28.   rich rules:
  29.  
  30. drop
  31.   target: DROP
  32.   icmp-block-inversion: no
  33.   interfaces:
  34.   sources:
  35.   services:
  36.   ports:
  37.   protocols:
  38.   masquerade: no
  39.   forward-ports:
  40.   source-ports:
  41.   icmp-blocks:
  42.   rich rules:
  43.  
  44. external
  45.   target: default
  46.   icmp-block-inversion: no
  47.   interfaces:
  48.   sources:
  49.   services: ssh
  50.   ports:
  51.   protocols:
  52.   masquerade: yes
  53.   forward-ports:
  54.   source-ports:
  55.   icmp-blocks:
  56.   rich rules:
  57.  
  58. home
  59.   target: default
  60.   icmp-block-inversion: no
  61.   interfaces:
  62.   sources:
  63.   services: ssh mdns samba-client dhcpv6-client
  64.   ports:
  65.   protocols:
  66.   masquerade: no
  67.   forward-ports:
  68.   source-ports:
  69.   icmp-blocks:
  70.   rich rules:
  71.  
  72. internal
  73.   target: default
  74.   icmp-block-inversion: no
  75.   interfaces:
  76.   sources:
  77.   services: ssh mdns samba-client dhcpv6-client
  78.   ports:
  79.   protocols:
  80.   masquerade: no
  81.   forward-ports:
  82.   source-ports:
  83.   icmp-blocks:
  84.   rich rules:
  85.  
  86. public (active)
  87.   target: default
  88.   icmp-block-inversion: no
  89.   interfaces: eth0
  90.   sources:
  91.   services: ssh dhcpv6-client
  92.   ports:
  93.   protocols:
  94.   masquerade: no
  95.   forward-ports:
  96.   source-ports:
  97.   icmp-blocks:
  98.   rich rules:
  99.  
  100. trusted
  101.   target: ACCEPT
  102.   icmp-block-inversion: no
  103.   interfaces:
  104.   sources:
  105.   services:
  106.   ports:
  107.   protocols:
  108.   masquerade: no
  109.   forward-ports:
  110.   source-ports:
  111.   icmp-blocks:
  112.   rich rules:
  113.  
  114. work
  115.   target: default
  116.   icmp-block-inversion: no
  117.   interfaces:
  118.   sources:
  119.   services: ssh dhcpv6-client
  120.   ports:
  121.   protocols:
  122.   masquerade: no
  123.   forward-ports:
  124.   source-ports:
  125.   icmp-blocks:
  126.   rich rules:
复制代码
例如:
  1. [root@svr7 ~]# firewall-cmd --get-zones      //查看防火墙有哪些区域
  2. block dmz drop external home internal public trusted work
复制代码
例如:
  1. [root@svr7 ~]# firewall-cmd --get-services    //查看防火墙有哪些服务
  2. RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap
  3. imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nfs3
复制代码
例如:
  1. [root@svr7 ~]# firewall-cmd --get-default-zone     //查看当前默认区域
  2. public
复制代码

3、设置防火墙计谋

默认地区为public,限定较严格(对于开放式环境,建议将默认地区修改为trusted)
针对(运行时 / 永久)设置计谋规则时,运行时为暂时操作,永久需添加--permanent写入防火墙设置文件,写入后需要共同--reload重新加载设置文件或reboot重启才能生效
防火墙判断原则:根据客户端哀求的来源IP地址并检察防火墙地区规则哪个地区有该源IP地址规则,满意规则要求则进入该地区,否则进入默认地区(默认环境下为public)
设置防火墙地区命令:


  • 命令:firewall-cmd --set-default-zone=地区名
设置防火墙规则命令(运行时、永久):


  • 命令:firewall-cmd --zone=地区名 --add-service=服务名   //运行时-添加
  • 命令:firewall-cmd --permanent --zone=地区名 --add-source=网段/IP地址 //永久-限定
  • 命令:firewall-cmd --permanent --zone=地区名 --add-service=服务名  //永久-添加
  • 命令:firewall-cmd --permanent --zone=地区名 --remove-service=服务名  //永久删除
注意:permanent只用在防火墙规则,对设置默认地区无效,默认地区设置是永久生效
重载防火墙设置文件命令:


  • 命令:firewall-cmd --reload    //重载防火墙永久计谋,才能生效
注意:重载防火墙永久计谋,暂时计谋将清空

① 设置防火墙默认地区(指定默认的安全地区)
命令:firewall-cmd --set-default-zone=地区名
例如:修改主机1防火墙默认地区为trusted,主机2实现http和ftp访问
  1. 主机2:
  2. [root@pc207 ~]# curl http://192.168.4.7
  3. curl: (7) Failed connect to 192.168.4.7:80; 没有到主机的路由    //防火墙策略限制
  4. [root@pc207 ~]# curl ftp://192.168.4.7
  5. curl: (7) Failed connect to 192.168.4.7:21; 没有到主机的路由
  6.  
  7. 主机1:配置默认区域
  8. [root@svr7 ~]# firewall-cmd --get-default-zone     //查看防火墙默认区域
  9. public
  10. [root@svr7 ~]# firewall-cmd --set-default-zone=trusted   //修改防火墙默认区域
  11. success
  12. [root@svr7 ~]# firewall-cmd --get-default-zone
  13. trusted
  14. 主机2:
  15. [root@pc207 ~]# curl http://192.168.4.7   //验证http服务
  16. <h1> hello world
  17. [root@pc207 ~]# curl ftp://192.168.4.7    //验证ftp服务
  18. -rw-r--r--    1 0        0               0 Mar 12 03:30 1.txt
  19. drwxr-xr-x    2 0        0               6 Aug 03  2017 pub
复制代码

② 设置防火墙规则(默认地区开通服务)< 暂时生效 >
命令:firewall-cmd --zone=地区名 --add-service=服务名
例如:修改主机1防火墙默认地区public,添加服务,主机2实现http和ftp访问
  1. 主机1:
  2. [root@svr7 ~]# firewall-cmd --set-default-zone=public
  3. success
  4. [root@svr7 ~]# firewall-cmd --list-all --zone=public
  5. public (active)
  6.   target: default
  7.   icmp-block-inversion: no
  8.   interfaces: eth0
  9.   sources:
  10.   services: ssh dhcpv6-client        //允许服务中未有添加http和ftp
  11.   ports:
  12.   protocols:
  13.   masquerade: no
  14.   forward-ports:
  15.   source-ports:
  16.   icmp-blocks:
  17.   rich rules
  18. 主机2:
  19. [root@pc207 ~]# curl http://192.168.4.7     //访问失败
  20. curl: (7) Failed connect to 192.168.4.7:80; 没有到主机的路由   //防火墙策略限制
  21.  
  22. 主机1:
  23. [root@svr7 ~]# firewall-cmd --zone=public --add-service=http   //添加服务http
  24. success
  25. [root@svr7 ~]# firewall-cmd --zone=public --add-service=ftp   //添加服务ftp
  26. success
  27. [root@svr7 ~]# firewall-cmd --list-all --zone=public
  28. public (active)
  29.   target: default
  30.   icmp-block-inversion: no
  31.   interfaces: eth0
  32.   sources:
  33.   services: ssh dhcpv6-client http ftp    //允许服务中已添加http和ftp
  34.   ports:
  35.   protocols:
  36.   masquerade: no
  37.   forward-ports:
  38.   source-ports:
  39.   icmp-blocks:
  40.   rich rules:
  41. 主机2:
  42. [root@pc207 ~]# curl http://192.168.4.7     //访问成功
  43. <h1> hello world
  44. [root@pc207 ~]# curl ftp://192.168.4.7      //访问成功
  45. -rw-r--r--    1 0        0               0 Mar 12 03:30 1.txt
  46. drwxr-xr-x    2 0        0               6 Aug 03  2017 pub
复制代码

③ 设置防火墙规则(永久设置-添加)< 永久生效 >
命令:firewall-cmd --permanent --zone=地区名 --add-service=服务名
例如:修改永久防火墙规则设置,并重新加载永久防火墙计谋
  1. [root@svr7 ~]# firewall-cmd --reload    //重载防火墙永久策略,临时策略将清空
  2. success
  3. [root@svr7 ~]# firewall-cmd --zone=public --list-all
  4. public (active)
  5.   target: default
  6.   icmp-block-inversion: no
  7.   interfaces: eth0
  8.   sources:
  9.   services: ssh dhcpv6-client
  10.   ports:
  11.   protocols:
  12.   masquerade: no
  13.   forward-ports:
  14.   source-ports:
  15.   icmp-blocks:
  16.   rich rules:
  17. [root@svr7 ~]# firewall-cmd --permanent --zone=public --add-service=http
  18. success
  19. [root@svr7 ~]# firewall-cmd --permanent --zone=public --add-service=ftp
  20. success
  21. [root@svr7 ~]# firewall-cmd --zone=public --list-all
  22. public (active)
  23.   target: default
  24.   icmp-block-inversion: no
  25.   interfaces: eth0
  26.   sources:
  27.   services: ssh dhcpv6-client
  28.   ports:
  29.   protocols:
  30.   masquerade: no
  31.   forward-ports:
  32.   source-ports:
  33.   icmp-blocks:
  34.   rich rules:
  35. [root@svr7 ~]# firewall-cmd --reload    //重载防火墙永久策略,才能生效
  36. success
  37. [root@svr7 ~]# firewall-cmd --zone=public --list-all
  38. public (active)
  39.   target: default
  40.   icmp-block-inversion: no
  41.   interfaces: eth0
  42.   sources:
  43.   services: ssh dhcpv6-client http ftp
  44.   ports:
  45.   protocols:
  46.   masquerade: no
  47.   forward-ports:
  48.   source-ports:
  49.   icmp-blocks:
  50.   rich rules:
复制代码

④ 设置防火墙规则(永久设置-删除)< 永久生效 >
命令:firewall-cmd --permanent --zone=地区名 --remove-service=服务名
例如:永久修改并删除ftp服务
  1. [root@svr7 ~]# firewall-cmd --permanent --zone=public --remove-service=ftp
  2. success
  3. [root@svr7 ~]# firewall-cmd --zone=public --list-all
  4. public (active)
  5.   target: default
  6.   icmp-block-inversion: no
  7.   interfaces: eth0
  8.   sources:
  9.   services: ssh dhcpv6-client http ftp
  10.   ports:
  11.   protocols:
  12.   masquerade: no
  13.   forward-ports:
  14.   source-ports:
  15.   icmp-blocks:
  16.   rich rules:
  17. [root@svr7 ~]# firewall-cmd --reload
  18. success
  19. [root@svr7 ~]# firewall-cmd --zone=public --list-all
  20. public (active)
  21.   target: default
  22.   icmp-block-inversion: no
  23.   interfaces: eth0
  24.   sources:
  25.   services: ssh dhcpv6-client http
  26.   ports:
  27.   protocols:
  28.   masquerade: no
  29.   forward-ports:
  30.   source-ports:
  31.   icmp-blocks:
  32.   rich rules:
复制代码

⑤ 设置防火墙规则(添加限定网段)
命令:firewall-cmd [--permanent] --zone=地区名 --add-source=网段/IP地址
例如:修改主机1防火墙默认地区规则,拒绝主机2网段、服务访问本机
  1. 主机1:
  2. [root@svr7 ~]# firewall-cmd --zone=block --add-source=192.168.4.0/24
  3. success
  4. =[root@svr7 ~]# firewall-cmd --zone=block --list-all
  5. block (active)
  6.   target: %%REJECT%%
  7.   icmp-block-inversion: no
  8.   interfaces:
  9.   sources: 192.168.4.0/24
  10.   services:
  11.   ports:
  12.   protocols:
  13.   masquerade: no
  14.   forward-ports:
  15.   source-ports:
  16.   icmp-blocks:
  17.   rich rules:
  18.  
  19. 主机2:
  20. [root@pc207 ~]# curl ftp://192.168.4.7
  21. curl: (7) Failed connect to 192.168.4.7:21; 没有到主机的路由
  22. [root@pc207 ~]# curl http://192.168.4.7
  23. curl: (7) Failed connect to 192.168.4.7:80; 没有到主机的路由
  24. [root@pc207 ~]# ssh root@192.168.4.7
  25. ssh: connect to host 192.168.4.7 port 22: No route to host
  26. [root@pc207 ~]# ping 192.168.4.7
  27. PING 192.168.4.7 (192.168.4.7) 56(84) bytes of data.
  28. From 192.168.4.7 icmp_seq=1 Destination Host Prohibited
  29. From 192.168.4.7 icmp_seq=2 Destination Host Prohibited
  30. ^C
  31. --- 192.168.4.7 ping statistics ---
  32. 2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1000ms
复制代码
常见报错:已经是block地区报错
  1. [root@svr7 ~]# firewall-cmd --set-default-zone=block
  2. Warning: ZONE_ALREADY_SET: block
复制代码
常见报错:--get不与--list-all共用
  1. [root@svr7 ~]# firewall-cmd --get-default-zone --list-all
  2. usage: see firewall-cmd man page
  3. Can't use stand-alone options with other options.
复制代码
常见报错:规则辩论
  1. [root@svr7 ~]# firewall-cmd --zone=block --add-source=192.168.4.0/24
  2. success
  3. [root@svr7 ~]# firewall-cmd --zone=trusted --add-source=192.168.4.0/24
  4. Error: ZONE_CONFLICT: '192.168.4.0/24' already bound to a zone
复制代码

五、体系故障修复排除

1)忘记root用户暗码
故障现象:无法执行需要root权限的管理操作,若没有其他可用账号,将无法登录体系;
解决思路:引导进入修复模式,然后重设暗码;
步调1:重启体系,进入recovery恢复模式


  • 按e键,找到linux16行,末尾添加rd.break console=tty0
  • 按ctrl+x启动
步调2:以可写方式重新挂载/sysroot,并切换到此环境
  1. Switch_root# mount -o remount,rw /sysroot
  2. Switch_root# chroot /sysroot
复制代码
步调3:将root用户的暗码设置为redhat
  1. echo redhat | passwd --stdin root
复制代码
步调4:重设SELinux安全标签
  1. touch /.autorelabel
复制代码
步调5:先后执行exit、reboot完成恢复
  1. exit
  2. reboot
复制代码

2)体系文件破坏故障
- 故障现象:/etc/fstab文件内容有误,体系无法正常开机
- 解决思路:引导进入恢复模式,然后进行修复

六、Systemd服务管理

1)init步伐的作用(即初始化步伐)
Linux体系和服务管理器systemd,是内核引导之后加载的第一个初始化进程(PID=1),负责掌控整个Linux的运行/服务资源组合;
传统的init步伐风格:


  • System v:序次加载(RHEL5系列采用)
  • Upstart:变乱触发(RHEL6系列采用)
2)Systemd服务管理器(一个更高效的体系&服务管理器)
开机服务并行启动,各体系服务间的精确依赖
设置目录:/etc/systemd/system/
服务目录:/lib/systemd/system/
主要管理工具:systemctl
3)列出服务常用命令
列出活动的体系服务


  • 命令:systemctl -t service
列出所有体系服务(包括不活动的)


  • 命令:systemctl -t service --all //列出所有的服务

4)对于服务的管理(与手动启动有辩论)


  • 命令:systemctl restart 服务名   //重起服务
  • 命令:systemctl start 服务名      //开启服务
  • 命令:systemctl stop 服务名      //制止服务
  • 命令:systemctl status 服务名    //检察服务当前的状态
  • 命令:systemctl enable 服务名    //设置服务开机自启动
  • 命令:systemctl disable 服务名    //设置服务克制开机自启动
  • 命令:systemctl is-enabled 服务名   //检察服务是否开机自启
  • 命令:systemctl is-active 服务名    //检察服务是否开启
  • 命令:systemctl daemon-reload    //重新加载所有服务设置文件
例如:
  1. [root@svr7 ~]# yum -y install httpd    //安装软件包
  2. [root@svr7 ~]# rpm -q httpd
  3. httpd-2.4.6-80.el7.centos.x86_64
  4. [root@svr7 ~]# > /etc/resolv.conf    //清除dns文件内容
  5. [root@svr7 ~]# /usr/sbin/httpd     //手动启动httpd程序
  6. [root@svr7 ~]# pgrep -lx httpd    //查看进程信息
  7. 3387 httpd
  8. [root@svr7 ~]# killall httpd      //杀死手动启动的httpd,否则会与服务管理器冲突
  9. [root@svr7 ~]# systemctl restart httpd     //重启httpd服务
  10. [root@svr7 ~]# pgrep -lx httpd
  11. 3420 httpd
  12. 3430 httpd
  13. 3431 httpd
  14. 3432 httpd
  15. 3433 httpd
  16. 3434 httpd
  17. [root@svr7 ~]# systemctl status httpd     //查看服务httpd状态
  18. ● httpd.service - The Apache HTTP Server
  19.    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  20.    Active: active (running) since 一 2021-03-15 09:56:17 CST; 36s ago
  21.      Docs: man:httpd(8)
  22.            man:apachectl(8)
  23.  Main PID: 3639 (httpd)
  24.    Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
  25.     Tasks: 6
  26.    CGroup: /system.slice/httpd.service
  27.            ├─3639 /usr/sbin/httpd -DFOREGROUND
  28.            ├─3640 /usr/sbin/httpd -DFOREGROUND
  29.            ├─3641 /usr/sbin/httpd -DFOREGROUND
  30.            ├─3642 /usr/sbin/httpd -DFOREGROUND
  31.            ├─3643 /usr/sbin/httpd -DFOREGROUND
  32.            └─3644 /usr/sbin/httpd -DFOREGROUND
  33. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: Starting The Apache HTTP Server...
  34. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: Started The Apache HTTP Server.
  35.  
  36. [root@svr7 ~]# systemctl enable httpd     //设置httpd开机自启动
  37. Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
  38. [root@svr7 ~]# systemctl is-enabled httpd     //查看httpd是否是开机自启动
  39. enabled
  40.  
  41. [root@svr7 ~]# systemctl disable httpd    //关闭httpd开机自启动
  42. Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
  43. [root@svr7 ~]# systemctl is-enabled httpd   //查看httpd是否是开机自启动
  44. disabled
  45.  
  46. [root@svr7 ~]# systemctl stop httpd   //停止服务
  47. [root@svr7 ~]# systemctl status httpd
  48. ● httpd.service - The Apache HTTP Server
  49.    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  50.    Active: inactive (dead)
  51.      Docs: man:httpd(8)
  52.            man:apachectl(8)
  53. 3月 15 09:53:49 svr7.tedu.cn systemd[1]: Starting The Apache HTTP Server...
  54. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: httpd.service stop-sigterm timed out. Killing.
  55. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: httpd.service: main process exited, code=killed, status=9/KILL
  56. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: Unit httpd.service entered failed state.
  57. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: httpd.service failed.
  58. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: Starting The Apache HTTP Server...
  59. 3月 15 09:56:17 svr7.tedu.cn systemd[1]: Started The Apache HTTP Server.
  60. 3月 15 10:19:24 svr7.tedu.cn systemd[1]: Stopping The Apache HTTP Server...
  61. 3月 15 10:19:25 svr7.tedu.cn systemd[1]: Stopped The Apache HTTP Server.
  62. Hint: Some lines were ellipsized, use -l to show in full.
复制代码

七、管理运行级别

1)RHEL6:运行级别,共300个服务
   

  • 0:关机,0个服务(类似poweroff)
  • 1:单用户模式(根本功能的实现,破解Linux暗码),50个服务
  • 2:多用户字符界面(不支持网络),80个服务
  • 3:多用户字符界面(支持网络)服务器默认运行级别,100个服务
  • 4:暂未界说,0个服务
  • 5:图形界面(功能丰富,但占用资源最高),300个服务
  • 6:重起,0个服务(类似reboot)
  切换运行级别:init 数字
注意:5级别,前提是已安装图形界面工具的软件包;
注意:RHEL8的8.5版本将取消运行级别;
2)RHEL7:运行模式(运行级别)


  • 字符模式:multi-user.target(类似RHEL6运行级别3)
  • 图形模式:graphical.target(类似RHEL6运行级别5)
3)切换运行模式
① 列出可用运行模式
- 命令:systemctl -t target
② 当前直接切换到字符模式 (影响当前)
- 命令:systemctl isolate multi-user.target //相当于原来的init 3
③ 当前直接切换到图形模式(影响当前)
- 命令:systemctl isolate graphical.target //相当于原来的init 5
4)设置默认运行模式
① 检察默认级别
- 命令:systemctl get-default
② 设置默认级别
- 命令:systemctl set-default multi-user.target
- 命令:systemctl set-default graphical.target
例如:
  1. [root@svr7 ~]# systemctl -t target     //列出可运行模式
  2. UNIT                   LOAD   ACTIVE SUB    DESCRIPTION
  3. basic.target           loaded active active Basic System
  4. cryptsetup.target      loaded active active Local Encrypted Volumes
  5. getty-pre.target       loaded active active Login Prompts (Pre)
  6. getty.target           loaded active active Login Prompts
  7. graphical.target       loaded active active Graphical Interface
  8. local-fs-pre.target    loaded active active Local File Systems (Pre)
  9. local-fs.target        loaded active active Local File Systems
  10. multi-user.target      loaded active active Multi-User System
  11. network-online.target  loaded active active Network is Online
  12. network-pre.target     loaded active active Network (Pre)
  13. network.target         loaded active active Network
  14. nfs-client.target      loaded active active NFS client services
  15. nss-user-lookup.target loaded active active User and Group Name Lookups
  16. paths.target           loaded active active Paths
  17. remote-fs-pre.target   loaded active active Remote File Systems (Pre)
  18. remote-fs.target       loaded active active Remote File Systems
  19. rpc_pipefs.target      loaded active active rpc_pipefs.target
  20. slices.target          loaded active active Slices
  21. sockets.target         loaded active active Sockets
  22. sound.target           loaded active active Sound Card
  23. swap.target            loaded active active Swap
  24. sysinit.target         loaded active active System Initialization
  25. timers.target          loaded active active Timers
  26. LOAD   = Reflects whether the unit definition was properly loaded.
  27. ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
  28. SUB    = The low-level unit activation state, values depend on unit type.
  29. 23 loaded units listed. Pass --all to see loaded but inactive units, too.
  30. To show all installed unit files use 'systemctl list-unit-files'.
复制代码

例如:切换运行模式为字符模式
  1. [root@svr7 ~]# systemctl isolate multi-user.target
复制代码
如图所示:


例如:切换运行模式为图形模式
  1. [root@svr7 ~]# systemctl isolate graphical.target
复制代码
如图所示:

例如:
  1. [root@svr7 ~]# systemctl set-default multi-user.target    //设置默认运行模式
  2. Removed symlink /etc/systemd/system/default.target.
  3. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
  4. [root@svr7 ~]# systemctl get-default
  5. multi-user.target
  6. [root@svr7 /]# reboot     //重启验证
复制代码
例如:设置永久计谋,每次开机自动进入graphical.target字符模式
  1. [root@svr7 ~]# systemctl isolate graphical.target
  2. [root@svr7 ~]# systemctl set-default graphical.target    //设置默认运行模式
  3. Removed symlink /etc/systemd/system/default.target.
  4. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target
  5. [root@svr7 ~]# systemctl get-default
  6. graphical.target
  7. [root@svr7 /]# reboot     //重启验证
复制代码

增补:ssh登录提示
记任命户登录记录/root/.sshr/known_hosts,同一用户登录,记录不一样会报错

小结:

本篇章节为 【第一阶段】ENGINEER-DAY5 的学习笔记,可以开端了解到 SELinux、体系故障修复、HTTPD/FTP服务搭建、防火墙计谋管理、服务管理。除此之外推荐参考相关学习网址:


  • 菜鸟教程 - 学的不仅是技能,更是梦想!

Tip:毕竟两个人的聪明大于一个人的聪明,如果你不明白本章节的内容或需要相关笔记、视频,可私信小安,请不要害羞和回避,可以向他人请教,花点时间直到你真正的明白

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

曂沅仴駦

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表