7、系统管理

文章目录


尚硅谷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 319 15:24 .
drwxr-xr-x. 10 root root 4096 319 15:24 ..
-rw-r--r--. 1 root root 18104 13 2018 functions
-rwxr-xr-x. 1 root root 4334 13 2018 netconsole
-rwxr-xr-x. 1 root root 7293 13 2018 network
-rw-r--r--. 1 root root 1160 411 2018 READ

7.2.3 案例实操

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

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
(2)开启/关闭 network 服务指定级别的自动启动
[root@centos7:101 ~]# chkconfig --level 指定级别 network on
[root@centos7:101 ~]# chkconfig --level 指定级别 network off

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 427 2018 abrt-ccpp.serv
-rw-r--r--. 1 root root 380 427 2018 abrtd.service
-rw-r--r--. 1 root root 361 427 2018 abrt-oops.service
-rw-r--r--. 1 root root 266 427 2018 abrt-pstoreoops.service
-rw-r--r--. 1 root root 262 427 2018 abrt-vmcore.service
-rw-r--r--. 1 root root 311 427 2018 abrt-xorg.service
-rw-r--r--. 1 root root 751 411 2018 accounts-daemon.service
-rw-r--r--. 1 root root 527 325 2017 alsa-restore.service
-rw-r--r--. 1 root root 486 325 2017 alsa-state.service
……

7.4.3 案例实操

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

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
(2)图形化操作
[root@centos7-101 ~]# setup

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

7.6.4 修改当前运行级别

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

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

7.7 关闭防火墙

7.7.1 临时关闭防火墙

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

7.7.2 开机启动时关闭防火墙

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

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 
(2)重启
[root@centos7:101 ~]# reboot
(3)停机(不断电)
[root@centos7:101 ~]#halt
(4)计算机将在 1 分钟后关机,并且会显示在登录用户的当前屏幕中
[root@centos7:101 ~]#shutdown -h 1 ‘This server will shutdown after 1 mins’ 
(5)立马关机(等同于 poweroff)
[root@centos7:101 ~]# shutdown -h now 
(6)系统立马重启(等同于 reboot)
[root@centos7:101 ~]# shutdown -r
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值