CentOS/RHEL内软件安装1

CentOS/RHEL内软件安装1

 

10月9日任务

7.1 安装软件包的三种方法

7.2 rpm包介绍

7.3 rpm工具用法

7.4 yum工具用法

7.5 yum搭建本地仓库(视频中ppt小错误: gpcheck改为gpgcheck,yum cean 改为 yum  clean)

 

常见安装软件包的三种方法

  • rpm工具(红帽包管理工具)

    • 安装位置、文件名等在安装前就已确定

    • 安装较为简单

  • yum工具

    • 由python开发

    • 自动安装相关依赖软件包

    • 最简单

  • 源码包

    • 软件的源码文件集合

    • 需要使用编译器(gcc)编译安装

    • 最困难,安装过程困难会有很多问题(可能缺少库函数)

rpm工具

系统镜像文件中默认有很多软件包,在安装过程中,有些软件包并没有安装。用户通过光盘驱动加载系统镜像文件,

并挂载到系统内的挂载点上(只读形式),然后就可以使用rpm工具来在安装系统后安装之前所未安装软件包。

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cd /mnt/Packages/
[root@localhost Packages]# ls
...
yum-plugin-versionlock-1.1.31-40.el7.noarch.rpm
yum-utils-1.1.31-40.el7.noarch.rpm
zenity-3.8.0-5.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-17.el7.x86_64.rpm
zlib-devel-1.2.7-17.el7.x86_64.rpm
zsh-5.0.2-25.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm

一个rpm包由以下几个信息组合(-连接)命名

例:zlib-1.2.7-17.el7.x86_64.rpm

  • 软件名 -- zlib

  • 版本信息 -- 1.2.7

    • 主版本.次版本[.修正版本]

  • 发布版本号 -- 17.el7(7.x版本)

  • 系统平台 -- x86_64

  • 文件后缀 -- rpm

Centos7.x版本不区分32位和64位,默认都是64位;7.x版本前区分,64位平台可以安装32位软件!

rpm工具用法

安装:rpm -ivh 包文件
# 不需要其他依赖的包直接安装
[root@localhost Packages]# rpm -ivh zsh-5.0.2-25.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-25.el7 ################################# [100%]

