0
点赞
收藏
分享

微信扫一扫

rpm,yum命令

刘员外__ 2022-09-27 阅读 265

RPM是RPM(Redhat) Package Manager(RPM软件包管理器)的缩写,虽然有red hat的标志,但是其原始设计理念是开放式的,现在OpenLinux ,Suse ,Turbo Linux等Linux版本都有采用,可以算是行业公认标准了。

一、rpm软件包的管理

1、rpm包的获取方式

1·Centos系统镜像光盘

2·​​网站rpmfind.net​​

3·安装mysql、nginx软件,可以去他们的官方网站下载

4·Centos yum源中

2、rpm包格式说明

rpm,yum命令_mysql


rpm,yum命令_mysql_02

注:结尾有noarch代表此包在32位,64位上都可以运行,这种类型的包通常是文本文件。

结尾有i686代表只可以在32位系统上运行

结尾有X86_64代表在64位系统上运行,64位系统可以兼容32位系统的包

查看内核版本

[root@localhost Packages]# uname -r
3.10.0-693.el7.x86_64

3、安装rpm软件

rpm工具使用分为安装、查询、验证、更新、删除等操作

命令格式:rpm [参数]  软件包

参数:

-i 是istall的意思,安装软件包

-v 显示附加信息,显示更多详细信息

-V 效验,对已安装的软件进行效验

-h --hash ,安装时输出#########标记

rpm使用时,什么时候使用软件包全名,什么时候使用软件包名?

全名:在安装和更新升级的时候使用

包名:对已经安装过的软件包进行使用,如查找已经安装的包,卸载包。rpm包安装后通常会保存在本地/var/lib/rpm目录下

4、rpm查询功能

命令格式:rpm -q(query) 跟上参数

-a(all)查询所有已安装的软件包

-i 显示已安装的软件包信息

-l (list)查询软件包中文件安装的位置

-p 查询未安装软件包的信息,后面要加软件的命名

-f 查询系统文件属于哪个软件包,反向查询

-R 查询软件包的依赖关系

-V 查询安装的软件是否被修改过

[root@localhost ~]# rpm -q lrzsz       #查询已安装的软件包,已安装会显示
lrzsz-0.12.20-36.el7.x86_64
[root@localhost ~]# rpm -qa | grep lrz #查询所有已安装包中含有lrz的包
lrzsz-0.12.20-36.el7.x86_64
[root@localhost ~]# rpm -qf /usr/bin/find #查询find命令是哪个软件包安装的
findutils-4.5.11-5.el7.x86_64
[root@localhost ~]# rpm -qi lrzsz #显示lrzsz的详细信息
Name : lrzsz
Version : 0.12.20
Release : 36.el7
Architecture: x86_64
Install Date: Wed 31 Aug 2022 10:24:20 AM EDT
Group : Applications/Communications
Size : 184846
License : GPLv2+
Signature : RSA/SHA256, Thu 03 Jul 2014 11:35:32 PM EDT, Key ID 24c6a8a7f4a80eb5
Source RPM : lrzsz-0.12.20-36.el7.src.rpm
Build Date : Mon 09 Jun 2014 07:29:11 PM EDT
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.ohse.de/uwe/software/lrzsz.html
Summary : The lrz and lsz modem communications programs
Description :
Lrzsz (consisting of lrz and lsz) is a cosmetically modified
zmodem/ymodem/xmodem package built from the public-domain version of
the rzsz package. Lrzsz was created to provide a working GNU
copylefted Zmodem solution for Linux systems.
[root@localhost ~]# rpm -ql lrzsz #查询lrzsz包中文件所在的位置
/usr/bin/rb
/usr/bin/rx
/usr/bin/rz
/usr/bin/sb
/usr/bin/sx
/usr/bin/sz
/usr/share/locale/de/LC_MESSAGES/lrzsz.mo
/usr/share/man/man1/rz.1.gz
/usr/share/man/man1/sz.1.gz
[root@localhost ~]# ls /mnt/Packages/php-mysql-5.4.16-42.el7.x86_64.rpm /mnt/Packages/php-mysql-5.4.16-42.el7.x86_64.rpm
[root@localhost ~]# rpm -pql /mnt/Packages/php-mysql-5.4.16-42.el7.x86_64.rpm
/etc/php.d/mysql.ini #查询php-mysql包安装后会生成的文件,此命令需要完全
/etc/php.d/mysqli.ini 的包名,可以先用ls命令查看
/etc/php.d/pdo_mysql.ini
/usr/lib64/php/modules/mysql.so
/usr/lib64/php/modules/mysqli.so
/usr/lib64/php/modules/pdo_mysql.so
[root@localhost ~]# rpm -Vf `which find` #查询find命令是否被人修改过。` `反引号代表把反引
[root@localhost ~]# 中命令的执行结果给上一个命令执行。
#命令执行后没有回显表示命令没有被修改,反之
被修改过。

