rpm, yum and yum LAN software sources

Chapter 7 Package Installation and Uninstallation

7.1 Three ways to install packages

  • rpmtools

rpm (Redhat Package Manager) RPM package manager is a set of management programs that install the packages we need to Linux hosts in a database record manner. The rpm package is a pre-compiled and packaged file on the Linux machine, and it is very fast to install. But there is a disadvantage: the installation environment must be the same as or equivalent to the compilation time; there is mutual dependence between packages, so when installing or uninstalling packages, you need to install/uninstall the dependent packages first. It is necessary to uninstall this package.

  • yumtools

The yum command is an rpm-based package manager in Fedora, RedHat and SUSE. It enables system administrators to interact and automate finer and more detailed management of RPM packages. It can automatically download and install RPM packages from specified servers. Handle dependencies and install all dependent software packages at one time, without having to download and install tediously again and again.

  • source package

The source code distribution of Linux software refers to the distribution form that provides all the program source codes of the software, and requires users to compile and install executable binary codes by themselves. The advantage is that the configuration is flexible, some functions/modules can be removed or retained at will, and it is suitable for a variety of hardware/operating system platforms and compilation environments; the disadvantage is that it is more difficult.

7.2-7.3 rpm tools

rpm package introduction (preparation)

Mount the system installation disk image (mount to an empty directory, where the /mnt/ directory is not used, so directly mount it to the /mnt/ directory)

[root@3 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  1.3G   27G    5% /
devtmpfs        483M     0  483M    0% /dev
tmpfs           493M     0  493M    0% /dev/shm
tmpfs           493M  6.8M  486M    2% /run
tmpfs           493M     0  493M    0% /sys/fs/cgroup
/dev/sda1       197M  109M   88M   56% /boot
tmpfs            99M     0   99M    0% /run/user/0
[root@3 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@3 mnt]# ls
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL
[root@3 Packages]# ls
yum-plugin-changelog-1.1.31-40.el7.noarch.rpm
yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
yum-plugin-tmprepo-1.1.31-40.el7.noarch.rpm
yum-plugin-verify-1.1.31-40.el7.noarch.rpm
yum-plugin-versionlock-1.1.31-40.el7.noarch.rpm
……
(rpm包格式:包名、版本号、发布版本号、平台)

The rpm package is stored under the Packages file!

rpm tool usage

install rpm package

Syntax:  rpm [options] [parameters]
Options:
-i:=install, install
-v: visualize
-h: display installation progress
Commonly used when installing an rpm package with options:
--force: force installation
--nodeps:=no dependent installation without dependencies (ignoring dependencies with other packages)

  • eg1: Install an rpm package (no dependencies)
[root@3 Packages]# rpm -ivh x86info-1.30-6.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:x86info-1:1.30-6.el7             ################################# [100%]
  • eg2: Install an rpm package (with dependencies)
[root@3 Packages]# rpm -ivh yp-tools-2.14-3.el7.x86_64.rpm
错误:依赖检测失败:
	ypbind 被 yp-tools-2.14-3.el7.x86_64 需要
## 即,两个包之间存在依赖关系
## 解决办法:
①:
[root@3 Packages]# rpm -iv hyp-tools-2.14-3.el7.x86_64.rpm yp-tools-2.14-3.el7.x86_64
②:
[root@3 Packages]# rpm -ivh --force yp-tools-2.14-3.el7.x86_64.rpm
(添加--force或--nodeps选项即可安装)

Note:  When installing a package with dependencies, you can install the package it depends on first and then install the target package (install the package with dependencies at the same time), or use the --force or --nodeps option to forcibly install (not recommended) .

upgrade rpm package

Syntax:  rpm [-U] [package name]

[root@3 Packages]# rpm -Uvh x86info-1.30-6.el7.x86_64.rpm
Preparing...                          ################################# [100%]
	package x86info-1:1.30-6.el7.x86_64 is already installed

Note:  If you upgrade an already installed package of the latest version, there is no operation after executing this command.

Uninstall an rpm package

Syntax:  rpm [-e] [package name]

[root@3 Packages]# rpm -e x86info-1.30-6.el7.x86_64.rpm
error: package x86info-1.30-6.el7.x86_64.rpm is not installed
[root@3 Packages]# rpm -e x86info

Note:  directly follow the registration when uninstalling, without the information of the package; when there is a dependency between the packages, you also need to uninstall the dependent package first.

Query rpm package

Query installed packages

Syntax:
rpm [-q] [package name] Query the specified package
rpm [-qa] Query all installed packages
eg:

[root@3 Packages]# rpm -q kmod
kmod-20-9.el7.x86_64
#########################################
[root@3 Packages]# rpm -qa |head -5
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

Query information about installed packages

Syntax:  rpm [-qi] [package name]
i=information

[root@3 Packages]# rpm -qi filesystem
Name        : filesystem
Version     : 3.2
Release     : 21.el7
Architecture: x86_64
Install Date: Mon May 22 01:19:49 2017
Group       : System Environment/Base
Size        : 0
……

Query the files installed by a package

Syntax:  rpm [-ql] [package name]
l=list

[root@3 Packages]# rpm -ql vim-enhanced
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor

View the installation package of a file

Syntax:  rpm [-qf] [absolute file path]

[root@3 Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-1.el7_3.1.x86_64

That is, query its installation package through its absolute path, and use the which command to query when its absolute path is not known.

backtick command

The function of the backticks is to execute the Linux command within the backticks first, and then assign the execution result to a variable. That is, put a Linux command in backticks on the command line, the command will be executed first, and then its result will be used as an argument to the command line.

eg:

[root@3 Packages]# rpm -qf `which cd`
bash-4.2.46-20.el7_2.x86_64

Description:  Execute the "which cd" command first, and then execute the command with the result of "which cd" as the parameter of "rpm -qf".

7.4 yum tool usage

List all rpm packages

Syntax:  yum list

[root@3 Packages]# yum list 
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
Installed Packages
NetworkManager-libnm.x86_64                1:1.4.0-12.el7              @anaconda
NetworkManager-team.x86_64                 1:1.4.0-12.el7              @anaconda
zsh.x86_64                                        5.0.2-25.el7_3.1                    updates  
zsh-html.x86_64                                   5.0.2-25.el7_3.1                    updates  
zziplib.i686                                      0.13.62-5.el7                       base     
zziplib.x86_64                                    0.13.62-5.el7                       base   
……
Exiting on Broken Pipe
注: 第一列是包名,第二列是版本号,第三列是库

Note:  "@" in the location of the library indicates that it is installed; "updates" indicates that it has been installed, there is a new version and needs to be upgraded; the others indicate rpm packages that can be installed but not yet installed.

  • yum configuration file
[root@3 Packages]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
  • Information about the configuration file base
[root@3 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
……
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
……

Description:  This file contains the mirror address information of the base library where the rpm package is located!

search for rpm packages

Syntax:  yum search [keyword]

[root@3 Packages]# yum search vim
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
====================================== N/S matched: vim =======================================
golang-vim.noarch : Vim plugins for Go
protobuf-vim.x86_64 : Vim syntax highlighting 
vim-minimal.x86_64 : A minimal version of the VIM editor

  Name and summary matches only, use "search all" for everything.

Note:  When you use this command to search, all the information containing 'vim' (keyword) will be listed, which is not accurate. In order to only search for related rpm packages, the following methods can be used:

[root@3 Packages]# yum list |grep vim
Failed to set locale, defaulting to C
vim-common.x86_64                          2:7.4.160-1.el7_3.1         @updates 
vim-enhanced.x86_64                        2:7.4.160-1.el7_3.1         @updates 
vim-filesystem.x86_64                      2:7.4.160-1.el7_3.1         @updates 
vim-minimal.x86_64                         2:7.4.160-1.el7             @anaconda

Description:  grep means filtering.

List rpm package groups

Syntax:  yum grouplist

[root@3 Packages]# 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.btte.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
Available Environment Groups:
   Minimal Install
   Compute Node
……
Available Groups:
   Compatibility Libraries
   Console Internet Tools
……
Done

install rpm package

Syntax:  yum install [-y] [package name]
Description:  If the '-y' option is not added, it will be installed interactively with the user. The first is to list the rpm packages that need to be installed, and then the user will be asked if they need to be installed. Enter 'y' to install it, and enter 'n' to not install it. This is too troublesome, so add the '-y' option directly and omit the connection with the user. interaction between.

Install rpm package group

Syntax:  yum groupinstall [-y] [package group name]
If you don't know the group name, you can view it with yum grouplist (Note: You can only use the English name when installing).

uninstall rpm package

Syntax:  yum remove [-y] [package name]
Description:  The '-y' option is the same as the usage of install. It should be noted that when using this command to uninstall, all packages that the target file depends on will be deleted at the same time, so it is necessary to Use with caution!

upgrade rpm package

Syntax:  yum update [-y] [package name]
Description:  If no package name is added, all packages in the system and the system itself will be upgraded (use with caution, generally only when the system is just installed).

yum provides

The function of this command is to search its rpm package name by known command name.
usage:

[root@3 Packages]# yum provides “/*/vim”

Note:  Because the command location is uncertain, use '*' (wildcard) to represent its path when searching.

7.5 yum builds a local warehouse

Sometimes the Linux system cannot be connected to the Internet. At this time, the yum source on the Internet cannot be used. We need to use the Linux system CD to create a yum source.

step

Mount the CD - delete all repo files in the /etc/yum.repos.d/ directory - create a new file dvd.repo - clear the original cache 'yum clean all'.

[root@3 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak   
备份原.repo文件
[root@3 ~]# cd /etc/yum.repos.d   切换目录
[root@3 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[root@3 yum.repos.d]# rm -rf ./*
删除原有repo文件
[root@3 yum.repos.d]# vim dvd.repo
[dvd]
name=install dvd        
baseurl=file:///mnt
enable=1
gpgcheck=0
此部分内容除baseurl目录根据个人实际操作更改外,其余内容固定。

[root@3 yum.repos.d]# 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
[root@3 ~]# yum list 
……
Available Packages  还未安装的可安装rpm包的库都变成dvd
ypserv.x86_64                                    2.31-8.el7                           dvd      
yum-langpacks.noarch                             0.4.2-7.el7                          dvd      
yum-plugin-aliases.noarch                        1.1.31-40.el7                        dvd      
yum-plugin-changelog.noarch                      1.1.31-40.el7                        dvd      
yum-plugin-tmprepo.noarch                        1.1.31-40.el7                        dvd      ……

After the configuration is complete, you can directly use yum to install the required rpm packages. If you do not want to use the local yum source, you need to delete the /etc/yum.repos.d/dvd.repo file and restore the original configuration file.

Extension 1: yum keeps already installed packages

You can set yum to keep downloaded rpm packages for later upgrades or reinstallations.
Modify /etc/yum/conf to:

[main]
cachedir=/home/soft1/yumcache
keepcache=1
debuglevel=2

The cachedir is where the downloaded packages are placed, and can be modified to the location where you want to place them.
When keepcache is 1, it means to save the downloaded rpm package.

Extension 2: yum local area network software source construction

Build Apache server or ftp server

yum installation or binary package installation.

Prepare the RPM package

Download both DVD1 and DVD2.iso of CentOS, decompress all the contents in DVD1.iso, put them in the /var/www/html/centos-6 directory, and then decompress DVD2.iso to the Packages directory. Copy the rpm package to the /var/html/centos-6/Packages directory, so that there are more than 6000 rpm packages in /var/html/centos-6/Packages.

Create yum repository

准备createrepo:yum -y install createrepo

Create repository: createrepo /var/www/html/centos-6/

After the creation is complete, some files will be generated under /var/www/html/centos-6/repodata.

Use software sources

Try the software source on other centos machines to see if it works.

  • First modify the software source configuration file on the machine:
# cd /etc/yum.repos.d/
# mkdir bk
# mv *.repo bk/
# cp bk/CentOS-Base.repo ./
# vi CentOS-Base.repo
  • The CentOS-Base.repo file is modified as follows:
[base]
name=CentOS-$releasever - Base
baseurl=http://*.*.*.*/centos-6/
gpgcheck=1(改成0下面那行就不用设置了)
gpgkey=http:///*.*.*.*/centos-6/RPM-GPG-KEY-CentOS-6
enabled=1
#released updates 
#[updates]
#name=CentOS-$releasever - Updates
#baseurl=http:///*.*.*.*/centos-6/
#gpgcheck=1
#gpgkey=http:///*.*.*.*/centos-6/RPM-GPG-KEY-CentOS-6
#enabled = 1

After saving, you can use the software source of the LAN:

# yum update

The original address of the article: http://www.linuxidc.com/Linux/2013-07/87315.htm

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325091704&siteId=291194637