# 安装时可能需要安装其他依赖包
[root@localhost Packages]# rpm -e ppp
错误:依赖检测失败:
ppp = 2.4.5 被 (已安裝) NetworkManager-1:1.4.0-12.el7.x86_64 需要
[root@localhost Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm
错误:依赖检测失败:
texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要

升级:rpm -Uvh 包文件

[root@localhost Packages]# rpm -Uvh zsh-5.0.2-25.el7.x86_64.rpm
...

卸载:rpm -e 包名(zip)

# 卸载成功不提示
[root@localhost Packages]# rpm -e zsh

# 有相关依赖提示卸载不成功
[root@localhost Packages]# rpm -e ppp
错误:依赖检测失败:
ppp = 2.4.5 被 (已安裝) NetworkManager-1:1.4.0-12.el7.x86_64 需要
查询
  • rpm -qa (查询所有已安装的包)

[root@localhost Packages]# rpm -qa
trousers-0.3.13-1.el7.x86_64
filesystem-3.2-21.el7.x86_64
net-tools-2.0-0.17.20131004git.el7.x86_64
bind-license-9.9.4-37.el7.noarch
fxload-2002_04_11-16.el7.x86_64
nss-softokn-freebl-3.16.2.3-14.4.el7.x86_64
libthai-0.1.14-9.el7.x86_64
ncurses-libs-5.9-13.20130511.el7.x86_64
libX11-common-1.6.3-3.el7.noarch
libselinux-2.5-6.el7.x86_64
libXfixes-5.0.1-2.1.el7.x86_64
sed-4.2.2-5.el7.x86_64
libXinerama-1.1.3-2.1.el7.x86_64
...
  • rpm -q 包名 (查询指定的包是否安装)
# 已安装
[root@localhost Packages]# rpm -q tree
tree-1.6.0-10.el7.x86_64

# 未安装
[root@localhost Packages]# rpm -q trees
未安装软件包 trees
  • rpm -qi 包名(查询指定包的详细信息info)
[root@localhost Packages]# rpm -qi tree
Name : tree
Version : 1.6.0
Release : 10.el7
Architecture: x86_64
Install Date: ... 21时13分13秒
Group : Applications/File
Size : 89505
License : GPLv2+
Signature : RSA/SHA256, 2014年07月04日 星期五 13时36分46秒, Key ID 24c6a8a7f4a80eb5
Source RPM : tree-1.6.0-10.el7.src.rpm
Build Date : 2014年06月10日 星期二 03时28分53秒
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://mama.indstate.edu/users/ice/tree/
Summary : File system tree viewer
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.
  • rpm -ql 包名(显示包所安装的文件)
[root@localhost Packages]# rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.6.0
/usr/share/doc/tree-1.6.0/LICENSE
/usr/share/doc/tree-1.6.0/README
/usr/share/man/man1/tree.1.gz
  • rpm -qf 文件绝对路径 (查询文件是由什么包所安装的)
# 按照已知文件查看由什么包安装
[root@localhost Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-2.el7.x86_64

# “ ` ”(反引号)-- 将命令执行的结果作为输入
[root@localhost Packages]# rpm -qf `which cd`
bash-4.2.46-20.el7_2.x86_64

rpm安装、卸载时都会检测软件依赖性,不符合不会进行安装、卸载!相对而言比较难用!

yum工具使用

yum配置文件 /etc/yum.repos.d/目录下

# 基本的仓库文件CentOS-Base.repo;
# 外部仓库文件epel.repo;
[root@centos7 Packages]# ls -l /etc/yum.repos.d/
总用量 36
-rw-r--r--. 1 root root 1664 8月 30 23:53 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 8月 30 23:53 CentOS-CR.repo
-rw-r--r--. 1 root root 649 8月 30 23:53 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 8月 30 23:53 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 8月 30 23:53 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月 30 23:53 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 8月 30 23:53 CentOS-Vault.repo
-rw-r--r--. 1 root root 957 12月 28 2016 epel.repo
-rw-r--r--. 1 root root 1056 12月 28 2016 epel-testing.repo
  • 列出可安装的软件包:yum list
[root@localhost Packages]# yum list
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.comInstalled Packages
GeoIP.x86_64 1.5.0-11.el7 @an
aconda
NetworkManager.x86_64 1:1.4.0-12.el7 @an
aconda
NetworkManager-libnm.x86_64 1:1.4.0-12.el7 @an
aconda
NetworkManager-team.x86_64 1:1.4.0-12.el7 @an
aconda
...
  • 搜索相关软件包:yum search 软件包名 或 yum list | grep 软件包名
# 搜索相关包
[root@centos7 Packages]# yum search "vim"
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirror01.idc.hinet.net
* extras: centosn4.centos.org
* updates: mirrors.cn99.com
=============================== N/S matched: vim ===============================
beakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in
: VIM editor
fluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vim
neovim.x86_64 : Vim-fork focused on extensibility and agility
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers
: descriptions
python2-neovim.noarch : Python client to Neovim
python34-neovim.noarch : Python client to Neovim
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-clustershell.noarch : VIM files for ClusterShell
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
...

--------- --------------- --------------
# yum search搜索说明内有匹配也会被找出# yum list | grep 较 yum search 更精确
[root@centos7 Packages]# yum list | grep "vim"
vim-common.x86_64 2:7.4.160-2.el7 @base
vim-enhanced.x86_64 2:7.4.160-2.el7 @base
vim-filesystem.x86_64 2:7.4.160-2.el7 @base
vim-minimal.x86_64 2:7.4.160-2.el7 @base
beakerlib-vim-syntax.noarch 1.16-3.el7 epel
fluxbox-vim-syntax.noarch 1.3.7-1.el7 epel
neovim.x86_64 0.2.0-2.el7 epel
protobuf-vim.x86_64 2.5.0-8.el7 base
python2-neovim.noarch 0.1.13-3.el7 epel
...
  • 安装: yum install [-y] 软件名
# 不加-y参数,在安装过程中会询问是否安装,y安装,n不安装
[root@localhost Packages]# yum install zsh
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
epel/x86_64/metalink | 5.1 kB 00:00
epel | 4.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/2): extras/7/x86_64/primary_db | 129 kB 00:00
(2/2): updates/7/x86_64/primary_db | 3.6 MB 00:01
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
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
Is this ok [y/d/N]: y
Downloading packages:
zsh-5.0.2-28.el7.x86_64.rpm | 2.4 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zsh-5.0.2-28.el7.x86_64 1/1
Verifying : zsh-5.0.2-28.el7.x86_64 1/1

Installed:
zsh.x86_64 0:5.0.2-28.el7

Complete!
  • 查看组包信息(已安装、可用): yum grouplist
[root@localhost Packages]# yum grouplist
Failed to set locale, defaulting to C
Loaded plugins: fastestmirrorThere is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.comAvailable Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
MATE Desktop
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative WorkstationAvailable Groups:
CIFS file server
Compatibility Libraries
Console Internet Tools
Desktop
Desktop Platform
...
  • 安装组包: yum groupinstall [-y] 组包名
# 不加-y参数,安装过程会询问
[root@localhost Packages]# yum groupinstall -y Desktop
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: ftp.sjtu.edu.cn
* epel: mirrors.ustc.edu.cn
...
  • 卸载:yum remove [-y] 软件包名 (会连依赖包一起卸载)
[root@localhost Packages]# yum remove zsh
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================
Package Arch Version Repository Size
==========================================================================
Removing:
zsh x86_64 5.0.2-28.el7 @base 5.6 M

Transaction Summary
==========================================================================
Remove 1 Package

Installed size: 5.6 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : zsh-5.0.2-28.el7.x86_64 1/1
Verifying : zsh-5.0.2-28.el7.x86_64 1/1

Removed:
zsh.x86_64 0:5.0.2-28.el7

Complete!
  • 升级:yum update [-y] (不要随意升级)
# 后面不接软件名,默认会将系统及其内部的软件都进行升级# 对系统进行升级的操作最好在刚安装的时候运行;# 已运行程序的最好不要升级系统
  • 根据命令搜索相关包名:yum provides "/*/COMMAND"
[root@localhost Packages]# yum provides "/*/tree"
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
...
tree-1.6.0-10.el7.x86_64 : File system tree viewer
Repo : @base
Matched from:
Filename : /usr/bin/tree

搭建本地yum仓库

由于有些情况,可能导致网络无法使用,在这个时候一个软件的本地yum仓库就十分有用。我们可以通过在/etc/yum.repos.d/目录下新增一个dvd.repo的本地仓库文件来实现无网络情况下,yum其他仓库无法安装软件的替代方案。在测试时可以断开网络连接试试看效果如何。

  1. 将光盘挂载在/mnt目录

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only

    2. 创建新仓库文件并编辑

[root@localhost ~]# vim /etc/yum.repos.d/dvd.repo

[dvd]
name=dvd # 仓库名称
baseurl=file:///mnt# 本地目录/mnt
enable=1
gpgcheck=0 # 不进行校验

    3. 清除原仓库缓存

[root@localhost ~]# yum clean all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: base dvd epel extras updates
Cleaning up everything
Cleaning up list of fastest mirrors

    4. 重新进行仓库文件的缓存

[root@localhost ~]# yum list
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
dvd | 3.6 kB 00:00
epel/x86_64/metalink | 5.1 kB 00:00
epel | 4.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/9): dvd/group_gz | 155 kB 00:00
(2/9): dvd/primary_db | 3.0 MB 00:00
(3/9): base/7/x86_64/group_gz | 156 kB 00:00
(4/9): extras/7/x86_64/primary_db | 129 kB 00:00
(5/9): base/7/x86_64/primary_db | 5.7 MB 00:02
...

如果某个仓库你已经不需要了,可以手动删除/etc/yum.repos.d/仓库.repo文件,然后执行yum clean all清理缓存,最后执行yum list再次加载缓存即可。

扩展知识

保留yum安装时所下载的rpm包

编辑/etc/yum.conf

# 添加下列配置
[main]
cachedir=你想要存放软件的目录 # 下载包存放目录
keepcache=1 # 保存已下载的rpm包
debuglevel=2
局域网软件源的搭建
  1. 搭建网络服务器(如ftp服务器)

  2. 服务器端存放软件包:把系统镜像文件内Packages目录的rpm包存放到这个目录下

  3. 创建软件仓库

    • createrepo工具安装:yum install -y createrepo

    • 创建仓库:createrepo 软件包存放目录

  4. 客户端编辑仓库文件(本地仓库配置)

    1. vim /etc/yum.repos.d/CentOS-Base.repo

[base]name=CentOS-$releasever-Base
baseurl=http://服务器ip/仓库目录
enable=1gpgcheck=0

            2. yum clean all

            3. yum list

转载于:https://my.oschina.net/u/3964535/blog/2236588

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值