码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 7、系统管理


    文章目录

    • 7、系统管理
      • 7.1 Linux 中的进程和服务
      • 7.2 service 服务管理(CentOS 6 版本-了解)
        • 7.2.1 基本语法
        • 7.2.2 经验技巧
        • 7.2.3 案例实操
          • (1)查看网络服务的状态
          • (2)停止网络服务
          • (3)启动网络服务
          • (4)重启网络服务
      • 7.3 chkconfig 设置后台服务的自启配置(CentOS 6 版本)
        • 7.3.1 基本语法
        • 7.3.2 案例实操
          • (1)开启/关闭 network(网络)服务的自动启动
          • (2)开启/关闭 network 服务指定级别的自动启动
      • 7.4 systemctl (CentOS 7 版本-重点掌握)
        • 7.4.1 基本语法
        • 7.4.2 经验技巧
        • 7.4.3 案例实操
          • (1)查看防火墙服务的状态
          • (2)停止防火墙服务
          • (3)启动防火墙服务
          • (4)重启防火墙服务
      • 7.5 systemctl 设置后台服务的自启配置
        • 7.5.1 基本语法
        • 7.5.2 案例实操
          • (1)开启/关闭 iptables(防火墙)服务的自动启动
          • (2)图形化操作
      • 7.6 系统运行级别
        • 7.6.1 Linux 运行级别[CentOS 6]
        • 7.6.2 CentOS7 的运行级别简化为:
        • 7.6.3 查看当前运行级别:
        • 7.6.4 修改当前运行级别
      • 7.7 关闭防火墙
        • 7.7.1 临时关闭防火墙
          • (1)查看防火墙状态
          • (2)临时关闭防火墙
        • 7.7.2 开机启动时关闭防火墙
          • (1)查看防火墙开机启动状态
          • (2)设置开机时关闭防火墙
      • 7.8 关机重启命令
        • 7.8.1 基本语法
        • 7.8.2 经验技巧
        • 7.8.3 案例实操
          • (1)将数据由内存同步到硬盘中
          • (2)重启
          • (3)停机(不断电)
          • (4)计算机将在 1 分钟后关机,并且会显示在登录用户的当前屏幕中
          • (5)立马关机(等同于 poweroff)
          • (6)系统立马重启(等同于 reboot)


    尚硅谷2022版Linux教程-讲师:武晟然

    壁立千仞 无欲则刚

    7、系统管理

    7.1 Linux 中的进程和服务

    计算机中,一个正在执行的程序或命令,被叫做“进程”(process)。
    启动之后一只存在、常驻内存的进程,一般被称作“服务”(service)。

    7.2 service 服务管理(CentOS 6 版本-了解)

    7.2.1 基本语法

    service 服务名 start | stop | restart | status

    7.2.2 经验技巧

    查看服务的方法:/etc/init.d/服务名 ,发现只有两个服务保留在 servic

    [root@centos7:101 init.d]# pwd
    /etc/init.d
    [root@centos7:101 init.d]# ls -al
    drwxr-xr-x. 2 root root 4096 3 月 19 15:24 .
    drwxr-xr-x. 10 root root 4096 3 月 19 15:24 ..
    -rw-r--r--. 1 root root 18104 1 月 3 2018 functions
    -rwxr-xr-x. 1 root root 4334 1 月 3 2018 netconsole
    -rwxr-xr-x. 1 root root 7293 1 月 3 2018 network
    -rw-r--r--. 1 root root 1160 4 月 11 2018 READ
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    7.2.3 案例实操

    (1)查看网络服务的状态
    [root@centos7:101 ~]# service network status
    
    • 1
    (2)停止网络服务
    [root@centos7:101 ~]# service network stop
    
    • 1
    (3)启动网络服务
    [root@centos7:101 ~]# service network start
    
    • 1
    (4)重启网络服务
    [root@centos7:101 ~]# service network restart
    
    • 1

    7.3 chkconfig 设置后台服务的自启配置(CentOS 6 版本)

    7.3.1 基本语法

    chkconfig (功能描述:查看所有服务器自启配置)
    chkconfig 服务名 off (功能描述:关掉指定服务的自动启动)
    chkconfig 服务名 on (功能描述:开启指定服务的自动启动)
    chkconfig 服务名 --list (功能描述:查看服务开机启动状态)

    7.3.2 案例实操

    (1)开启/关闭 network(网络)服务的自动启动
    [root@centos7:101 ~]# chkconfig network on
    [root@centos7:101 ~]# chkconfig network off
    
    • 1
    • 2
    (2)开启/关闭 network 服务指定级别的自动启动
    [root@centos7:101 ~]# chkconfig --level 指定级别 network on
    [root@centos7:101 ~]# chkconfig --level 指定级别 network off
    
    • 1
    • 2

    7.4 systemctl (CentOS 7 版本-重点掌握)

    7.4.1 基本语法

    systemctl start | stop | restart | status 服务名

    7.4.2 经验技巧

    查看服务的方法:/usr/lib/systemd/system

    [root@centos7:101 system]# pwd
    /usr/lib/systemd/system
    [root@centos7:101 init.d]# ls -al
    -rw-r--r--. 1 root root 275 4 月 27 2018 abrt-ccpp.serv
    -rw-r--r--. 1 root root 380 4 月 27 2018 abrtd.service
    -rw-r--r--. 1 root root 361 4 月 27 2018 abrt-oops.service
    -rw-r--r--. 1 root root 266 4 月 27 2018 abrt-pstoreoops.service
    -rw-r--r--. 1 root root 262 4 月 27 2018 abrt-vmcore.service
    -rw-r--r--. 1 root root 311 4 月 27 2018 abrt-xorg.service
    -rw-r--r--. 1 root root 751 4 月 11 2018 accounts-daemon.service
    -rw-r--r--. 1 root root 527 3 月 25 2017 alsa-restore.service
    -rw-r--r--. 1 root root 486 3 月 25 2017 alsa-state.service
    ……
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    7.4.3 案例实操

    (1)查看防火墙服务的状态
    [root@centos7:101 ~]# systemctl status firewalld
    
    • 1
    (2)停止防火墙服务
    [root@centos7:101 ~]# systemctl stop firewalld
    
    • 1
    (3)启动防火墙服务
    [root@centos7:101 ~]# systemctl start firewalld
    
    • 1
    (4)重启防火墙服务
    [root@centos7:101 ~]# systemctl restart firewalld
    
    • 1

    7.5 systemctl 设置后台服务的自启配置

    7.5.1 基本语法

    systemctl list-unit-files (功能描述:查看服务开机启动状态)
    systemctl disable service_name (功能描述:关掉指定服务的自动启动)
    systemctl enable service_name (功能描述:开启指定服务的自动启动)

    7.5.2 案例实操

    (1)开启/关闭 iptables(防火墙)服务的自动启动
    [root@centos7:101 ~]# systemctl enable firewalld.service
    [root@centos7:101 ~]# systemctl disable firewalld.service
    
    • 1
    • 2
    (2)图形化操作
    [root@centos7-101 ~]# setup
    
    • 1

    7.6 系统运行级别

    7.6.1 Linux 运行级别[CentOS 6]

    在这里插入图片描述

    7.6.2 CentOS7 的运行级别简化为:

    multi-user.target 等价于原运行级别 3(多用户有网,无图形界面)
    graphical.target 等价于原运行级别 5(多用户有网,有图形界面)

    7.6.3 查看当前运行级别:

    [root@centos7:101 ~]# systemctl get-default
    
    • 1

    7.6.4 修改当前运行级别

    [root@centos7:101 ~]# systemctl set-default TARGET.target 
    
    • 1

    (这里 TARGET 取 multi-user 或者 graphical)

    7.7 关闭防火墙

    7.7.1 临时关闭防火墙

    (1)查看防火墙状态
    [root@centos7:101 ~]# systemctl status firewalld
    
    • 1
    (2)临时关闭防火墙
    [root@centos7:101 ~]# systemctl stop firewalld
    
    • 1

    7.7.2 开机启动时关闭防火墙

    (1)查看防火墙开机启动状态
    [root@centos7:101 ~]# systemctl enable firewalld.service
    
    • 1
    (2)设置开机时关闭防火墙
    [root@centos7:101 ~]# systemctl disable firewalld.service 
    
    • 1

    7.8 关机重启命令

    在 linux 领域内大多用在服务器上,很少遇到关机的操作。毕竟服务器上跑一个服务是永无止境的,除非特殊情况下,不得已才会关机。

    7.8.1 基本语法

    (1)sync (功能描述:将数据由内存同步到硬盘中)
    (2)halt (功能描述:停机,关闭系统,但不断电)
    (3)poweroff (功能描述:关机,断电)
    (3)reboot (功能描述:就是重启,等同于 shutdown -r now)
    (4)shutdown [选项] 时间

    选项功能
    -H相当于–halt,停机
    -r-r=reboot 重启
    参数功能
    now立刻关机
    时间等待多久后关机(时间单位是分钟)。

    7.8.2 经验技巧

    Linux 系统中为了提高磁盘的读写效率,对磁盘采取了 “预读迟写”操作方式。当用户保存文件时,Linux 核心并不一定立即将保存数据写入物理磁盘中,而是将数据保存在缓冲区中,等缓冲区满时再写入磁盘,这种方式可以极大的提高磁盘写入数据的效率。但是,也带来了安全隐患,如果数据还未写入磁盘时,系统掉电或者其他严重问题出现,则将导致数据丢失。使用 sync 指令可以立即将缓冲区的数据写入磁盘。

    7.8.3 案例实操

    (1)将数据由内存同步到硬盘中
    [root@centos7:101 ~]#sync 
    
    • 1
    (2)重启
    [root@centos7:101 ~]# reboot
    
    • 1
    (3)停机(不断电)
    [root@centos7:101 ~]#halt
    
    • 1
    (4)计算机将在 1 分钟后关机,并且会显示在登录用户的当前屏幕中
    [root@centos7:101 ~]#shutdown -h 1 ‘This server will shutdown after 1 mins’ 
    
    • 1
    (5)立马关机(等同于 poweroff)
    [root@centos7:101 ~]# shutdown -h now 
    
    • 1
    (6)系统立马重启(等同于 reboot)
    [root@centos7:101 ~]# shutdown -r
    
    • 1
  • 相关阅读:
    Ps:变换
    Unity(第十八部)物理力学,碰撞,触发、关节和材质
    【不看答案挑战,今天你刷题了吗?】LeetCode33,题目+解析+答案
    (一分钟看懂4种拒绝策略) java多线程拒绝策略
    本地环境下启动openFaas创建的Java的云函数
    【KELM分类】基于matlab鲸鱼算法优化KELM分类【含Matlab源码 2033期】
    【Spring】初阶三 - AOP
    opencv 入门学习
    thinkphp5实现多数据库连接
    centos7配置
  • 原文地址:https://blog.csdn.net/zhao854116434/article/details/127987762
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号