rpm能够实现程序的快速,简单安装(跟编译安装比),可是rpm本身不能解决依赖,因此不少工具为了自动解决依赖应运而生,其中yum就是其中之一。php
必须有个文件服务器,里面放置因此的rpm包,以及包的相关元数据(-qi,-qR获得的数据)。元数据可使用createrepo
来建立。并放置在repodata目录下。c++
这个文件服务器可使用ftp,http,nfs协议来传输数据,也可使用file:///(本地服务)。sql
客户端使用yum程序,安装程序包。安装时,查询文件服务器,本身从文件服务器找依赖,并安装。shell
yum是一个程序,查看本机是否安装了yum:centos
# rpm -q yum yum-3.4.3-161.el7.centos.noarch
查看yum程序所使用的配置文件:缓存
/etc/yum.conf是主配置文件,它里面引用了目录/etc/yum.repos.d/,因此/etc/yum.repos.d/目录下的*.repo也是yum的配置文件.它提供了因此仓库的公共配置。bash
实现了把配置文件分割成了许多独立的小的配置文件。服务器
/etc/yum.repos.d/目录下的*.repo:为仓库的指向提供配置信息。微信
# rpm -qc yum /etc/logrotate.d/yum#log用 /etc/yum.conf /etc/yum/version-groups.conf#版本控制
/etc/yum.conf内容:babel
[main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
[main]:主配置,至关于程序的指向入口
cachedir:缓存路径
keepcache:是否保持缓存
debuglevel:调试级别
logfile:日志文件
exactarch:是否作精确匹配。若是OS是centos7,当找到的rpm包,既有centos6的也有centos7的,若是此处的值是1,则选择centos7的。
gpgcheck:安装时,是否检查完整性和来源合法性。1则检查
plugins:yum是否支持插件。1则支持
使用whatis查看是否有man帮助。
# whatis yum.conf yum.conf (5) - Configuration file for yum(8).
使用:man 5 yum.conf
能够获得详细的yum.conf配置文件的详细帮助。
[repositoryid]:仓库的id
name=仓库的名字
baseurl=url://path/to/repository/:仓库在哪里,地址能够有多个,那么选哪一个呢?根据failovermethod选。
baseurl=url://server1/path/to/repository/
url://server2/path/to/repository/
url://server3/path/to/repository/
centos7下/etc/yum.repos.d/下的repo配置文件有几个,只有CentOS-Base.repo文件里repo的enabled是1,也就是可使用状态,其他的配置文件里的repo的enabled都是0.
# ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Base.repo_20191129 CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
查看配置文件:/etc/yum.repos.d/CentOS-Base.repo的内容。
[base] name=CentOS-$releasever - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
指定baseurl的技巧:指到repodata所在的网页的URL。
上面的updates的baseurl的值就是下图的网页地址栏的URL。理由是repodata在这里。
查看repo list:
# yum repolist Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile repo id repo name status !base/7/x86_64 CentOS-7 - Base 10,097 !extras/7/x86_64 CentOS-7 - Extras 323 !updates/7/x86_64 CentOS-7 - Updates 1,446 repolist: 11,866
repo id:
repo name:是配置文件/etc/yum.repos.d/CentOS-Base.repo里的name的值
status:这个repo里的rmp包的数量。
yum [options][command] [package ...]
显示repo(仓库)列表(list):repolist [all|enabled|disabled]
# yum repolist all # yum repolist enabled # yum repolist disabled
显示指定repo里有哪些rpm包:yum list [all | glob_exp1] [glob_exp2] [...]
显示全部的包:
# yum list
可使用glob_exp。
显示内容的第三列:repo配置文件中的repoid
# yum list php* Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Available Packages php.x86_64 5.4.16-46.1.el7_7 updates php-bcmath.x86_64 5.4.16-46.1.el7_7 updates php-pear.noarch 1:1.9.4-21.el7 base php-pecl-memcache.x86_64 3.0.8-4.el7 base
显示repo中还未安装的包:yum list available [glob_exp1][...]
# yum list available
显示repo中的能够升级的包:yum list updates [glob_exp1][...]
# yum list updates
显示已经安装的包:yum list installed [glob_exp1][...]
# yum list installed zlib.x86_64 1.2.7-18.el7 @anaconda zsh.x86_64 5.0.2-33.el7 installed
显示已经安装了的extra repo中的包:yum list extras [glob_exp1][...]
# yum list extras
显示已经安装的包,哪些已经废弃了:yum list distro-extras [glob_exp1][...]
# yum list distro-extras
安装包:yum install package1 [package2
若是repo里有多个版本,能够指定版本,例如:yum install gcc-4.8.5
也能够不指定版本,则安装最新版:yum install gcc
升级包:yum update [package1][package2] [...]
# yum update gcc Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile No packages marked for update
降级:downgrade package1 [package2][...]
相似:rpm -Uvh --oldpackage
从新覆盖安装:reinstall package1 [package2][...]
相似:rpm -ivh --replacepkgs
检查有哪些包能够升级:yum check-update
卸载包:yum remove | erase package1 [package2][...]
当卸载的包,被别的包依赖时,别的包也一并被卸载
卸载cpp:因为gcc依赖于cpp,全部若是卸载cpp,则gcc也会被卸载。
查看包的信息:yum info [glob_exp1][...]
相似rpm -qi
# yum info gcc Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Installed Packages Name : gcc Arch : x86_64 Version : 4.8.5 Release : 39.el7 Size : 37 M Repo : installed From repo : base Summary : Various compilers (C, C++, Objective-C, Java, ...) URL : http://gcc.gnu.org License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD Description : The gcc package contains the GNU Compiler Collection version 4.8. : You'll need this package in order to compile C code
查看程序或文件是有哪一个包提供的:yum provides | whatprovides feature1 [feature2
相似rpm -qf file
# yum provides /usr/bin/gcc Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile gcc-4.8.5-39.el7.x86_64 : Various compilers (C, C++, Objective-C, Java, ...) Repo : base Matched from: Filename : /usr/bin/gcc gcc-4.8.5-39.el7.x86_64 : Various compilers (C, C++, Objective-C, Java, ...) Repo : @base Matched from: Filename : /usr/bin/gcc
清除元数据文件在本地的缓存:clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
yum按文件时,会把程序包和元数据文件缓存在本地,当安装结束,yum会删除程序包文件,可是不会删除 元数据文件。
构建缓存:yum makecache [fast]
用关键字搜索信息:yum search string1 [string2][...]
从包名和包的summary里搜索指定的关键字。
# yum search bash Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile ====================================================== N/S matched: bash ======================================================= bash-completion.noarch : Programmable completion for Bash bash-doc.x86_64 : Documentation files for bash libguestfs-bash-completion.noarch : Bash tab-completion scripts for libguestfs tools libvirt-bash-completion.x86_64 : Bash completion script pcp-pmda-bash.x86_64 : Performance Co-Pilot (PCP) metrics for the Bash shell bash.x86_64 : The GNU Bourne Again shell Name and summary matches only, use "search all" for everything.
显示某个包所依赖的包:deplist package1 [package2][...]
# yum deplist gcc Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile package: gcc.x86_64 4.8.5-39.el7 dependency: /bin/sh provider: bash.x86_64 4.2.46-33.el7 dependency: /sbin/install-info provider: info.x86_64 5.1-5.el7 ...
查看yum的安装,更新,卸载的历史:yum history
不带参数则是history list
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
# yum history Loaded plugins: fastestmirror, langpacks ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 5 | root <root> | 2020-02-15 23:00 | Install | 2 4 | root <root> | 2020-02-15 22:59 | Erase | 8 3 | root <root> | 2020-02-15 22:48 | Update | 11 < 2 | ys <ys> | 2019-11-29 17:38 | Install | 8 > 1 | System <unset> | 2019-11-29 16:44 | Install | 1458 history list
上面是汇总的信息,若是想看id为5的详细信息,也就是id为5的安装了哪些包,则使用:
# yum history info 5 Loaded plugins: fastestmirror, langpacks Transaction ID : 5 Begin time : Sat Feb 15 23:00:14 2020 Begin rpmdb : 1459:fe9d7def2a5edd098cfe39ebe0732b67038170b5 End time : 23:00:19 2020 (5 seconds) End rpmdb : 1461:ed3657ce694e0e90ea8bf62a092f06422c81ac28 User : root <root> Return-Code : Success Command Line : install gcc Transaction performed with: Installed rpm-4.11.3-35.el7.x86_64 @anaconda Installed yum-3.4.3-161.el7.centos.noarch @anaconda Installed yum-plugin-fastestmirror-1.1.31-50.el7.noarch @anaconda Packages Altered: Dep-Install cpp-4.8.5-39.el7.x86_64 @base Install gcc-4.8.5-39.el7.x86_64 @base history info
查看yumdb大小:
# yum history stats Loaded plugins: fastestmirror, langpacks File : //var/lib/yum/history/history-2020-02-16.sqlite Size : 23,552 Transactions: 0 history stats
本地安装/升级:想安装的包在yum repo中没有,能够下载一个rpm包安装。但为何不用rpm呢,由于rpm不能解决依赖,而yum能够,因此即便是本地的rpm包,也可使用yum安装,可是参数是rpm文件名。
localinstall/localupdate是为了兼容之前的版本,应该使用intall/update 参数是rpm文件名。
localinstall rpmfile1 [rpmfile2][...]
(maintained for legacy reasons only - use install)
localupdate rpmfile1 [rpmfile2][...]
(maintained for legacy reasons only - use update)
组安装/更新/卸载/查看
查看有哪些组可供安装:
# yum groups list Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation Installed Groups: Development Tools Available Groups: Compatibility Libraries Console Internet Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System Management Done
查看某个组里有哪些包:
# yum groups info Development\ Tools Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Group: Development Tools Group-Id: development Description: A basic development environment. Mandatory Packages: gcc =gcc-c++ gettext =libtool make Default Packages: byacc =gcc-gfortran swig =systemtap Optional Packages: ElectricFence ant babel bzr
Mandatory Packages:必须安装的包
Default Packages:默认安装的包
Optional Packages:可选安装的包
安装:
# yum groups install "Development Tools"
更新:
# yum groups update "Development Tools" Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Maybe run: yum groups mark install (see man yum) No packages in any requested group available to install or updates
删除:
# yum groups remove Development\ Tools
1,先挂载centos系统安装盘到/media目录。
2,建立文件local.repo
[base] name=local repo centos baseurl=file:///media/ enabled=1 gpgcheck=0
3,而后就能够正常使用yum命令了。
$releasever:当前OS的发行版的主版本号。centos7的话,此变量的值就是7
$arch:架构。好比i386,i486等
$basearch:基础架构。若是是ix86架构的话,则此变量的值为i386
$YUM0-$YUM9:自定义变量
使用变量的例子:
name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
createrepo [options] <directory>
使用createrepo很简单,只须要指定rpm包所在的目录。
就会作成目录:repodata
# pwd /tmp/repos # createrepo ./ Spawning worker 0 with 19 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete # ls -d repodata/ repodata/
repodata目录的文件构成:
# ll repodata/ total 52 -rw-r--r--. 1 root root 12690 Feb 16 11:24 7150dafd709770a783ea087b2ff869aaecfb007b0fcce6f544924c4c1e1e4405-primary.sqlite.bz2 -rw-r--r--. 1 root root 4184 Feb 16 11:24 7f43292a24f471448badbf18db488dbe52efc22237170ad2f6fc7aa36ac45a0e-primary.xml.gz -rw-r--r--. 1 root root 2686 Feb 16 11:24 8351058925b5438dbe9abd2c246c64f3eafcc741f644ef268ac8747a82bc48ab-filelists.xml.gz -rw-r--r--. 1 root root 2655 Feb 16 11:24 a5b6ce405bfa9814e77ab3159b77aa4a2c55ac445a5244ff449b1125badc2a9b-other.xml.gz -rw-r--r--. 1 root root 5918 Feb 16 11:24 c58fa90f9a3825f07092ff63f524a86183a0e9f99e19d3a84b785cef2edf93f8-other.sqlite.bz2 -rw-r--r--. 1 root root 5423 Feb 16 11:24 fa9fbb57fe96cf749733a6232b4860f70c7abd60b7b0c72f9486771f63f9a4ec-filelists.sqlite.bz2 -rw-r--r--. 1 root root 2976 Feb 16 11:24 repomd.xml
建立repo配置文件:
[local2] name=your repo centos baseurl=file:///tmp/repos enabled=1 gpgcheck=0
验证:repoid:local2已经可使用了
# yum repolist local2 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile repo id repo name status local2 your repo centos 19 repolist: 19
1,configure脚本使用和做用
做用:指定安装到哪,启用哪些特性
使用:每一个源代码的configure的用法可能都不同,全部使用前,用:configure --help
查看都支持哪些选项。
选项分类:
安装路径设定:
--prefix=/path/to/somewhere:指定安装路径(方便之后卸载,直接把目录删除)。不指定可能安装到了/usr/local
--sysconfdir=/path/to/somewhere:指定配置文件放到哪里
交叉编译设定:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST:编译后运行的目标架构。cross-compile to build programs to run on HOST [BUILD]
--target=TARGET configure for building compilers for TARGET [HOST]
安装特性设定:
--disable-FEATURE
--enable-FEATURE[=ARG]
设定安装时依赖哪些包,不依赖哪些包
--with-PACKAGE[=ARG]:ARG为路径信息等。
--without-PACKAGE
1,把可执行程序目录添加到PATH环境变量
新建文件:/etc/profile.d/NAME.sh
添加 export PATH=/PATH/TO/BIN:$PATH
2,添加库文件路径
新建文件:/etc/ld.so.conf.d/name.conf
添加:/PATH/TO/lib
3,让系统找到头文件
建立头文件的符号连接:`ln -s /PATH/TO/include /usr/include/
4,导出帮助手册
编辑/etc/man_db.conf,添加:
#MANDATORY_MANPATH /usr/src/pvm3/man # MANDATORY_MANPATH /usr/man MANDATORY_MANPATH /usr/share/man MANDATORY_MANPATH /usr/local/share/man MANDATORY_MANPATH /PATH/TO/man