Mirror download, domain name resolution, time synchronization Click Ali Yun Open Source Mirror Station
Introduction to 1 YUM
Introduction to 1.1 YUM
CentOS uses yum and dnf to resolve the package dependencies of rpm.
YUM:rpm's front-end program, which solves package-related dependencies, locates packages between libraries, an alternative tool for up2date, and CentOS 8 uses dnf instead of yum, but retains compatibility with Yum and is generic in configuration.
YUM, formerly YUP (Yellow dog Updater, a Software Updater for Yellow dog Linux), was originally developed by TSS Corporation (Terra Soft Solutions, INC.) in Python and later improved by the Linux development team at Duck University, named YUM (Yellow dog Updater, Modified). To successfully use the YUM mechanism to update systems and software, a software repository containing various rpm installation package files and their dependent software is required, and the server providing the software repository is also known as the "source" server. As long as information such as the address of the software repository is correctly specified in the client, the software can be installed or updated through the corresponding "source" server.
YUM(Yellow dog Updater,Modified):
- Software Update Mechanism Based on RPM Package
- Dependency can be resolved automatically
- All packages are provided centrally to the YUM software repository
How 1.2 yum works
yum is environment-dependent, service-side and client-side, allowing cross-network.
Yum is based on C/S mode:
- The yum server stores metadata for rpm packages and related packages
- The Yum client accesses the yum server for installation or query, etc.
Yum implementation process:
yum repository (warehouse) is created on the yum server. Many rpm packages and their related metadata files are stored in the warehouse in advance (under the specific directory repodata). When the yum client installs the package using the yum/dnf tool, the metadata in the repodata is automatically downloaded, the distant data is queried for related packages and dependencies, and the related packages are automatically downloaded and installed from the warehouse.
Server (both RPM packages and metadata are required):
- RPM package (stored in package folder Packages)
- Metadata (stored in the metadata folder repodata, which contains: catalogs (software catalogs), software dependencies, software grouping)
#Looking at the Yum repository that comes with the disc, you can see the Packages folder and the repodata folder: [root@localhost ~]# Mount/dev/sr0/mnt //Mount the disc to/mnt/directory mount: /dev/sr0 Write protected, mounted read-only [root@localhost ~]# Ls/mnt //View package and metadata folders on CD CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7 EFI images Packages RPM-GPG-KEY-CentOS-Testing-7 EULA isolinux repodata TRANS.TBL
Local warehouse type:
- Warehouse for Discs (Basic Warehouse)
- epel extended warehouse
1.3 How to implement installation services
2 yum client configuration
yum client profile
/etc/yum.conf #Provide public configuration for all warehouses /etc/yum.repos.d/*.repo #Configuration files for each warehouse
2.1 yum master profile
Location: /etc/yum.conf
[root@localhost ~]# vim /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever //The cache directory of RPM packages downloaded by yum, $basearch for hardware architecture, $release ever system version such as 7 keepcache=0 //Whether or not to save the cache 0 means not to save, 1 means to save debuglevel=2 //Debug level (0-10), default 2 logfile=/var/log/yum.log //Log file location exactarch=1 //Allow different versions of rpm installation obsoletes=1 //This is an update parameter, whether to allow older versions to run gpgcheck=1 //Whether to validate the GPG(GNU Private Guard) key, 1 means validation plugins=1 //Allow plug-ins, 1 for allow installonly_limit=5 //Save several cores bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # Variables available in yum's repo profile: $releasever: current OS Major release number, e.g. 8, 7, 6 $arch: CPU Architecture, such as: aarch64, i586, i686,x86_64 etc. $basearch: System basic platform; i386, x86_64 $contentdir: Represents a directory, such as: centos-8,centos-7 $YUM0-$YUM9:Custom variable
2.2 yum repository profile
2.2.1 Warehouse Profile Description
Location: /etc/yum.repos.d/*.repo
The default yum repository in the system is centos'official yum source (foreign source), which requires an external network to be connected.
[root@localhost yum.repos.d]# ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@localhost yum.repos.d]# vim yuji.repo //yum repository profile format [yuji] name=yuji #Set Name baseurl=file: ///mnt #Set the link address, file://is a fixed format for local sources enabled=1 #Open this yum source gpgcheck=0 #Whether to verify the public key, 0 means no verification is required
Several forms of baseurl in the yum warehouse configuration file:
# Local Source Local directory file:// # Network Source FTP service ftp:// HTTP service http:// External Network Environment https://
2.2.2 Path to baseurl
yum Source for CentOS System
#Ali Yun https://mirrors.aliyun.com/centos/$releasever/
yum Source for EPEL
#Ali Yun https://mirrors.aliyun.com/epel/$releasever/x86_64
Update Source
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/
2.3 log file
Location: /var/log/yum.log
[root@localhost yum.repos.d]# Head-5/var/log/yum. Log //View log files Jan 19 10:55:29 Installed: tree-1.6.0-10.el7.x86_64 Feb 21 23:21:53 Installed: finger-0.17-52.el7.x86_64 Mar 19 17:10:29 Updated: 32:bind-license-9.11.4-26.P2.el7_9.9.noarch Mar 19 17:10:30 Updated: 32:bind-libs-lite-9.11.4-26.P2.el7_9.9.x86_64 Mar 19 17:10:30 Updated: 32:bind-libs-9.11.4-26.P2.el7_9.9.x86_64
3 yum command details
command | No keywords | Join keywords, packages, package groups |
---|---|---|
yum list | Show all available packages | Single installable package |
yum info | Show information about all available packages | Individual specific information |
yum search | \ | Fuzzy Find All Related Information |
yum whatprovides | \ | Find precisely |
yum install | \ | Install specific packages |
yum update | All software upgrades, update the kernel | Specific software upgrade |
yum upgrade | Update packages only, but not kernels | Specific software updates |
yum remove | \ | Uninstall specific software |
yum history | View current yum operation history | \ |
yum history info | \ | List the details of a transaction with a sequence number |
yum history undo | \ | Sequence number to uninstall the software installed in the sequence number |
yum history redo | \ | Re-execute operation in sequence number by adding sequence number |
Package group:
command | No keywords | Join keywords, packages, package groups |
---|---|---|
yum grouplist | Show all available package groups | Show specific package groups |
yum groupinfo | Show all package group details | Display specific information about specific package groups |
yum groupinstall | \ | Install specific package groups |
yum group update | All package group upgrades | Specific package group upgrade |
yum groupremove | \ | Uninstall package group specific software |
Tips:
When the package is not cleanly uninstalled by using the "yum remove software name", you can use the "yum history undo serial number" to uninstall the entire package without any residue.
4 yum warehouse building method
Software warehouse is provided in:
- Local directory: file://absolute path
- FTP Service: ftp://ip Path in Address/Site
- HTTP service: http://domain name or ip address/path in site
4.1 Build local yum warehouse
Setup steps:
Step 1, Mount the disc (/dev/sr0 or/dev/cdrom is fine, /dev/cdrom is a soft link to/dev/sr0)
[root@localhost ~]# Mount/dev/sr0/mnt //Mount the disc to/mnt directory mount: /dev/sr0 Write protected, mounted read-only [root@localhost ~]# Df-Th //Check if mounting was successful file system type Capacity used Available Used% mount point /dev/mapper/centos-root xfs 10G 4.0G 6.1G 40% / devtmpfs devtmpfs 897M 0 897M 0% /dev tmpfs tmpfs 912M 0 912M 0% /dev/shm tmpfs tmpfs 912M 9.1M 903M 1% /run tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sdb5 xfs 2.0G 33M 2.0G 2% /data/bb /dev/sda1 xfs 1014M 179M 836M 18% /boot /dev/sdb1 xfs 10G 33M 10G 1% /data/aa /dev/mapper/vg01-lvmail xfs 13G 33M 13G 1% /data/mail tmpfs tmpfs 183M 12K 183M 1% /run/user/42 tmpfs tmpfs 183M 0 183M 0% /run/user/0 /dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
Note: The mount command is a one-time mount and does not exist after exiting the current terminal or restarting. Permanent mounting requires modification of the configuration file/etc/fstab.
Step 2, Switch to/etc/yum.repo.d/Directory, remove the warehouse files that came with it.
[root@localhost ~]# Cd/etc/yum.repos.d/ //Switch to/etc/yum.repos.d/Directory [root@localhost yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@localhost yum.repos.d]# mkdir aaa //Create a new directory named aaa [root@localhost yum.repos.d]# mv *.repo aaa //will be in the yum warehouse to. File at end of repo moved to aaa [root@localhost yum.repos.d]# ls aaa
Step 3. Create a new yum warehouse file.
[root@localhost yum.repos.d]# vim yuji.repo //new yum repository file [yuji] name=yuji #Set Name baseurl=file:///mnt #Set the link address, file://is fixed format, points to/mnt enabled=1 #Open this yum source gpgcheck=0 #No need to verify public key
Step 4. Clean up the cache and install the software.
[root@localhost yum.repos.d]# yum clean all //clean up yum cache [root@localhost yum.repos.d]# yum makecache //Re-establish metadata [root@localhost yum.repos.d]# yum list //View list of installable software [root@localhost yum.repos.d]# Yum install dhcp-y //yum install DHCP test success
4.2 Set up Ali Cloud Warehouse (http external network environment)
The default warehouse file is foreign cloud warehouse, which is slower and can be replaced by Ali cloud warehouse.
Operation steps:
Step 1, Switch to/etc/yum.repo.d/Directory, remove the warehouse files that came with it.
[root@localhost ~]# Cd/etc/yum.repos.d/ //Switch to/etc/yum.repos.d/Directory [root@localhost yum.repos.d]# mkdir aaa [root@localhost yum.repos.d]# mv *.repo aaa //will be in the yum warehouse to. File at end of repo moved to aaa [root@localhost yum.repos.d]# ls aaa
Step 2, New Ali Cloud Warehouse.
[root@localhost yum.repos.d]# vim ali.repo [ali] name=aliyun #baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/ Which version of //Open works, the main explanatory variable here baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=0 [epel] //epel source warehouse name=epel baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/ gpgcheck=0 [update] //Update Package Warehouse name=update baseurl=https://mirrors.aliyun.com/centos/7/updates/x86_64/ gpgcheck=0
Step 3. Clean up the cache and install the software.
[root@localhost yum.repos.d]# yum clean all //clean up yum cache [root@localhost yum.repos.d]# yum makecache //Re-establish metadata [root@localhost yum.repos.d]# yum list //View list of installable software [root@localhost yum.repos.d]# Yum install tree-y //yum install tree test success
4.3 http Cloud Warehouse
Cloud warehouse built by http can be used in both external and Intranet environments, but it is mostly used in intranet.
Server: 192.168.72.10
Client: 192.168.72.129
Setup steps:
Step 1. Install the hhtpd service program on the server side.
[root@localhost ~]# yum install httpd -y
Step 2. Switch the server to/var/www/html/directory, create a new subdirectory centos7, and mount the CD-ROM drive into the centos7 directory (you can also copy all the packages in the CD-ROM drive into that directory).
[root@localhost ~]# Cd/var/www/html //Switch directories [root@localhost html]# ls [root@localhost html]# mkdir centos7 //New directory centos7 [root@localhost html]# Mount/dev/sr0. / Centos7 //Mount the CD-ROM drive in the centos7 directory mount: /dev/sr0 Write protected, mounted read-only [root@localhost html]# ls ./centos7 CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7 EFI images Packages RPM-GPG-KEY-CentOS-Testing-7 EULA isolinux repodata TRANS.TBL
Step 3. The server closes the firewall and selinux to start the httpd service.
[root@localhost html]# systemctl stop firewalld [root@localhost html]# setenforce 0 setenforce: SELinux is disabled [root@localhost html]# systemctl start httpd
Step 4, Client Switch to/etc/yum.repos.d/Directory, create a new folder, move the default Yum repository file to that directory. Write a new warehouse file
[root@192 ~]# Cd/etc/yum. Repos. D //Client Switch Directory [root@192 yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@192 yum.repos.d]# mkdir bak //New Folder [root@192 yum.repos.d]# mv *.repo bak //Move the default warehouse file to this folder [root@192 yum.repos.d]# ls bak [root@192 yum.repos.d]# vim http.repo //Write a new warehouse file [http] name=http baseurl=http://192.168.72.10/centos7 enabled=1 gpgcheck=0
Step 5, Clean up the yum cache and re-establish the metadata. It also tests whether the package can be successfully installed using yum.
[root@192 yum.repos.d]# yum clean all && yum makecache Plugins loaded: fastestmirror, langpacks Cleaning up software sources: ftp Cleaning up everything Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos Cleaning up list of fastest mirrors Plugins loaded: fastestmirror, langpacks ftp | 3.6 kB 00:00:00 (1/4): ftp/group_gz | 156 kB 00:00:00 (2/4): ftp/primary_db | 3.1 MB 00:00:00 (3/4): ftp/other_db | 1.2 MB 00:00:00 (4/4): ftp/filelists_db | 3.1 MB 00:00:00 Determining fastest mirrors Metadata cache established [root@192 yum.repos.d]# Yum install ftp-y //test the yum installation to install successfully.
4.4 ftp Cloud Warehouse
The cloud warehouse built by ftp can be used in both external and Intranet environments, but it is mostly used in the intranet.
Server: 192.168.72.10
Client: 192.168.72.129
Setup steps:
Step 1. Install the vsftpd service program on the server side.
[root@localhost html]# yum install vsftpd -y
Step 2. Switch the server to a new subdirectory centos under /var/ftp/directory and mount the CD-ROM into the centos directory (you can also copy all the file packages inside the CD-ROM into the centos directory).
[root@localhost html]# Cd/var/ftp //switch to/ftp/var/directory [root@localhost ftp]# ls pub [root@localhost ftp]# mkdir centos //Create centos directory [root@localhost ftp]# [root@localhost ftp]# Mount/dev/sr0. / centos //Mount the CD-ROM drive in the centos directory mount: /dev/sr0 Write protected, mounted read-only [root@localhost ftp]# ls ./centos CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7 EFI images Packages RPM-GPG-KEY-CentOS-Testing-7 EULA isolinux repodata TRANS.TBL
Step 3. The server opens the vsftpd service, closes the firewall and selinux.
[root@localhost ~]# systemctl start vsftpd [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0
Step 4. Client installs ftp program to test if ftp service is normal.
[root@192 ~]# Yum install ftp-y //install FTP program [root@192 ~]# ftp 192.168.72.10 //Test whether the ftp service can access the server properly Connected to 192.168.72.10 (192.168.72.10). 220 (vsFTPd 3.0.2) Name (192.168.72.10:root): ftp 331 Please specify the password. Password: 230 Login successful. //Can be accessed normally Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,72,10,85,22). 150 Here comes the directory listing. drwxr-xr-x 8 0 0 2048 Sep 05 2017 centos drwxr-xr-x 2 0 0 6 Jun 09 2021 pub 226 Directory send OK. ftp> bye 221 Goodbye.
Step 5. The client writes the yum warehouse file.
[root@192 ~]# Cd/etc/yum. Repos. D //Switch directories [root@192 yum.repos.d]# ls bak2 CentOS-Debuginfo.repo CentOS-Sources.repo CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo CentOS-CR.repo CentOS-Media.repo [root@192 yum.repos.d]# mkdir bak1 //New Folder [root@192 yum.repos.d]# mv *.repo bak1 //Move the default warehouse files to this directory [root@192 yum.repos.d]# ls bak1 bak2 [root@192 yum.repos.d]# vim ftp.repo //Write a new warehouse file [ftp] name=ftp baseurl=ftp://192.168.72.10/centos //Path to server-side/var/ftp/centos/directory enabled=1 gpgcheck=0
Step 6. Clean up the yum cache and re-establish the metadata. It also tests whether the package can be successfully installed using yum.
[root@192 yum.repos.d]# yum clean all && yum makecache Plugins loaded: fastestmirror, langpacks Cleaning up software sources: ftp Cleaning up everything Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos Cleaning up list of fastest mirrors Plugins loaded: fastestmirror, langpacks ftp | 3.6 kB 00:00:00 (1/4): ftp/group_gz | 156 kB 00:00:00 (2/4): ftp/primary_db | 3.1 MB 00:00:00 (3/4): ftp/other_db | 1.2 MB 00:00:00 (4/4): ftp/filelists_db | 3.1 MB 00:00:00 Determining fastest mirrors Metadata cache established [root@192 yum.repos.d]# Yum install httpd-y //Test the yum installation to install successfully.
4.5 Build local epel source warehouse
Scenario for local epel source warehouse:
- In the case of external network connection, you can use foreign sources or Aliyun warehouse, etc.
- However, in practice, the internal network of the company often cannot connect to the external network. At this time, you can set up a local epel source warehouse in advance, that is, Download all the software packages of the epel source in advance in a server that can connect to the external network. After you have written the warehouse file, you can also use yum to install the software packages when you are offline.
- The server-side epel source repository can then be used by other hosts either through http or ftp.
Operation steps:
Step 1. Install the epel source and download all the software packages for the epel source.
[root@localhost ~]# yum install epel-release //install EPEL source [root@localhost ~]# mkdir centos7 //New centos7 Directory [root@localhost ~]# Reposync-r epel-p/centos7/ & //download synchronous EPEL source package, download to/centos7/directory, &meaning download in background [root@localhost ~]# ls /centos7 epel
Step 2. Install the createrepo command (the command that establishes metadata), then use the createrepo command to create metadata.
[root@localhost ~]# Yum-y install createrepo //install createrepo command [root@localhost ~]# Createrepo-v/centos7/epel //Create metadata (software catalogs, dependencies) [root@localhost ~]# Cd/centos7/epel//Switch to centos7/epel directory [root@localhost epel]# ls) //View packages and metadata Packages repodata
Step 3, Switch to/etc/yum.repos.d directory, remove the default warehouse file, and write a new warehouse file.
[root@localhost ~]# Cd/etc/yum.repos.d/ //Switch to/etc/yum.repos.d/Directory [root@localhost yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@localhost yum.repos.d]# mkdir aaa //Create a new directory named aaa [root@localhost yum.repos.d]# mv *.repo aaa //will be in the yum warehouse to. File at end of repo moved to aaa [root@localhost yum.repos.d]# ls aaa [root@localhost yum.repos.d]# vim epellocal.repo //new yum repository file [epellocal] name=epellocal #Set Name baseurl=file:///centos7/epel #Set link address, path to/centos7/epel directory enabled=1 #Open this yum source gpgcheck=0 #No need to verify public key
If other hosts want to use the epel repository in this machine, they can build it locally using http or ftp:
baseurl=http://192.168.72.10/centos7/epel //http mode baseurl=ftp://192.168.72.10/centos7/epel //ftp mode
5 Tips
5.1 Generate warehouse files by command
The above four methods are all configured by manually writing the yum warehouse file or by command.
Commands are written/etc/yum, just like the file configuration above. Repos. D, only the command line is to automatically generate the warehouse file.
1. Setting up external network environment
Command format:
wget -O /etc/yum.repos.d/name.repo(Customize to repo End File Name) Source Path
The wget command configures the Ali Cloud Warehouse:
wget -O /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2. Build the internal network environment
Command format:
yum-config-manager --add-repo=file:// yum-config-manager --add-repo=ftp://
Example:
yum-config-manager --add-repo=file:///mnt //Use local source yum-config-manager --add-repo=ftp://192.168.72.10/centos7//ftp mode build
5.2 Download dependent packages locally (but do not install)
When a host on the internal network installs a package but lacks a dependent package, the dependent package can be downloaded by a server that can connect to the external network and shared with the host.
You can then use the command "yum install--downloadonly", which can download only the required software and its dependent packages without installing the software, greatly reducing the problem of finding dependent packages when installing without an external network. The command format is as follows:
yum install --downloadonly +Software Name --downloaddir=Appoint rpm Package Storage Path
For example, the dependent packages needed to download nginx are in the / mnt/nginx directory:
yum install nginx --downloadonly --downloaddir=/mnt/nginx
This article is from: https://juejin.cn/post/7078172295302217735