5、rpm的卸载

命令格式:rpm -e(erase) 包名

[root@localhost ~]# rpm -q lrzsz     #查询已安装的包 
lrzsz-0.12.20-36.el7.x86_64
[root@localhost ~]# rpm -e lrzsz #卸载
[root@localhost ~]# rpm -q lrzsz #再次查询显示未安装
package lrzsz is not installed
[root@localhost ~]#

二、YUM的使用

yum(全称位Yellow dog Updater Modified)是一个前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并安装,可以自动处理依赖关系,并且一次安装所有依赖的包,无须繁琐的一次次的下载,安装。

YUM:解决依赖关系问题,自动下载软件包,基于C/S架构

C:client(客户端)     S:ftp/http/file(服务端)

1、配置本地yum源

rpm,yum命令_centos_03

[root@localhost ~]# mount /dev/sr0 /mnt   #将光盘镜像挂载到/mnt目录下
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# ls /mnt #查看光盘内容
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 ~]# cd /etc/yum.repos.d #进入yum源固定目录
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo
CentOS-Debuginfo.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir back #创建一个back目录存放其他yum源
[root@localhost yum.repos.d]# mv ./*.repo ./back #将其他yum源移到back目录
[root@localhost yum.repos.d]# ls
back
[root@localhost yum.repos.d]# vim back.repo #创建一个本地yum源的配置文件

rpm,yum命令_mysql_04

[root@localhost yum.repos.d]# yum clean all        #清除缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: back
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache #重新建立元数据
Loaded plugins: fastestmirror, langpacks
back | 3.6 kB 00:00
(1/4): back/group_gz | 156 kB 00:00
(2/4): back/filelists_db | 3.1 MB 00:00
(3/4): back/primary_db | 3.1 MB 00:00
(4/4): back/other_db | 1.2 MB 00:00
Determining fastest mirrors
Metadata Cache Created
[root@localhost yum.repos.d]# yum install httpd -y #验证本地yum源
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-67.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos for package: httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================
Package Arch Version Repository
Size
========================================================================
Installing:
httpd x86_64 2.4.6-67.el7.centos back 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 back 103 k
apr-util x86_64 1.5.2-6.el7 back 92 k
httpd-tools x86_64 2.4.6-67.el7.centos back 87 k
mailcap noarch 2.1.41-2.el7 back 31 k

Transaction Summary
========================================================================
Install 1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Downloading packages:
------------------------------------------------------------------------
Total 14 MB/s | 3.0 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-67.el7.centos.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-67.el7.centos.x86_64 5/5
Verifying : httpd-2.4.6-67.el7.centos.x86_64 1/5
Verifying : mailcap-2.1.41-2.el7.noarch 2/5
Verifying : apr-1.4.8-3.el7.x86_64 3/5
Verifying : httpd-tools-2.4.6-67.el7.centos.x86_64 4/5
Verifying : apr-util-1.5.2-6.el7.x86_64 5/5

