Practical combat of yum source configuration under Linux

1. Management of software packages under Linux

1. Software installation method

① RPM package management (dependency issues need to be resolved separately)

② YUM package management (requires network and YUM warehouse support, will automatically download software from the Internet, and automatically resolve dependencies)

③ Source code installation (the installation process is relatively complicated, source code installation is a three-step process. Advantages: highly customizable)

Software: mainline, stable

2. Configuration process of source code installation

In Linux systems, source code installation is divided into three steps (three steps):

Step 1: Configuration process (configuring the installation path of the software)

Step 2: Compilation process (compile the software from source code into an installable program)

Step 3: Installation process (install the compiled program)

# ./configure & amp; & amp; make & amp; & amp; make install

3. Detailed explanation of the configuration process of source code installation (customization)

# cd software source code package
# ./configure [options]
# ./configure --help
?
--prefix=... Directories to put files in /usr/local software home directory
--bindir=... Directory of $prefix/bin command
--etcdir=... $prefix/etc Configuration file directory httpd => /etc/httpd/httpd.conf
--mandir=... $prefix/share/man man document path
--locale=... $prefix/share/locale language encoding
...

4. Detailed explanation of the compilation process

# make

In the Linux operating system, the main function of make is to package source codes in other languages into programs that Linux can recognize and install. The compilation process requires the support of a gcc software (development tool)!

5. Installation process

# make install

6. Axel multi-thread download software source code installation

Step one: Get axel multi-thread download software

Step 2: Upload the axel software package to the Linux system

Step 3: Install axel software (three steps for source code installation => configuration + compilation + installation)

① Decompress the software

# tar -zxf axel-2.4.tar.gz
or
# tar -xf axel-2.4.tar.gz

② Use the cd command to switch to the axel directory

# cd axel-2.4

③ Configure axel software (do not use the default configuration)

# ./configure --help
Usage: ./configure [OPTIONS]
Option Description Default
--prefix=... Directories to put files in /usr/local
--bindir=... $prefix/bin
--etcdir=... $prefix/etc
--mandir=... $sharedir/man
--locale=... $sharedir/locale

Set the installation path of axel software to /opt/axel

# ./configure --prefix=/opt/axel

④ Compile and install axel software

# make
# make install
or
# make & amp; & amp; make install
 & amp; & amp;: Logical AND. If the make compilation is successful, the make install installation program on the right will be executed immediately. If the make compilation fails, the above program will stop execution and then throw an error. 

Step 4: Test and use

[root@yunwei ~]# axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
bash: axel: command not found...

The main reason for the above problems is that we did not use the default installation method, so when we executed the axel command, it could not find the corresponding software.

Step 5: Solve the problem of inaccessible commands

The first method: using soft links (similar to shortcuts in Windows)
The second way: use environment variables (important, environment variables in Linux)

7. Use soft links to solve command not found

# which axel
/usr/bin/which: no axel in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
?
# ll /opt/axel/bin
axel
?
Solution: Create a shortcut to /opt/axel/bin/axel to /usr/local/bin
# ln -s /opt/axel/bin/axel /usr/local/bin/axel
?
Basic syntax:
# ln -s source file path soft link path
?
# axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

8. Use environment variables to solve command not found

environment variables

Terminal => Command => System environment variable (PATH => /etc/profile) => Storage path of some commands

After the axel multi-threaded download software is successfully installed through the source code, the axel command does not appear in the system environment variables because the default installation path is not used, so command not found appears.

Step 1: Query the environment variables of the current system

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Step 2: Add the directory where axel is located to the environment variable

① Use vim to edit the /etc/profile file and append to the last line
# vim /etc/profile
...
export PATH=$PATH:/opt/axel/bin
# source /etc/profile => means the above configuration will take effect immediately
?
② Use the echo command to append a line to the /etc/profile file
# echo 'export PATH=$PATH:/opt/axel/bin' >> /etc/profile
# source /etc/profile

Step 3: Test whether the axel command can be used

# axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

9. Solve the problem that the source code installation software manual cannot be found

Problem reappears:

[root@localhost axel]# man axel
No manual entry for axel
Reason: The specified man document cannot be found

solution:

[root@localhost axel]# vim /etc/man.config
...
Add the following content:
MANPATH /opt/axel/share/man

10. Uninstall software installed from source code

Step one: Enter the source code installation package
# cd axel-2.4
# make uninstall => Install software installation packages and other programs
# make distclean => Uninstall the compilation and configuration process
Step 2: Delete the software directory
# rm -rf /opt/axel

2. YUM source overview

1. Function of yum source

==Software package manager==, similar to 360 software manager

2. Advantages of yum source

RPM installation (download software, install separately, dependencies need to be resolved)

Source code installation (download the source code package of the software, unzip it, enter the directory => configure + compile + install)

yum source: equivalent to an upgraded version of rpm package management

It can ==solve the dependencies between software packages== and improve the work efficiency of operation and maintenance personnel.

The bottom layer of the yum source is still based on RPM for software installation operations, so after yum installs the software, we can also use rpm -qa |grep software name

3. Yum source classification

☆ Local yum source

The yum warehouse is == local == (system CD/image file) => does not require network support

☆ Network yum source

