Linux 软件管理(Centos 7)

1、概述

1.1、RPM 包

简介

  • RPM(原Red Hat Package Manager,现在是一个递归缩写)
  • 由 Red Hat 公司提出,被众多 Linux 发行版所采用
  • 也称二进制( binary code)无需编译,可以直接使用
  • 无法设定个人设置,开关功能
  • 软件包示例(注意后缀)
  • mysql-community-common-5.7.12-1.el7.x86_64.rpm

RPM 包

zip-3.0-11.el7.x86_64.rpm
# zip — 软件包名 
# 3.0-11 — 版本号(Version)  
# el7 — 发布版本(Release5/6/7)  
# x86_64 — 系统平台(32/64) 
# rpm — 文件后缀

1.2、源码包

简介

  • source code 需要经过GCC,C++编译环境编译才能运行
  • 可以设定个人设置,开关功能
  • 软件包示例(注意后缀)
  • nginx-1.8.1.tar.gz

源码包

nginx-1.8.1.tar.gz 
# nginx —  包名
# 1.8.1 — 版本号
# tar.gz — 压缩格式

2、RPM 包管理

2.1、YUM 工具

简介

  • Yum(全称为 Yellow dog Updater,Modified)
  • 是一个在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前端软件包管理器
  • 基于RPM包管理,能够从指定的服务器自动下载 RPM 包并且安装
  • 可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装

2.1.1、本地源 — 系统安装光盘

简介

  • 通过系统光盘获得软件包,并安装软件

