CentOS/RHEL內軟件安裝1

CentOS/RHEL內軟件安裝1python

 

10月9日任務linux

7.1 安裝軟件包的三種方法git

7.2 rpm包介紹shell

7.3 rpm工具用法vim

7.4 yum工具用法centos

7.5 yum搭建本地倉庫(視頻中ppt小錯誤: gpcheck改成gpgcheck,yum cean 改成 yum  clean)緩存

 

常見安裝軟件包的三種方法

  • rpm工具(紅帽包管理工具)bash

    • 安裝位置、文件名等在安裝前就已肯定服務器

    • 安裝較爲簡單網絡

  • 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

相關文章
相關標籤/搜索