The yum warehouse is not local, but ==remote==

  • The more well-known network sources in China (aliyun source, 163 source, sohu source, open source mirrors of well-known universities, etc.)

    Alibaba Source: Alibaba Open Source Mirror Station-OPSX Mirror Station-Alibaba Cloud Developer Community

    NetEase source: Welcome to NetEase open source mirror site

    Sohu source: Index of /

    Tsinghua Source: Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  • The more well-known foreign network sources (centos source, redhat source, extended epel source, etc.)

  • ==Specific software==Relevant network sources (Nginx, MySQL, Zabbix, etc.)

4. Local yum source backup (important)

Step 1: Use the cd command to switch to the /etc/yum.repos.d directory

# cd /etc/yum.repos.d/

Step 2: Back up all warehouse files

# tar -zcf repo.tar.gz *.repo

Step 3: Delete all warehouse files ending with .repo

# rm -rf *.repo

3. Local YUM source configuration

1. Local YUM configuration

① Use the CD image as the YUM source repository

② Download a lot of software and use the software package as a YUM source repository

2. Use the CD image as the YUM source repository

Step 1: Install the CD image of the CentOS7.6 system in the VMware system

Step 2: Mount the CD to a directory

# cd ~
?
#rm -rf /mnt/*
# mount -o ro /dev/sr0 /mnt
Option description:
-o: Mounting mode, ro means mounting in readonly=>read-only mode
              rw represents mounting in read/write=>read-write mode
#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
  ├─centos-root 253:0 0 17G 0 lvm /
  └─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 4.3G 0 rom /mnt

To uninstall or demount, use umount /mnt

Step 3: Add the CD mount to the boot file

# chmod + x /etc/rc.local
# echo 'mount -o ro /dev/sr0 /mnt' >> /etc/rc.local

/etc/rc.local is the system startup file. After the system starts, this file will be automatically loaded and executed.

Step 4: Write local YUM warehouse file

# cd /etc/yum.repos.d/
Create a file ending with *.repo with any name
# vim local.repo
[local]
name=localyum
baseurl=file:///mnt
gpgcheck=0
enabled=1
# yum clean all
# yum makecache
# yum repolist all
?
Note: file://local protocol path, followed by the specific path of the warehouse

Standard format of yum repository

[Warehouse ID name], the name is arbitrary, you can have multiple IDs in one file

name=warehouse name

baseurl=path to the warehouse, supports multiple formats, file://local path, ftp://, http:// or https://

gpgcheck=gpg key, the value can be 0 (representing no detection), 1 (representing detection, if it is 1, a gpgkey=key connection must be defined below)

enabled=Whether to start the current warehouse, the value can be 0 or 1, the default is 1, which means starting the warehouse

Step 5: Test whether the local YUM warehouse is available

# yum install httpd -y

3. Extended man 5

In the Linux system, given a configuration file, how to query the role of each option in this file?

# man command

Extension: man 5 configuration file name

# man 5 yum.conf

4. Network YUM source configuration

1. Classification of network YUM sources

① Use YUM sources from relatively well-known platforms (Alibaba Cloud, Tencent, Tsinghua)

② Some specific software (such as Nginx, MySQL, Zabbix, etc.) need to customize the network YUM source according to the official website documents

2. Use YUM sources from well-known platforms

Alibaba Source: Alibaba Open Source Mirror Station-OPSX Mirror Station-Alibaba Cloud Developer Community

NetEase source: Welcome to NetEase open source mirror site

Sohu source: Index of /

Tsinghua Source: Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

Tencent source, Huawei source…

Baidu search => Huawei mirror mirror source

Case: Configuring Alibaba Cloud’s yum source

Step 1: Baidu, search for the YUM source you want, enter the official website, and find CentOS

Step 2: Configure Alibaba Cloud’s YUM source according to the official website prompts

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
?
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
?
# yum clean all
# yum makecache

3. Extension: EPEL source configuration

What is an EPEL source?

Answer: EPEL is an extension of the official website source.

CentOS-Base.repo file => Basic source (official YUM source)

epel.repo file => extension source, a supplement to the official YUM source

# yum install epel-release -y

For example: the running train is in the epel source

# yum install sl -y
# sl

4. YUM source configuration for specific software

For example, several special software, such as Nginx, MySQL, Zabbix

Nginx: nginx news

MySQL: MySQL

Zabbix: Zabbix :: The Enterprise-Class Open Source Network Monitoring Solution

Find the official document and write the YUM source configuration into the following file (repo file)

# cd /etc/yum.repos.d
# vim nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

Clear cache:

# yum clean all
# yum makecache

Install Nginx:

# yum install nginx -y

5. Build your own YUM source warehouse

1. Cache installation package

When is caching software needed?

  • You need to install the same version of the package next time

  • Due to network reasons, the network installation is very slow. Cache the software package and configure the local warehouse.

2. How to cache software installation packages

# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever defines the cache path of the software package
keepcache=1 1 turns on caching; 0 turns off
debuglevel=2
logfile=/var/log/yum.log
...

3. Download all software and dependent software to a certain path

Only download without installing software:

# yum install --downloadonly --downloaddir=save path software name

Case: Download samba software and dependent software

# mkdir /soft
# yum install --downloadonly --downloaddir=/soft samba

4. Customized YUM warehouse

Step 1: Install the createrepo software for making warehouses in the system

# yum install createrepo -y

Step 2: Make the /soft folder into a local self-built warehouse

# createrepo /soft

Step 3: Create a soft.repo warehouse in the /etc/yum.repos.d directory

# cd /etc/yum.repos.d/
# vim soft.repo
[soft]
name=softyum
baseurl=file:///soft
gpgcheck=0
enabled=1

Clean cache + rebuild cache:

# yum clean all
# yum makecache