具体步骤

  • 第一步:观察 YUM 核心配置目录下的任何一个配置文件
  • ll /etc/yum.repos.d/*
  • 第二步:备份并移除官方 YUM 仓库
[root@localhost yum.repos.d]# mv   /etc/yum.repos.d/*     /tmp
[root@localhost yum.repos.d]# ll /tmp/* | grep repo
-rw-r--r--. 1 root      root        2523 1226 19:31 /tmp/CentOS-Base.repo
  • 第三步:编写本地 YUM 库配置文件
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# touch 1.repo
[root@localhost yum.repos.d]# vim 1.repo 

# 1.repo 文本内容
[1]
name=1
baseurl=file:///mnt/cdrom
gpgcheck=0    

# 注释
# /etc/yum.repos.d/ 是 YUM 下载地址库目录
# [1]某一个库的名称,中括号 [] 是必须的
# name=1 是库的说明,name 是必须的  
# baseurl=file:///mnt/cdrom 下载库的具体地址
# gpgcheck=0 是关闭校验                                                                                                
  • 第四步:挂载安装光盘
# 1. 创建挂载点
[root@localhost ~]# mkdir /mnt/cdrom

# 2. 查看挂载文件
[root@localhost ~]# ls /dev | grep cdrom
cdrom

# 3. 挂载
[root@localhost ~]# mount /dev/cdrom  /mnt/cdrom/
mount: /dev/sr0 写保护,将以只读方式挂载
mount: /dev/sr0 已经挂载或 /mnt/cdrom 忙
       /dev/sr0 已经挂载到 /mnt/cdrom 上

# 4. 查看挂载点目录
[root@localhost ~]# ls /mnt/cdrom/
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL

# 设置开机自启动挂载
[root@localhost ~]# vim /root/.bashrc
# 写入内容:mount /dev/cdrom /mnt/cdrom

使用 YUM 安装文件并验证

  • 第一步:安装 httpd
[root@localhost yum.repos.d]# yum -y install httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
1                                                                   | 3.6 kB  00:00:00     
(1/2): 1/group_gz                                                   | 153 kB  00:00:00     
(2/2): 1/primary_db                                                 | 3.3 MB  00:00:00     
匹配 httpd-2.4.6-95.el7.centos.x86_64 的软件包已经安装。正在检查更新。
无须任何处理
[root@localhost yum.repos.d]# 
  • 第二步:打开软件并设置防火墙
# 2. 启动软件, 关闭防火墙, 关闭防火墙自启
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
  • 第三步:打开浏览器,输入(127.0.0.1)

在这里插入图片描述
观察仓库信息

  • 可以发现是自己配置的 YUM 仓库信息
[root@localhost /]# yum repolist 
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                       源名称                                   状态
1                                            1                                        4,070
repolist: 4,070

2.1.2、网络源 — 官方源

目的

  • 使用国内厂商提供的软件包地址
  • (如:http://alibaba.com/.sadflsdjfjsdalkfdsa)作为YUM的仓库
2.1.2.1、阿里云

具体步骤

  • 第一步:下载 wget
[root@localhost yum.repos.d]# yum  install   wget
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 wget-1.14-18.el7_6.1.x86_64 已安装并且是最新版本
无须任何处理
  • 第二步:清理原先的 YUM 仓库
[root@localhost yum.repos.d]# mv 1.repo /tmp
  • 第三步:下载阿里源至 YUM 库
[root@localhost yum.repos.d]# wget  http://mirrors.aliyun.com/repo/Centos-7.repo  -O /etc/yum.repos.d/CentOS-Base.repo 
--2021-04-16 17:04:02--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 119.36.224.241, 119.36.224.239, 119.36.224.248, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|119.36.224.241|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至:/etc/yum.repos.d/CentOS-Base.repo”

100%[=================================================================================================================================>] 2,523       --.-K/s 用时 0s      

2021-04-16 17:04:02 (268 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
  • 第四步:更新 YUM 源
# 1. 查看 YUM 源
[root@localhost yum.repos.d]# yum  repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                         源名称                                                状态
base/7/x86_64                  CentOS-7 - Base - mirrors.aliyun.com                  10,072
extras/7/x86_64                CentOS-7 - Extras - mirrors.aliyun.com                   468
updates/7/x86_64               CentOS-7 - Updates - mirrors.aliyun.com                1,924
repolist: 12,464

# 2. 重建缓存
[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                | 3.6 kB  00:00:00     
extras                                                              | 2.9 kB  00:00:00     
updates                                                             | 2.9 kB  00:00:00     
(1/6): extras/7/x86_64/other_db                                     | 138 kB  00:00:00     
(2/6): extras/7/x86_64/filelists_db                                 | 230 kB  00:00:00     
(3/6): updates/7/x86_64/other_db                                    | 555 kB  00:00:02     
(4/6): base/7/x86_64/other_db                                       | 2.6 MB  00:00:06     
(5/6): base/7/x86_64/filelists_db                                   | 7.2 MB  00:00:09     
(6/6): updates/7/x86_64/filelists_db                                | 4.2 MB  00:00:10     
元数据缓存已建立
2.1.2.2、EPEL

简介:额外软件包

具体步骤

  • 第一步:下载配置文件
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2021-04-16 17:08:58--  http://mirrors.aliyun.com/repo/epel-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 119.36.224.242, 119.36.225.226, 119.36.224.208, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|119.36.224.242|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:664 [application/octet-stream]
正在保存至:/etc/yum.repos.d/epel.repo”

100%[=================================================>] 664         --.-K/s 用时 0s      

2021-04-16 17:08:58 (145 MB/s) - 已保存 “/etc/yum.repos.d/epel.repo” [664/664])
  • 第二步:重建缓存
[root@localhost yum.repos.d]# yum  makecache
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                | 3.6 kB  00:00:00     
epel                                                                | 4.7 kB  00:00:00     
extras                                                              | 2.9 kB  00:00:00     
updates                                                             | 2.9 kB  00:00:00     
(1/6): epel/x86_64/group_gz                                         |  96 kB  00:00:00     
(2/6): epel/x86_64/updateinfo                                       | 1.0 MB  00:00:00     
(3/6): epel/x86_64/prestodelta                                      |  869 B  00:00:00     
(4/6): epel/x86_64/primary_db                                       | 6.9 MB  00:00:09     
(5/6): epel/x86_64/other_db                                         | 3.3 MB  00:00:09     
(6/6): epel/x86_64/filelists_db                                     |  12 MB  00:00:20     
元数据缓存已建立

2.2、使用 YUM 管理 RPM 包

2.2.1、安装

  • 全新安装:yum -y install httpd
  • 重新安装:yum -y reinstall httpd
  • 升级安装:yum -y update httpd

2.2.2、查询

  • 查询 YUM 源:yum repolist
  • 查询 HTTP 程序:yum list httpd(带 @ 的表示已经安装)
[root@localhost ~]# yum list httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
httpd.x86_64                          2.4.6-97.el7.centos                          @updates

2.2.3、移除

  • 移除 HTTP 程序:yum -y remove httpd
[root@localhost ~]# yum -y remove  httpd
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-97.el7.centos 将被 删除
--> 解决依赖关系完成

依赖关系解决

===========================================================================================
 Package         架构             版本                            源                  大小
===========================================================================================
正在删除:
 httpd           x86_64           2.4.6-97.el7.centos             @updates           9.4 M

事务概要
===========================================================================================
移除  1 软件包

安装大小:9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在删除    : httpd-2.4.6-97.el7.centos.x86_64                                       1/1 
  验证中      : httpd-2.4.6-97.el7.centos.x86_64                                       1/1 

删除:
  httpd.x86_64 0:2.4.6-97.el7.centos                                                       

完毕!
[root@localhost ~]# yum list httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
可安装的软件包
httpd.x86_64                          2.4.6-97.el7.centos                           update

2.3、RPM 包

前言

  • 管理红帽系统/centos 系统,rpm 包的基本工具,与 YUM 功能相同
  • 优点:不需要配置,可以直接使用
  • 缺点:无法解决依赖关系,无法自行下载软件包

2.3.1、安装

具体步骤

  • 第一步:找到安装包
[root@localhost ~]# cd   /mnt/cdrom/Packages
[root@localhost Packages]# ls wget-1.14-18.el7_6.1.x86_64.rpm 
wget-1.14-18.el7_6.1.x86_64.rpm
  • 第二步:安装(i — 安装,v — 可视化,h — 百分比)
[root@localhost Packages]# rpm -ivh wget-1.14-18.el7_6.1.x86_64.rpm 
准备中...                          ################################# [100%]
	软件包 wget-1.14-18.el7_6.1.x86_64 已经安装

2.3.2、查询

  • 参数:q(查询)
  • 可以软件包的名字表示软件安装成功
[root@localhost Packages]# rpm -q wget
wget-1.14-18.el7_6.1.x86_64

2.3.3、卸载

  • 参数:e(卸载)
  • 注意后面跟的是软件,而不是 rpm 包
[root@localhost Packages]# rpm -evh wget-1.14-18.el7_6.1.x86_64
准备中...                          ################################# [100%]
正在清理/删除...
   1:wget-1.14-18.el7_6.1             ################################# [100%]
  • 卸载后再次查询
[root@localhost Packages]# rpm -q  wget
未安装软件包 wget 

3、源码包管理

3.1、获取源码包

  • Apache: www.apache.org
  • Nginx: www.nginx.org
  • Tengine: tengine.taobao.org

3.2、部署 Tengine

具体步骤

  • 第一步:下载源码包
  • wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
  • 第二步:准备编译环境
  • yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
  • 第三步:解压
  • tar xvf tengine-2.2.0.tar.gz
  • 第四步:配置
[root@localhost ~]# ls
anaconda-ks.cfg       tengine-2.2.0         公共  视频  文档  音乐
initial-setup-ks.cfg  tengine-2.2.0.tar.gz  模板  图片  下载  桌面
[root@localhost ~]# cd tengine-2.2.0/
[root@localhost tengine-2.2.0]# useradd xiaohan
[root@localhost tengine-2.2.0]# ./configure  --user=xiaohan  --group=xiaohan --prefix=/usr/local/nginx 
checking for OS
 + Linux 3.10.0-1160.24.1.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
checking for gcc -pipe switch ... found
......
  • 第五步:编译
  • make
  • 第六步:安装
  • make install
  • 第七步:启动验证
# 1. 若之前启动过 httpd 服务
[root@localhost tengine-2.2.0]# systemctl stop  httpd

# 2. 启动服务
[root@localhost tengine-2.2.0]# /usr/local/nginx/sbin/nginx

# 3. 关闭防火墙
[root@localhost tengine-2.2.0]# systemctl stop firewalld

# 4. 打开浏览器, 输入 127.0.0.1
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是我来晚了!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值