Master yum source configuration in one article

Table of Contents

1. Introduction to yum source

2. yum resource library management tool

2.1. Use yum-config-manager to manage yum source repository

2.2. Download domestic image sources through wget

2.3. Common commands for operating yum source

3. Local mirror source configuration

4. Detailed explanation of *.repo files

5. Extended source configuration

6. Use yum source


1. Introduction to yum source

yum (short for Yellow dog Updater Modified), the purpose of yum is to automatically upgrade, install/remove rpm packages, collect information about rpm packages, check dependencies and automatically prompt users to solve them. The key to yum is to have a reliable repository. As the name suggests, this is a software warehouse. It can be a file server or a local software pool, but it must contain the rpm header. The header includes various information about the rpm package. Includes description, functionality, provided files, dependencies, etc. It is by collecting these headers and analyzing them that the remaining tasks can be automated.

It can automatically download and install RPM packages from a designated server, automatically handle dependencies, and install all dependent software packages at once, without the need to download and install them again and again. You can also make a yum server yourself, and you can make a yum server based on the CD image.

There are two common configuration methods for yum sources: one is to use local disk mounting when there is no network; the other is to download directly through management tools in a network environment (one is to use yum- config-manager to download, the other is to use wget to download in the /etc/yum.repos.d/ directory).

2. yum resource library management tool
2.1. Use yum-config-manager to manage the yum source warehouse

The yum-config-manager command is used to add, delete, modify and check the resource library (files under /etc/yum.repos.d/ ). It is recommended to use yum- config-manager command to make changes. This command is not installed by default in the system. This command is in the yum-utils package and can be installed through the following command.

# yum source management tool installation
yum install -y yum-utils # Non-root users need to add sudo to execute

# yum-config-manager Common commands
yum-config-manager --add-repo=** # Add mirror warehouse
yum-config-manager --enable centosplus # Enable the warehouse, centosplus is the source identifier, configured in the repo file [centosplus]
yum-config-manager --disable centosplus # Disable the warehouse, centosplus is the source identifier, configured in the repo file [centosplus]

# Example: Add Alibaba Cloud docker image warehouse
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Next, enter the /etc/yum.repos.d/ directory, find the newly added warehouse, check the source identifier, and execute --enable/--disable
2.2. Download domestic image sources through wget
# Go to the /etc/yum.repos.d/ directory
wget http://mirrors.aliyun.com/repo/Centos-7.repo # Ali’s source
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo # 163 source
# Note: There are multiple *.repo files in the yum.repo.d folder, which will be integrated into one file.
# If it contains the same source identifier, it will be overwritten (overwriting rule: the later overwrites the previous). 
2.3. Common commands for operating yum source
yum repolist # View all available sources
yum repolist [all|enable|disable] # View all repo and its status (whether it is currently enabled, if it is enabled, it will be marked as enable, and there is a 0 behind it to indicate that it is enabled, but cannot connect to the Internet)
# After configuring the yum source, you need to execute the following two commands
yum clean all # Clear all yum caches in the system
yum makecache # Generate yum cache, and the newly configured yum source will take effect
3. Local mirror source configuration
# There are two ways to configure the local mirror source:
# 1), use yum-config-manager to add;
# 2) Manually create *.repo files in the /etc/yum.repo.d/ directory
# ================================================= ================

mkdir /mnt/cdrom # Create a directory for mounting the CD
mount CentOS-7-x86_64-Everything-1511.iso /mnt/cdrom/ # Mount the CD to the image source
umount /mnt/cdrom # Uninstall

# 1. Automatically configure local warehouse
yum-config-manager --add-repo=file:///mnt/cdrom

# 2. Create a local image file vim myRepo.repo
[c7-media] # Source identifier, used to distinguish different repositories, required. Each source identifier in all configuration files cannot be repeated and must be unique (otherwise it will be overwritten)
name=CentOS-$releasever - Media # Source name, you don’t need to fill it in, but there will be a prompt
baseurl=file:///mnt/cdrom # There can be multiple addresses. Required, URL supports three protocols: http:// ftp:// file://
gpgcheck=1 # Whether to enable verification, the default value is 1 as defined in yum.conf
enabled=1 # Whether to disable this yum source, the default is 1, if set to 0 (enabled=0) it means to cancel the reference to c7-media
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# ====================== Variables referenced in the .repo file ==================== ==========
# 1. $releasever variable
The variable $releasever in yum is defined by distroverpkg in /etc/yum.conf. centos-release is an rpm package,
The so-called "distroverpkg=centos-release" means setting $releasever to the version number of the centos-release RPM package (check through the command: rpm -qi centos-release)
# 2. $basearch variable
View via arch command (x86_64)
4. Detailed explanation of *.repo files
# CentOS-Base.repo
[base] # Source ID, used to distinguish different repositories, required. Each source ID in all configuration files cannot be repeated and must be unique (otherwise it will be overwritten)
name=CentOS-$releasever - Base - mirrors.aliyun.com # Source name, you don’t need to fill it in, but there will be a prompt
#mirrorlist=* Mirror site, this can be commented out
failovermethod=priority|roundrobin # When there are multiple URLs, roundrobin means random selection, and priority means selecting sequentially from the first one.
# There can be multiple addresses. Required. URL supports three protocols: http:// ftp:// file://.
#baseUrl must point to the repodata folder of the repository on the yum server, because this folder stores the dependency information required for rpm file installation.
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
enabled=1 # Whether to disable this yum source, the default is 1, if set to 0 (enabled=0) it means disabled
gpgcheck=1 # Whether to enable verification, it has been defined in yum.conf and its default value is 1 (enabled by default)
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#If you enable yum source package verification, you need to import the RPM public key. This is only installed when the system does not import the rpm public key.
#This is equivalent to rpm --import http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
enabled=1 # Whether to disable this yum source, the default is 1, if set to 0 (enabled=0) it means disabled
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
enabled=1 # Whether to disable this yum source, the default is 1, if set to 0 (enabled=0) it means disabled
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
5. Extension source configuration

Network yum sources are basically basic yum sources, and some software may not be found there. The epel source is an extended source, which contains many software, so you need to install the epel extended source.

yum install -y epel-release # Non-root users need to add sudo
6. Use yum source

After the above configuration, you can use the yum source to install the software. Commonly used yum commands are

yum check-update # Check what software can be updated
yum -y update <pack_name> # Update all packages in the yum source (add the pack_name parameter and update the specified package package)
yum -y install <package_name> # If you do not add -y, you will be asked whether to install. If you want to install automatically without interaction, add -y.
yum install -y software name --downloadonly --downloaddir=/xx/xxx/xx/ #Only download the software but not install it
yum remove <package> # Uninstall the program package. This uninstall command takes effect on the package installed by yum or rpm. If it is compiled and installed, it is not controlled by yum.
yum upgrade/downgrade <package_name> # Upgrade/downgrade the specified package package
yum list software name # Check the software installation list
yum search software name # Search for software packages containing the software name string

I am a self-taught computer technology from scratch. I have certain learning experience in operation and maintenance, back-end, various middleware technologies, big data, etc. If I want to obtain relevant information (pdf version) or want to learn together,Follow the public on WeChat No.:Old little boy. Reply the corresponding Technical name/Technical point in the background to obtain it. (My learning purpose: once you learn it, share it for free)