Installed:
httpd.x86_64 0:2.4.6-67.el7.centos

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7
apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-67.el7.centos
mailcap.noarch 0:2.1.41-2.el7

Complete!
[root@localhost yum.repos.d]#

注:如果本地yum源配置文件gpgcheck=1,需要导入rpm公钥,方便校验包。校验一下可以提高安全性。

[back]
name=back
baseurl=file:///mnt
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
rpm --import #导入公钥

2、网络yum源

例1:使用阿里云centos7yum源

[root@localhost back]# wget -O /etc/yum.repos.d/CentOS-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2022-09-26 07:20:26-- http://mirrors.aliyun.com/repo/Centos-7.repo #wget -O(wget下载工具 ,-O指定保存位置)
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 58.216.14.243, 180.101.198.243, 180.101.198.242, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|58.216.14.243|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-7.repo’

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

2022-09-26 07:20:26 (597 MB/s) - ‘/etc/yum.repos.d/CentOS-7.repo’ saved [2523/2523]
[root@localhost back]# cd ../
[root@localhost yum.repos.d]# ls
back back.repo CentOS-7.repo net-7.repo

例2:安装Centos epel扩展yum源

[root@localhost yum.repos.d]# yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
epel-release noarch 7-11 extras 15 k

Transaction Summary
==============================================================================
Install 1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm | 15 kB 00:05
Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
From : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1

Installed:
epel-release.noarch 0:7-11

Complete!
[root@localhost yum.repos.d]# ls
back back.repo CentOS-7.repo epel.repo epel-testing.repo

3、YUM的使用

[root@localhost ~]# yum install httpd -y   #安装软件包  -y直接安装
[root@localhost ~]# yum update #升级软件包,改变软件设置和系统设置,系统版本内核都升级。
[root@localhost ~]# yum upgrade #升级软件包,不改变软件设置和系统设置,系统版本升级,
内核不改变。
[root@localhost ~]# yum info httpd #查看包的基本信息
[root@localhost ~]# yum -y remove #卸载软件包 -y直接卸载
[root@localhost ~]# yum search httpd #查找包括httpd字符的软件包

yum源报错:

1·确定光盘是否连接,光盘是否挂载

2·配置文件中格式是否正确,字母,符号有没有少写,挂载点和配置文件中设置的是否一致

3·网络源需要联网

三、tar源码包安装

源码安装nginx

1、编译环境:gcc 和 gcc-c++编译器,make

2、准备软件:nginx-1.18.0.tar.gz

安装nginx源码编译需要的依赖包

[root@localhost ~]# yum -y install gcc gcc-c++ make zlib-devel pcre pcre-devel openssl-devel
#gcc gcc++(编译器) make命令 pcre包作用是让nginx支持正则表达式,地址重写rewrite

3、开始安装:

源码编译三部曲:./configure   ,  make  ,  make install

[root@localhost ~]# ls
anaconda-ks.cfg Downloads nginx-1.18.0.tar.gz Templates
Desktop initial-setup-ks.cfg Pictures Videos
Documents Music Public
[root@localhost ~]# tar -zxvf nginx-1.18.0.tar.gz
[root@localhost ~]# cd nginx-1.18.0/
[root@localhost nginx-1.18.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.18.0]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.18.0]# make
[root@localhost nginx-1.18.0]# make install
#./configure
1.--prefix=// 指定安装路径
2.--with-pcre 和其他软件关联
3.检测安装环境
4.--enable 启用或禁用某项功能
最后生成Makefile
#make 把源代码文件编译成可执行的二进制文件
#make install 把二进制文件安装进硬盘

4、删除源码包:

安装完删除源码包,因为之前安装时指定了安装路径,所以删除时直接对指定的/usr/local/nginx进行操作就可以了。

举报

相关推荐

0 条评论