开源软件最初只提供了.tar.gz的打包的源码文件,用户必须自已编译每一个想在GNU/Linux上运行的软件。为了更加便利的方法来管理这些软件,出现了包管理系统。html
软件包管理器功能:node
将编译好的应用程序的各组成文件打包一个或几个程序包文件,利用包管理器能够方便快捷地实现程序 包的安装、卸载、查询、升级和校验等管理操做mysql
主流的程序包管理器linux
源代码打包文件命名:c++
name-VERSION.tar.gz|bz2|xzgit
VERSION: major.minor.releasegithub
rpm包命名方式:sql
常见的arch:数据库
x86: i386, i486, i586, i686ubuntu
x86_64: x64, x86_64, amd64
跟平台无关:noarch
1)包文件组成 (每一个包独有)
2)数据库(公共):/var/lib/rpm
1)系统发版的光盘或官方网站
CentOS镜像:
https://www.centos.org/download/
Ubuntu 镜像:
http://cdimage.ubuntu.com/releases/
2)第三方组织提供
https://fedoraproject.org/wiki/EPEL
https://mirrors.aliyun.com/epel/?spm=a2c6h.13651104.0.0.3bc47dfaZpesAr
3)软件项目官方站点
http://yum.mariadb.org/10.4/centos8-amd64/rpms/
http://repo.mysql.com/yum/mysql-8.0-community/el/8/x86_64/
4)搜索引擎
5)本身制做
将源码文件,利用工具,如:rpmbuild,fpm等工具制做成rpm包文件
格式:
rpm {-i|--install} [install-options] PACKAGE_FILE ...
选项:
安装选项【install-options】
注意:因为rpm命令安装包大部分会产生包依赖问题,因此通常不使用rpm安装包
格式:
升级 rpm {-U|--upgrade} [install-options] PACKAGE_FILE... rpm {-F|--freshen} [install-options] PACKAGE_FILE... #upgrade:安装有旧版程序包,则“升级”,若是不存在旧版程序包,则“安装” #freshen:安装有旧版程序包,则“升级”, 若是不存在旧版程序包,则不执行升级操做 降级 rpm {--oldpackage} [install-options] PACKAGE_FILE...
注意:1.不要对内核作升级操做;Linux支持多内核版本并存,所以直接安装新版本内核
2.若是原程序包的配置文件安装后曾被修改,升级时,新版本提供的同一个配置文件不会直接覆盖老 版本 的配置文件,而把新版本文件重命名(FILENAME.rpmnew)后保留
格式:
rpm {-q|--query} [select-options] [query-options]
【select-options】
【query-options】
和CAPABILITY相关
范例:
[root@centos8 data]# rpm -qf /etc/skel/.bashrc bash-4.4.19-10.el8.x86_64 [root@centos8 data]# rpm -ql tree /usr/bin/tree /usr/lib/.build-id /usr/lib/.build-id/d8 /usr/lib/.build-id/d8/6d516d7cb07fb9334cb268af808119e33a5ac5 /usr/share/doc/tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz [root@centos8 data]# rpm -qd tree /usr/share/doc/tree/LICENSE /usr/share/doc/tree/README /usr/share/man/man1/tree.1.gz [root@centos8 data]# rpm -q --scripts bash postinstall scriptlet (using <lua>): nl = '\n' sh = '/bin/sh'..nl ... [root@centos8 data]# rpm -q --whatrequires tree no package requires tree
格式:
rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
注意:当包卸载时,对应的配置文件不会删除, 以FILENAME.rpmsave形式保留
范例:强行删除rpm包,并恢复
[root@centos7 ~]#rpm -e rpm --nodeps #重启进入rescue模式 #mkdir /mnt/cdrom #mount /dev/sr0 /mnt/cdrom #rpm -ivh /mnt/cdrom/Packages/rpm-4.11.3-40.el7.x86_64.rpm --root=/mnt/sysimage #reboot
在安装包时,系统也会检查包的来源是不是合法的
本身校验步骤:
1.导入所须要公钥 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #查询密钥是否导入成功 rpm -qa “gpg-pubkey*” 2.检查包的完整性和签名 rpm -K|--checksig rpmfile
范例:
[root@centos8 ~]#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial [root@centos8 rpm-gpg]#rpm -K /misc/cd/AppStream/Packages/httpd-2.4.37- 16.module_el8.1.0+256+ae790463.x86_64.rpm /misc/cd/AppStream/Packages/httpd-2.4.37- 16.module_el8.1.0+256+ae790463.x86_64.rpm: digests signatures OK [root@centos8 ~]#rpm -qa "gpg-pubkey*" gpg-pubkey-8483c65d-5ccc5b19
软件在安装时,会将包里的每一个文件的元数据,如:大小,权限,全部者,时间等记录至rpm相关的数 据库中,能够用来检查包中的文件是否和当初安装时有所变化
格式:
rpm {-V|--verify} [select-options] [verify-options]
范例:
[root@centos8 data]# vim /etc/issue [root@centos8 data]# cat /etc/issue 111 \S Kernel \r on an \m [root@centos8 data]# rpm -V centos-release S.5....T. c /etc/issue [root@centos8 data]# vim /etc/issue [root@centos8 data]# rpm -V centos-release .......T. c /etc/issue
先在yum服务器上建立 yum repository(仓库),在仓库中事先存储了众多rpm包,以及包的相关的 元数据文件(放置于特定目录repodata下),当yum客户端利用yum/dnf工具进行安装时包时,会自动 下载repodata中的元数据,查询远数据是否存在相关的包及依赖关系,自动从仓库中找到相关包下载并 安装。
yum服务器的仓库能够多种形式存在:
yum客户端配置文件:
- /etc/yum.conf #为全部仓库提供公共配置 - /etc/yum.repos.d/*.repo: #为每一个仓库的提供配置文件 - 帮助参考: man 5 yum.conf
yum的repo配置文件中可用的变量:
- $releasever: 当前OS的发行版的主版本号,如:8,7,6 - $arch: CPU架构,如:aarch64, i586, i686,x86_64等 - $basearch:系统基础平台;i386, x86_64 - $contentdir:表示目录,好比:centos-8,centos-7 - $YUM0-$YUM9:自定义变量
范例:配置文件
[root@centos8 ~]# cat /etc//yum.conf [main] gpgcheck=1 #安装包前合法性校验 installonly_limit=3 #容许同时安装包的个数 clean_requirements_on_remove=True #卸载时是否删除不使用的包 best=True #升级时自动选择最新版本,即便缺乏包的依赖 skip_if_unavailable=False # [root@centos8 yum.repos.d]# cat /etc/yum.repos.d/CentOS-Base.repo [BaseOS] #仓库名称 name=CentOS-$releasever - Base #仓库描述 #仓库路径 baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/BaseOS/$basearch/os/ gpgcheck=1 #安装包前合法性校验 enabled=1 #是否启用仓库 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial #校验文件位置
范例:为centos8配置其余两个经常使用源(epel和Extras源)
[root@centos8 yum.repos.d]# vim CentOS-epel.repo [epel] name=Extra Packages for Enterprise Linux 8 - $basearch baseurl=http://mirrors.cloud.aliyuncs.com/epel/8/Everything/$basearch failovermethod=priority enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 [extras] name=CentOS-$releasever - Extras baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/extras/$basearch/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
yum-config-manager命令
用于管理yum仓库的配置文件
格式:
[root@centos8 ~]# yum provides yum-config-manager Last metadata expiration check: 1:31:04 ago on Thu 21 Jan 2021 10:29:03 AM CST. yum-utils-4.0.17-5.el8.noarch : Yum-utils CLI compatibility layer Repo : BaseOS Matched from: Filename : /usr/bin/yum-config-manager #增长仓库 yum-config-manager --add-repo URL或file #禁用仓库 yum-config-manager --disable “仓库名" #启用仓库 yum-config-manager --enable “仓库名”
格式:
yum [options] <command> [<args>...]
常见选项:
格式:
yum repolist [all|enabled|disabled] #显示仓库列表,all会列出没启用的仓库 yum list [all | glob_exp1] [glob_exp2] [...] #显示程序列表,all会列出没安装的包
范例:
[root@centos8 ~]# yum repolist repo id repo name AppStream CentOS-8 - AppStream BaseOS CentOS-8 - Base data created by dnf config-manager from file:///data epel Extra Packages for Enterprise Linux 8 - x86_64 extras CentOS-8 - Extras [root@centos8 ~]# yum repolist all repo id repo name status AppStream CentOS-8 - AppStream enabled AppStream-source CentOS-8 - AppStream Sources disabled [root@centos8 ~]# yum list all tree Last metadata expiration check: 2:21:49 ago on Thu 21 Jan 2021 10:29:03 AM CST. Installed Packages tree.x86_64 1.7.0-15.el8 @anaconda [root@centos8 ~]# yum list all httpd Last metadata expiration check: 2:22:00 ago on Thu 21 Jan 2021 10:29:03 AM CST. Available Packages httpd.x86_64 2.4.37-30.module_el8.3.0+561+97fdbbcc AppStrea
格式:
yum install package1 [package2] [...] yum reinstall package1 [package2] [...] #从新安装
范例:
[root@centos8 data]# yum install [url] Install a package directly from a URL [root@centos8 data]# yum -y install tree ... Installed: tree-1.7.0-15.el8.x86_64 Complete!
格式:
yum remove | erase package1 [package2] [...]
格式:
yum update [package1] [package2] [...] yum downgrade package1 [package2] [...] (降级) yum check-update(检查可用升级)
范例:
[root@centos7 ~]#yum install samba --disablerepo=updates [root@centos7 ~]#yum update samba #更新全部能够更新的软件 [root@centos7 ~]# yum update
3.3.5 查询
格式:
#查看程序包information: yum info [...] #查看指定的特性(能够是某文件)是由哪一个程序包所提供: yum provides | whatprovides feature1 [feature2] [...] #查看指定包所依赖的capabilities: yum deplist package1 [package2] [...]
范例:
#注意要写文件全路径才能查询到 [root@centos8 data]# yum provides vsftpd.conf Last metadata expiration check: 2:51:12 ago on Thu 21 Jan 2021 01:31:05 PM CST. Error: No Matches found [root@centos8 data]# yum provides vsftp.conf Last metadata expiration check: 2:50:03 ago on Thu 21 Jan 2021 01:31:05 PM CST. Error: No Matches found [root@centos8 data]# yum provides /etc/vsftpd/vsftpd.conf Last metadata expiration check: 2:50:58 ago on Thu 21 Jan 2021 01:31:05 PM CST. vsftpd-3.0.3-32.el8.x86_64 : Very Secure Ftp Daemon Repo : AppStream Matched from: Filename : /etc/vsftpd/vsftpd.conf [root@centos8 data]# yum info tree Last metadata expiration check: 2:52:35 ago on Thu 21 Jan 2021 01:31:05 PM CST. Installed Packages Name : tree Version : 1.7.0 Release : 15.el8 Architecture : x86_64 Size : 109 k Source : tree-1.7.0-15.el8.src.rpm Repository : @System From repo : BaseOS Summary : File system tree viewer URL : http://mama.indstate.edu/users/ice/tree/ License : GPLv2+ Description : The tree utility recursively displays the contents of directories in a : tree-like format. Tree is basically a UNIX port of the DOS tree : utility. [root@centos8 data]# yum deplist httpd Last metadata expiration check: 2:54:15 ago on Thu 21 Jan 2021 01:31:05 PM CST. package: httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 dependency: /bin/sh provider: bash-4.4.19-12.el8.x86_64 dependency: /etc/mime.types provider: mailcap-2.1.48-3.el8.noarch dependency: httpd-filesystem ...
格式:
#清除目录/var/cache/yum/缓存 yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] #构建缓存 yum makecache
范例:
[root@centos8 data]# du -sh /var/cache/dnf/ 41M /var/cache/dnf/ [root@centos8 data]# yum clean all 29 files removed [root@centos8 data]# du -sh /var/cache/dnf/ 1.3M /var/cache/dnf/ [root@centos8 data]# du -sh /var/cache/dnf/ 1.3M /var/cache/dnf/ [root@centos8 data]# yum makecache ... Metadata cache created. [root@centos8 data]# du -sh /var/cache/dnf/ 41M /var/cache/dnf/
yum 执行安装卸载命令会记录到相关日志中
#CentOS 7之前版本日志 /var/log/yum.log #CentOS 8 版本日志 /var/log/dnf.rpm.log /var/log/dnf.log
命令
yum history [info|list|packages-list|packages-info|summary|addoninfo|redo|undo|rollback|new|sync|stats]
范例:
[root@centos8 data]# yum history ID | Command line | Date and time | Action(s) | Altered ----------------------------------------------------------------------------------------------- 22 | -y install tree | 2021-01-21 16:07 | Install | 1 21 | remove tree | 2021-01-21 16:07 | Removed | 1 20 | -y install yum-utils.noarch | 2021-01-21 12:03 | I, U | 13 [root@centos8 ~]#dnf history undo 22 -y Removed: dnf-utils-4.0.2.2-3.el8.noarch Complete! [root@centos8 ~]#dnf history redo 22 -y
范例:
#该例在内网环境采用光盘挂在方式建立yum源 [root@centos7 os]#mount /data/CentOS-7-x86_64-DVD-2009\(1\).iso /home/centos/7/os/ mount: /dev/loop0 写保护,将以只读方式挂载 [root@centos7 os]#ll 总用量 696 -rw-r--r-- 3 root root 14 10月 30 05:14 CentOS_BuildTag drwxr-xr-x 3 root root 2048 10月 27 00:25 EFI -rw-rw-r-- 21 root root 227 8月 30 2017 EULA -rw-rw-r-- 21 root root 18009 12月 10 2015 GPL drwxr-xr-x 3 root root 2048 10月 27 00:26 images drwxr-xr-x 2 root root 2048 11月 3 00:17 isolinux drwxr-xr-x 2 root root 2048 10月 27 00:25 LiveOS drwxr-xr-x 2 root root 673792 11月 4 19:30 Packages drwxr-xr-x 2 root root 4096 11月 4 19:35 repodata -rw-rw-r-- 21 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7 -rw-rw-r-- 21 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7 -r--r--r-- 1 root root 2883 11月 4 19:36 TRANS.TBL #配置仓库服务器 [root@centos7 os]#mv CentOS7-Base-163.repo CentOS7-Base-163.repo.bak [root@centos7 os]cat Base.repo [root@centos7 os]#cat /etc/yum.repos.d/Base.repo [BaseOS] name=Centos7 BaseOS baseurl=file:///home/centos/7/os/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [root@centos7 os]#yum repolist 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 源标识 源名称 状态 BaseOS Centos7 BaseOS 4,070 repolist: 4,070 #安装httpd服务 [root@centos7 os]#yum -y install httpd [root@centos7 os]#service httpd start Redirecting to /bin/systemctl start httpd.service [root@centos7 ~]#cp -a /home/centos/7/os/* /var/www/html/centos/7/ #这里仓库服务端搭建完毕,修改本机仓库baseurl [root@centos7 ~]#cat /etc/yum.repos.d/Base.repo [BaseOS] name=Centos7 BaseOS baseurl=http://172.16.60.243/centos/7/ [root@centos7 os]#yum repolist 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 源标识 源名称 状态 BaseOS Centos7 BaseOS 4,070 repolist: 4,070 #客户端配置yum文件测试 [root@localhost yum.repos.d]# yum -y install vim ... 做为依赖被安装: gpm-libs.x86_64 0:1.20.7-6.el7 vim-common.x86_64 2:7.4.629-7.el7 vim-filesystem.x86_64 2:7.4.629-7.el7 完毕
范例:下载extras源,制做私有yum源
#安装下载工具 [root@centos8 ~]# yum -y install yum-utils #配置epel源 [root@centos8 ~]# cat /etc/yum.repos.d/CentOS-Base.repo ... [epelOS] name=CentOS-$releasever - epel #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/ gpgcheck=0 enabled=1 #使用工具下载rpm包和metadata [root@centos8 ~]# yum reposync --repoid=epelOS --download-metadata -p /data #下载完成将包和metadata拷贝至http中www文件夹下,在按照以前方式配置epel仓库便可
./configure
(1) 经过选项传递参数,指定安装路径、启用特性等;执行时会参考用户的指定以及Makefile.in文 件生成Makefile
(2) 检查依赖到的外部环境,如依赖的软件包
make 根据Makefile文件,会检测依赖的环境,进行构建应用程序
make install 复制文件到相应路径
解决安装环境和依赖
第一步:运行 configure 脚本,生成Makefile 文件
获取其支持使用的选项
第二步:make
第三步:make install
二进制程序目录导入至PATH环境变量中
编辑文件/etc/profile.d/NAME.sh
导入帮助手册
编辑/etc/man.config|man_db.conf文件,添加一个MANPATH
范例:编译安装 cmatrix
#准备:系统若是没有相关依赖需先进行安装 #gcc make autoconf ncurses-devel #1.下载cmatrix https://github.com/abishekvashok/cmatrix/releases #2.解压 [root@centos8 data]# tar -xf cmatrix-v2.0-Butterscotch.tar -C /usr/local/ #3.配置安装路径 [root@centos8 /]# cd /usr/local/src/cmatrix/ [root@centos8 cmatrix]#./configure --prefix=/apps/cmatrix #4.编译并安装 [root@centos8 cmatrix]#make && make install #5.配置环境 [root@centos8 ~]#echo 'PATH=/apps/cmatrix/bin:$PATH' > /etc/profile.d/cmatrix.sh [root@centos8 ~]#. /etc/profile.d/cmatrix.sh #或者用软连接实现 [root@centos8 ~]#ln -sv /apps/cmatrix/bin/cmatrix /usr/local/bin/ #6.实现man帮助 [root@centos8 ~]#vim /etc/man_db.conf MANDATORY_MANPATH /apps/cmatrix/share/man [root@centos8 ~]#man cmatrix