
linux运行模式与软件管理
“这江湖也没什么,也就酒还不错,我会学着喝点儿”

一、什么是运行模式
运行模式也叫做运行级别(在centos7里叫target)。在linux进入系统时会运行第一支程序,这个程序运行时会从5种模式中选择一种运行,这里的5种模式,就是运行模式。
第一支程序说明:
在centos6叫做 systemV
在centos7叫做systemd
因此在centos6和centos7里面的运行级别也发生了一些变化
二、运行级别说明
| SystemV(centos6) | systemd(centos7) | 含义 |
|---|---|---|
| init0 | systemctl poweroff | 关机 |
| Init1 | systemctl rescue | 单用户模式(用于维护) |
| Init[234] | systemctl isolate multi-user.target | 命令行模式 |
| Init5 | systemctl isolate graphical.target | 图形界面模式 |
| init6 | systemctl reboot | 重启 |
三、运行模式管理
1. 获取当前运行模式
[root@CaiChen ~]# systemctl get-default
graphical.target
2. 临时设置运行模式
# 切换为命令行模式
[root@CaiChen ~]# systemctl isolate multi-user.target
# 兼容centos6命令(和上面命令效果相同)
[root@CaiChen ~]# init 3
# 切换为图形界面模式
[root@CaiChen ~]# systemctl isolate graphical.target
[root@CaiChen ~]# init 5
根据上面2个模式,可以练习下模式0和模式6
2. 设定系统默认运行模式(永久设置)
# 设定默认运行模式为命令行模式
[root@CaiChen ~]# systemctl set-default multi-user.target
# 设定默认运行模式为图形界面模式
[root@CaiChen ~]# systemctl set-default graphical.target
注意:
- 设定之后,系统以后就会以该模式运行
- 切记不要设置为poweroff 和 reboot模式
四、RPM包管理
RPM全名是[RedHat Package Manager,是由Red Hat公司开发出来,由于非常好用,目前被很多linux发行版使用。
特点:
- 由于已经编译打包完毕,所以软件传输与安装很方便
- 查询、升级方便
1. RPM软件包常用命令
| 命令 | 作用 |
|---|---|
| rpm -ivh filename.rpm | 安装软件 |
| rpm -Uvh filename.rpm | 升级软件 |
| rpm -e filename.rpm | 卸载软件 |
| rpm -qpi filename.rpm | 查询软件的描述信息 |
| rpm -qa | 查询系统中所有的rpm软件 |
2. 案例
# 查看系统中是否已经安装了firefox
[root@CaiChen ~]# rpm -qa | grep firefox
firefox-24.5.0-1.el7.centos.x86_64
# 如果安装先进行卸载
[root@CaiChen ~]# rpm -e firefox
# 进入系统镜像中的Packages目录
[root@CaiChen Packages]# rpm -ivh firefox-24.5.0-1.el7.centos.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:firefox-24.5.0-1.el7.centos ################################# [100%]
RPM虽然能够使软件安装变得方便,但是在安装软件的时候依赖关系仍然需要自己解决,有些大型软件需要十多个依赖包,安装会变得复杂。这时候有进一步简化RPM管理软件的方式yum安装。
五、yum软件管理
yum软件管理是为了进一步简化RPM管理软件难度而设计的,yum能够根据用户的需求分析出所需软件包及相关依赖关系,自动从服务器下载软件包并安装到系统。
yum软件仓库:yum在下载软件时存放软件包的远程服务器
1. yum常用命令
| 命令 | 作用 |
|---|---|
| yum remove 软件包 | 移除软件包 |
| yum [-y] install 软件包名称 | 安装软件包(加y在安装时候不用输入y确认) |
| yum update 软件包名称 | 升级软件包 |
| yum list installed | 查看已安装软件包 |
2. 案例
# 查看是否安装了firefox
[root@CaiChen Packages]# yum list installed | grep firefox
firefox.x86_64 24.5.0-1.el7.centos @anaconda
[root@CaiChen Packages]# yum remove firefox
移除 1 软件包
安装大小:87 M
是否继续?[y/N]: //此处输入y
[root@CaiChen Packages]# yum install firefox
六、源码包管理
源码包,提供了源代码需要进行配置编译才能进行操作的一种软件包形式
特点:
- 安装比较麻烦,需要配置编译等过程才能安装
- 升级、卸载不方便
- 需要手工解决依赖关系
- 用户可以修改软件代码
1. 源码包的安装步骤
-
./configure
创建Makefile文件,该文件记录了原始码如何编译的详细信息。编译前的准备工作。
-
make clean
读取makefile关于clean的工作。这个步骤不一定会有,但是建议执行一下,因为我们不确定源码里有没有包含上次编译过的目标文件。
-
make
make会根据makefile中的预设工作进行编译行为。编译就是进行gcc将源码便以为可执行文件
-
make install
将编译好的的数据安装到预定的目录中,完成安装。
2. 案例
安装ntp时间服务器
[root@CaiChen ~]# tar -zxvf ntp-4.2.8p13.tar.gz
[root@CaiChen ~]# cd ntp-4.2.8p13/
[root@CaiChen ntp-4.2.8p13]# ./configure --prefix=/usr/local/ntp //--prefix指出安装目录
[root@CaiChen ntp-4.2.8p13]# make
[root@CaiChen ntp-4.2.8p13]# meke install
注意:
# 在执行./configure --prefix=/usr/local/ntp,碰到以下情况,使用后面的指令安装gcc和cc
[root@localhost ntp-4.2.8p13]# ./configure --prefix=/usr/local/ntp
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for style of include used by make... GNU
checking for cc... no
checking for gcc... no
configure: error: in `/root/ntp-4.2.8p13':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
# 安装gcc 和 cc
[root@localhost ntp-4.2.8p13]# yum -y install gcc cc
_____ _ _____ _
/ ____| (_) / ____| | |
| | __ _ _ | | | |__ ___ _ __
| | / _` | | | | | | '_ \ / _ \ | '_ \
| |____ | (_| | | | | |____ | | | | | __/ | | | |
\_____| \__,_| |_| \_____| |_| |_| \___| |_| |_|
好了各位,以上就是这篇文章的全部内容了,能看到这里人啊,都是人才。
如果这个文章写得还不错,觉得「王采臣」我有点东西的话 求点赞👍求关注❤️求分享👥 对耿男我来说真的非常有用!!!
白嫖不好,创作不易,各位的支持和认可,就是我创作的最大动力,我们下篇文章见!
王采臣 | 文 【原创】 如果本篇博客有任何错误,请批评指教,不胜感激 !微信公众号:
