Linux software management - yum tools

Posted by morgann7 on Tue, 04 Jan 2022 16:11:56 +0100

Linux software management - yum tools

yum basic overview

What is yum

yum is the package manager in RedHat and CentOS. It can download and install packages ending in rpm through the Internet, and can automatically handle dependencies without cumbersome downloading and installing again and again.

1. Get software online
2. RPM based management
3. Automatically resolve dependencies
4. The command is simple and easy to remember
5. Production best practices

What is yum source

To successfully install software packages using yum tool, you need a repository (software warehouse) containing various rpm software packages. This software warehouse is commonly called yum source or yum warehouse. This source can be local or network.

yum source configuration

After installing the system, there must be two warehouses:

Basic warehouse: base

Extended warehouse: epel

Warehouse profile

Location:/etc/yum.repos.d/
Name: it's all based on repo End of file
 to configure:
## There are two methods to configure Alibaba Base source:
wget -O /etc/yum.repos.d/zls_base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/zls_base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

## There are two methods to configure the Alibaba epel source:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Major image sources:
Alibaba cloud: https://opsx.alibaba.com/mirror
Tsinghua source: https://mirrors.tuna.tsinghua.edu.cn/
163 source: http://mirrors.163.com/
Huawei source: https://mirrors.huaweicloud.com/
Kedayuan: http://mirrors.ustc.edu.cn/

yum actual combat case

Query of packages in yum warehouse

## View the installation packages in all available warehouses in the current system
yum list

## View the detailed information of the specified package in the warehouse (you can also check if it is not installed)
For example: yum info tree 

## Query which package the ifconfig command belongs to
yum provides */ifconfig

yum warehouse query

## View the available warehouses in yum
yum repolist

## Check out all of yum's warehouses
yum repolist all

## Use the command to open or close the warehouse (Yum install - y Yum utils)
yum-config-manager --disable base
yum-config-manager --enable base

Install packages using yum or up2date

## install
yum install -y Package name

## Install locally and resolve dependencies (dependent packages must be in the warehouse)
yum localinstall

## Network resource installation
yum install -y https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/vsftpd- 3.0.2-28.el7.x86_64.rpm

Reinstall software using yum or up2date

## If you delete the software configuration file or related directory by mistake, you can use reinstall
yum reinstall nginx -y

Update software using yum or up2date

## Check the software in the current system and compare it with the software in yum warehouse. The software that needs to be updated
yum check-update

## Update software
yum update -y Package name

## Update all (very dangerous)
yum update -y

Remove package using yum or up2date

## Both remove and erase remove the related dependencies
yum remove -y tree
yum erase -y tree

yum cache related commands

## Clear all caches
yum clean all 

## Load cache (load all package names in the warehouse into memory)
yum makecache

yum package group related commands

## View package groups (list installed and all available software groups)
yum groups list

## Installation package group (install the software of Development tools group)
yum groups install Development tools

## Delete the package group (delete the package group of Development tools)
yum groups remove -y Development tools

yum history command

## View history of commands executed
yum history

## View details of the specified history yum command 25: ID
yum history info 25

## Undo history command
yum history undo 35

Download only options without installing using yum

yum install -y wget --downloadonly --downloaddir=/tmp
--downloadonly Download only, not install
--downloaddir=/route

yum's profile

yum can be configured in two ways:
1. Global configuration file / etc / yum.com conf/
2. Sub configuration file / etc / yum.com repos. D / all in the directory repo file

vim /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever   //Cache directory
keepcache=0     //Cache package, 1 startup, 0 shutdown
debuglevel=2    //Debug level
logfile=/var/log/yum.log    //Logging location
exactarch=1     //Check platform compatibility
obsoletes=1     //Check whether the package is discarded
gpgcheck=1      //Check whether the source is legal, and the public key information of the producer is required
plugins=1       //Enable query
installonly_limit=5
bugtracker_url
# metadata_expire=90m / / manually check metadata every hour
# in /etc/yum.repos.d / / including repos D directory

Make local warehouse

yum warehouse configuration file

## Name of warehouse
[base]

## The warehouse description information can be customized
name=CentOS-$releasever - Base - mirrors.aliyun.com

## Address of warehouse
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ 

## Check public and private keys        
gpgcheck=1

## Location of public key
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

## Open yum warehouse
enabled=1

http://		Hyper Text Transfer Protocol
https://	Hypertext transmission encryption protocol
ftp://		File transfer protocol
file://		Local File Protocol

Production warehouse

# 1. Compress all yum warehouse files
[root@oldboy ~]# gzip -r /etc/yum.repos.d/

# 2. Create local warehouse directory
[root@oldboy ~]# mkdir /yum_cangku

# 3. The image is mounted in this directory
[root@oldboy ~]# mount /dev/cdrom /yum_cangku/

