用python开发的工具,安装的也是rpm包html
优势是能够自动安装一个包所依赖的一些包。rpm包在安装时候可能会须要依赖另外一个包的支持,而安装另外一个包,可能还须要另外一个的依赖。这时候用yum就能够自动安装上全部的依赖包。方便,简单,快捷。python
要想使用rpm工具,首先须要有rpm包,下面利用contos7的镜像文件里找一下rpm包。linux
先链接虚拟机里面的光驱,光盘文件选一下contos7的镜像。链接好后开始挂载。git
挂载到/mnt/下,mount /dev/cdrom /mnt/github
[root@aminglinux-01 ~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 写保护,将以只读方式挂载 [root@aminglinux-01 ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda3 18G 3.6G 15G 20% / devtmpfs 479M 0 479M 0% /dev tmpfs 489M 0 489M 0% /dev/shm tmpfs 489M 6.7M 482M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/sda1 197M 109M 88M 56% /boot tmpfs 98M 0 98M 0% /run/user/0 /dev/sr0 4.1G 4.1G 0 100% /mnt
到mnt下看一下里面的内容。也就是光盘里的文件。rpm包是以红色名字显示的。docker
[root@aminglinux-01 ~]# cd /mnt/ [root@aminglinux-01 mnt]# ls CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
其中 Packages这个目录下装的就是rpm包文件。apache
xz-devel-5.2.2-1.el7.x86_64.rpm 包名-版本号-发布版本号.64位或32位数系统要求
以这个rpm包为例子,xz-devel就是包名,5.2.2这个是版本号。1.el7是发布版本号。x86_64,运行平台,区分32位,或者64位。也有不须要区分的,均可以用。vim
contos7已经开始不区分32或者64位的,都是64位系统。通常64位系统能够安装32位的软件。反过来不能够。windows
用法:centos
安装:rpm -ivh rpm包文件
升级:rpm -Uvh rpm包文件
卸载 :rpm -e 包名
查询安装的包: rpm -qa
查询指定包是否安装 : rpm -q
查询指定包信息 : rpm -qi
列出包安装的文件 : rpm -ql
查看一个文件是由哪一个包安装的 rpm -qf 文件绝对路径
rpm安装rpm -ivh rpm包文件 (这个是在当前有rpm包的目录,也可用绝对路径)
[root@aminglinux-01 Packages]# rpm -ivh zsh-5.0.2-25.el7.x86_64.rpm 准备中... ################################# [100%] 正在升级/安装... 1:zsh-5.0.2-25.el7 ################################# [100%] [root@aminglinux-01 Packages]#
[root@aminglinux-01 Packages]# rpm -e zsh [root@aminglinux-01 Packages]#
python-perf-3.10.0-514.el7.x86_64 perl-XML-Dumper-0.81-17.el7.noarch logrotate-3.8.6-12.el7.x86_64 net-snmp-agent-libs-5.7.2-28.el7.x86_64 nss-3.21.0-17.el7.x86_64 ----中间省略,特别多---- dhclient-4.2.5-47.el7.centos.x86_64 crontabs-1.11-6.20121102git.el7.noarch libdrm-2.4.67-3.el7.x86_64
[root@aminglinux-01 Packages]# rpm -q ppp ppp-2.4.5-33.el7.x86_64 [root@aminglinux-01 Packages]# rpm -q pppp 未安装软件包 pppp
[root@aminglinux-01 Packages]# rpm -qi vim-enhanced Name : vim-enhanced Epoch : 2 Version : 7.4.160 Release : 1.el7_3.1 Architecture: x86_64 Install Date: 2017年08月23日 星期三 20时09分35秒 Group : Applications/Editors Size : 2292098 License : Vim Signature : RSA/SHA256, 2016年12月22日 星期四 01时14分11秒, Key ID 24c6a8a7f4a80eb5 Source RPM : vim-7.4.160-1.el7_3.1.src.rpm Build Date : 2016年12月22日 星期四 01时00分52秒 Build Host : c1bm.rdu2.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://www.vim.org/ Summary : A version of the VIM editor which includes recent enhancements Description : VIM (VIsual editor iMproved) is an updated and improved version of the vi editor. Vi was the first real screen-based editor for UNIX, and is still very popular. VIM improves on vi by adding new features: multiple windows, multi-level undo, block highlighting and more. The vim-enhanced package contains a version of VIM with extra, recently introduced features like Python and Perl interpreters. Install the vim-enhanced package if you'd like to use a version of the VIM editor which includes recently added enhancements like interpreters for the Python and Perl scripting languages. You'll also need to install the vim-common package. [root@aminglinux-01 Packages]#
以下,上面讲到用rpm安装和卸载会出现依赖问题很是麻烦。若是用yum安装和卸载就会自动安装或卸载所须要的依赖。
[root@aminglinux-01 Packages]# rpm -ivh texlive-tools-svn26263.0-38.el7.noarch.rpm 错误:依赖检测失败: texlive-base 被 texlive-tools-2:svn26263.0-38.el7.noarch 须要 texlive-kpathsea-bin 被 texlive-tools-2:svn26263.0-38.el7.noarch 须要 tex-kpathsea 被 texlive-tools-2:svn26263.0-38.el7.noarch 须要 tex(color.sty) 被 texlive-tools-2:svn26263.0-38.el7.noarch 须要
yum install 包名 ,在用texlive这个包试一下。
事务概要 ========================================================================================================================================================== 安装 1 软件包 (+223 依赖软件包) 总下载量:118 M 安装大小:226 M Is this ok [y/d/N]:
能够看到自动检测到须要223个依赖包。按y就会下载安装,按n就是不安装。若是这么多依赖用rpm一个一个安装的话会累死,这也是yum的优势。
yum-plugin-tmprepo.noarch 1.1.31-45.el7 base yum-plugin-tsflags.noarch 1.1.31-45.el7 base yum-plugin-upgrade-helper.noarch 1.1.31-45.el7 base yum-plugin-verify.noarch 1.1.31-45.el7 base yum-plugin-versionlock.noarch 1.1.31-45.el7 base yum-rhn-plugin.noarch 2.0.1-10.el7 base yum-updateonboot.noarch 1.1.31-45.el7 base yum-utils.noarch 1.1.31-45.el7 base zenity.x86_64 3.22.0-1.el7 base
列出的很是多, 左侧是包名字和运行平台, 中间是版本号,和平台号。 最右侧是仓库名字。@开头的是已经安装过的包。
/etc/yum.repos.d/这里面是yum仓库的配置文件。
[root@localhost ~]# ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
用搜索vim举例。 yum search vim
[root@localhost ~]# yum search vim 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn ==================================================================== N/S matched: vim ==================================================================== protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions vim-X11.x86_64 : The VIM version of the vi editor for the X Window System vim-common.x86_64 : The common files needed by any version of the VIM editor vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements vim-filesystem.x86_64 : VIM filesystem layout vim-minimal.x86_64 : A minimal version of the VIM editor 名称和简介匹配 only,使用“search all”试试。 [root@localhost ~]#
用vim搜索举例 。 yum list |grep 'vim' 。不光能精确过滤,还有颜色显示。
[root@localhost ~]# yum grouplist 已加载插件:fastestmirror 没有安装组信息文件 Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn 可用的环境分组: 最小安装 基础设施服务器 计算节点 文件及打印服务器 基本网页服务器 虚拟化主机 带 GUI 的服务器 GNOME 桌面 KDE Plasma Workspaces 开发及生成工做站 可用组: 传统 UNIX 兼容性 兼容性程序库 图形管理工具 安全性工具 开发工具 控制台互联网工具 智能卡支持 科学记数法支持 系统管理 系统管理工具 完成
中文显示可能没法使用。须要用 LANG=en 转换英文看一下
[root@localhost ~]# LANG=en [root@localhost ~]# yum grouplist Failed to set locale, defaulting to C Loaded plugins: fastestmirror There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn 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 Available Groups: Compatibility Libraries Console Internet Tools Development Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System Management Done
卸载软件包也是会把全部的依赖卸载。因此卸载时候尽可能不要加-y, 以避免出现意外。
若是yum update 不加包名会自动升级系统中能升级的全部包。包括系统自己。
[root@localhost ~]# yum provides "/*/vim" Failed to set locale, defaulting to C Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.zju.edu.cn base/7/x86_64/filelists_db | 6.9 MB 00:00:06 extras/7/x86_64/filelists_db | 519 kB 00:00:00 updates/7/x86_64/filelists_db | 1.3 MB 00:00:00 cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system Repo : base Matched from: Filename : /usr/share/cmake/editors/vim 2:docker-unit-test-1.13.1-53.git774336d.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests Repo : extras Matched from: Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/contrib/syntax/vim Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim 2:docker-unit-test-1.13.1-58.git87f2fab.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests Repo : extras Matched from: Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/contrib/syntax/vim Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim 2:docker-unit-test-1.13.1-63.git94f4240.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests Repo : extras Matched from: Filename : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/contrib/syntax/vim Filename : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim Filename : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim git-1.8.3.1-13.el7.x86_64 : Fast Version Control System Repo : base Matched from: Filename : /usr/share/doc/git-1.8.3.1/contrib/vim 2:vim-common-7.4.160-4.el7.x86_64 : The common files needed by any version of the VIM editor Repo : base Matched from: Filename : /usr/share/vim 2:vim-enhanced-7.4.160-4.el7.x86_64 : A version of the VIM editor which includes recent enhancements Repo : base Matched from: Filename : /usr/bin/vim 2:vim-enhanced-7.4.160-2.el7.x86_64 : A version of the VIM editor which includes recent enhancements Repo : @base Matched from: Filename : /usr/bin/vim
能够根据命令路径来判断包名字。好比在/bin下或者/sbin下。
有些特殊状况下,服务器没有联网,可是想要yum安装一些软件。这时候就须要搭建一个本地的yum仓库来使用。
思路是先准备一个有yum包的储存盘,好比光盘。而后把以前的yum仓库文件备份下删除,而后添加新的仓库配置文件。
[root@localhost ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak [root@localhost ~]# rm -f /etc/yum.repos.d/*
[dvd] name=install dvd baseurl=file:///mnt 定义rpm包放在那里 enable=1 是否可用,1就是可用 gpgcheck=0 是否检测,0不检测。
[root@localhost ~]# yum clean all Failed to set locale, defaulting to C Loaded plugins: fastestmirror Cleaning repos: dvd Cleaning up everything Cleaning up list of fastest mirrors
xsettings-kde.x86_64 0.12.3-7.el7 dvd xsom.noarch 0-10.20110809svn.el7 dvd xterm.x86_64 295-3.el7 dvd xulrunner.x86_64 31.6.0-2.el7.centos dvd xvattr.x86_64 1.3-27.el7 dvd xz-devel.x86_64 5.2.2-1.el7 dvd yajl.x86_64 2.0.4-4.el7 dvd yelp.x86_64 1:3.14.2-1.el7 dvd yelp-libs.x86_64 1:3.14.2-1.el7 dvd yelp-xsl.noarch 3.14.0-1.el7 dvd
contos7默认yum源指向的是国外的网站,有的时候yum装程序特别的慢。这时候就须要把yum源改为国内的,下载速度就会提高。
首先删除rm -f CentOS-Base.repo 这个源
下载163源 CentOS7-Base-163.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 或者 curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all 清缓存
yum list 测试或者安装个wge试一下,就是能够用了。
光安装一个163源不够用,不少rpm都没有。因此安装一个扩展源。
安装好后会在 /etc/yum.repos.d下新生成一个epel.repo
epel.repo
zvbi.x86_64 0.2.35-1.el7 epel zvbi-devel.x86_64 0.2.35-1.el7 epel zvbi-fonts.noarch 0.2.35-1.el7 epel zziplib.i686 0.13.62-5.el7 base zziplib.x86_64 0.13.62-5.el7 base zziplib-devel.i686 0.13.62-5.el7 base
以前说过搭建本地yum仓库可是是用光驱里面的rpm包作的实验,而不是真正所须要的本地仓库。下面说一下如何用yum下载所须要的rpm包。
这种用法限于该包尚未安装。已经安装过的会提醒。
下载到/var/cache/yum/x86_64/7/仓库名/packages下面。
[root@localhost ~]# yum install zsh --downloadonly --downloaddir=/tmp/ Failed to set locale, defaulting to C Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * epel: mirrors.tongji.edu.cn Resolving Dependencies --> Running transaction check ---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================== Package Arch Version Repository Size ========================================================================================================================================================== Installing: zsh x86_64 5.0.2-28.el7 base 2.4 M Transaction Summary ========================================================================================================================================================== Install 1 Package Total download size: 2.4 M Installed size: 5.6 M Background downloading packages, then exiting: zsh-5.0.2-28.el7.x86_64.rpm | 2.4 MB 00:00:02 exiting because "Download Only" specified [root@localhost ~]# ls /tmp/ 1.txt systemd-private-a44b0f41787b47de9f672a72cec9768d-vmtoolsd.service-FOn2fg yum_save_tx.2018-05-30.11-10.T6z0Ih.yumtx passwd.sh yum_save_tx.2018-05-30.09-10.cW8ODj.yumtx zsh-5.0.2-28.el7.x86_64.rpm [root@localhost ~]#
[root@localhost src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz --2018-05-30 11:20:40-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 9076901 (8.7M) [application/octet-stream] Saving to: 'httpd-2.4.33.tar.gz' 100%[================================================================================================================>] 9,076,901 1.59MB/s in 5.9s 2018-05-30 11:20:46 (1.46 MB/s) - 'httpd-2.4.33.tar.gz' saved [9076901/9076901] [root@localhost src]# ls httpd-2.4.33.tar.gz
解压好后,进入目录,找到配置文件README 。这里面是一些软件的说明介绍。
还有一个文件是INSTALL 里面是安装文档。教程。开头介绍了安装步骤。
[root@localhost httpd-2.4.33]# cat INSTALL APACHE INSTALLATION OVERVIEW Quick Start - Unix ------------------ For complete installation documentation, see [ht]docs/manual/install.html or http://httpd.apache.org/docs/2.4/install.html $ ./configure --prefix=PREFIX $ make $ make install $ PREFIX/bin/apachectl start
./configure --help是能够查看安装都有哪些功能可选安装的。
./configure --prefix=/usr/local/apache2 指定安装目录
[root@localhost httpd-2.4.33]# ./configure --prefix=/usr/local/apache2 checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation.
直接报错了。 输入 echo $?查看若是是0就是上面命令执行没有问题,若是是1或则别的数说明上面命令报错了。
根据报错安装yum install apr apr-util apr-devel
而后安装yum install gcc
而后 make
而后 make install
卸载源码包的安装就是删除安装文件。