CentOS 软件和服务管理

  • 常见的Yum 命令
  • systemd初始化进程
  • systemd 与 System V init 的区别以及作用
  • systemctl 管理服务的启动、重启、重载、查看状态等命令
  • systemctl设置服务开机启动、不启动、查看各级别下服务启动状态等常用命令


Yum 软件仓库是为了进一步降低软件安装难度和复杂度而设计的技术。

Yum 软件仓库可以根据用户的要求分析出所需软件包及其相关的依赖关系,然后自动从服务器下载软件包并安装到系统。

常见的Yum 命令

命令

作用

yum repolist all

列出所有仓库

yum list all

列出仓库中所有软件包

yum info 软件包名称

查看软件包信息

yum install 软件包名称

安装软件包

yum reinstall 软件包名称

重新安装软件包

yum update 软件包名称

升级软件包

yum remove 软件包名称

移除软件包

yum clean all

清除所有仓库缓存

yum check-update

检查可更新的软件包

yum grouplist

查看系统中已经安装的软件包组

yum groupinstall 软件包组

安装指定的软件包组

yum groupremove 软件包组

移除指定的软件包组

yum groupinfo 软件包组

查询指定的软件包组信息

systemd初始化进程

Linux 操作系统的开机过程是这样的,即从BIOS开始,然后进入Boot Loader,再加载系统内核,然后内核进行初始化,最后启动初始化进程。

初始化进程作为Linux系统的第一个进程,它需要完成Linux系统中相关的初始化工作,为用户提供合适的工作环境。

CentOS7 系统已经替换掉了熟悉的初始化进程服务 System V init,正式采用全新的systemd 初始化进程服务采用了并发启动机制,开机速度得到了不小的提升。

CentOS7 系统选择systemd 初始化进程服务已经没有了“运行级别”的概念,Linux系统在启动时要进行大量的初始化工作,比如挂载文件系统和交换分区、启动各类进程服务等,这些都可以看作是一个一个的单元(Unit),systemd 用目标(target)代替了 System V init 中运行级别的概念。

systemd 与 System V init 的区别以及作用

System V init运行级别

systemd 目标名称

作用

0

runleve10.target,poweroff.target

关机

1

runleve11.target,rescue.target

单用户模式

2

runleve12.target,multi-user.target

等同于级别3

3

runleve13.target,multi-user.target

多用户的文本界面

4

runleve14.target,multi-user.target

等同于级别3

5

runleve15.target,graphical.target

多用户的图形界面

6

runleve16.target,reboot.target

重启

emergency

emergency.target

紧急Shell

如果想要将系统默认的运行目标修改为“多用户,无图形”模式,可直接用 ln 命令把多用户模式目标文件连接到 /etc/systemd/system/ 目录:

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

CentOS 6 使用 service、 chkconfig 等命令来管理系统服务。

CentOS 7 使用 systemctl 命令来管理服务。

systemctl 管理服务的启动、重启、重载、查看状态等命令

System V init命令(CentOS6)

systemctl 命令(CentOS7)

作用

service foo start

systemctl start foo.service

启动服务

service foo restart

systemctl restart foo.service

重启服务

service foo stop

systemctl stop foo.service

停止服务

service foo reload

systemctl reload foo.service

重新加载配置文件(不终止服务)

service foo status

systemctl status foo.service

查看服务状态

systemctl设置服务开机启动、不启动、查看各级别下服务启动状态等常用命令

System V init命令(CentOS6)

systemctl 命令(CentOS7)

作用

chkconfig foo on

systemctl enable foo.service

开机自动启动

chkconfig foo off

systemctl disable foo.service

开机不自动启动

chkconfig foo

systemctl is-enabled foo.service

查看服务是否为开机启动

chkconfig foo --list

systemctl list-unit-files --type=service

查看各级别下服务启动与禁用情况