# 4. Handwritten warehouse configuration file
[root@oldboy ~]# vim /etc/yum.repos.d/bendi.repo
[base]
name=This is local repository
baseurl=file:///yum_cangku/
gpgcheck=0
enable=1

# 5. Load cache
yum makecache

Make enterprise warehouse

The Base software package is provided on the local CD
update package available from yum cache
yum cache provides common software packages: nginx, zabbix, docker, saltstack

Prepare environment

IProle
10.0.0.10yum warehouse server
10.0.0.100Normal server client

**Target: * * for any virtual machine, modify the yum source to 10.0.0.10. This machine can be installed using yum

10.0.0.10 made into yum warehouse

# 1. Install the vsftpd service to turn the machine into a network service
[root@localhost ~]# yum install -y vsftpd

# 2. Start service 
[root@localhost ~]# systemctl start vsftpd

# 3. Close selinux
## Check whether selinux is enabled
[root@localhost ~]# getenforce 
Enforcing

## Temporary shutdown (once restarted, it will be turned on again)
[root@localhost ~]# setenforce 0

## Permanent shutdown (effective after restart) 
[root@localhost ~]# vim /etc/sysconfig/selinux 
SELINUX=disabled

# 4. Turn off the firewall 
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld

# 5. Create the base directory under the ftp directory 
[root@localhost ftp]# mkdir /var/ftp/base

# 6. Mount the CD 
[root@localhost ftp]# mount /dev/cdrom /mnt 
mount: /dev/sr0 is write-protected, mounting read-only

# 7. Copy all rpm packages 
[root@localhost ftp]# cp /mnt/Packages/* /var/ftp/base/

# 8. Install the warehouse creation command and create the repodata warehouse (Note: if the warehouse adds software each time, it needs to be regenerated)
[root@localhost base]# yum install -y createrepo

# 9. Create warehouse
[root@localhost base]# createrepo /var/ftp/base

Change yum source on 10.0.0.100

[root@oldboy /etc/yum.repos.d]# vim /etc/yum.repos.d/ftp.repo
[ftp_base]
name=ld_base
baseurl=ftp://10.0.0.10/base
gpgcheck=0
enabled=1

## Sync other people's feeds
rsync rsync://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/n/ 
https://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/n/

Using Nginx as a mirror warehouse

10.0.0.10 made into yum warehouse

# 1. Download Nginx
[root@oldboy ~]# yum install -y nginx

# 2. Modify / etc / nginx / nginx conf
server {
        listen 80;
        root /nginx_yum;
        server_name localhost;
        location / {
                autoindex on;
        }
}

# 3. Close selinux
## Check whether selinux is enabled
[root@oldboy ~]## getenforce 
Enforcing

## Temporary shutdown (once restarted, it will be turned on again)
[root@oldboy ~]## setenforce 0

## Permanent shutdown (effective after restart) 
[root@oldboy ~]## vim /etc/sysconfig/selinux SELINUX=disabled

# 4. Turn off the firewall 
[root@oldboy ~]## systemctl stop firewalld
[root@oldboy ~]## systemctl disable firewalld

# 5. Start Nginx
[root@oldboy ~]## systemctl start nginx

# 6. Create / nginx_yum/base and / nginx_yum/zabbix these two directories
[root@oldboy ~]# mkdir /nginx_yum/base
[root@oldboy ~]# mkdir /nginx_yum/zabbix

# 7. Mount the CD
[root@oldboy ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only

# 8. Copy all rpm packages to / nginx_ Download Yum / base /
[root@oldboy ~]# cp -rp /mnt/Packages/* /nginx_yum/base/

# 9. Download all zabbix packages from the Internet to / nginx_ Download Yum / zabbix /
[root@oldboy ~]# curl https://repo.huaweicloud.com/zabbix/zabbix/5.2/rhel/7/x86_64/|awk -F '"' '{print "wget -P /nginx_yum/zabbix/ https://repo.huaweicloud.com/zabbix/zabbix/5.2/rhel/7/x86_64/"$4}'|grep '.rpm$'|bash

# 10. Create warehouse
[root@oldboy ~]# createrepo /nginx_yum/base/
[root@oldboy ~]# createrepo /nginx_yum/zabbix/

Change yum source on 10.0.0.100

[root@oldboy /etc/yum.repos.d]# vim nginx_base.repo
[root@oldboy /etc/yum.repos.d]# cat nginx_base.repo 
[nginx_base]
name=This is a nginx repository
baseurl=http://10.0.0.13/base/
gpgcheck=0
enabled=1

[nginx_zabbix]
name=This is a nginx zabbix repository
baseurl=http://10.0.0.13/zabbix/
gpgcheck=0
enabled=1

Topics: Linux yum