Configure yum server in redhat intranet environment

Foreword:

In a production environment, all servers are generally not allowed to access the public network. The ideal situation is to have several servers acting as access proxies and also as cache servers. When the required package is available in the server, it is obtained through the intranet. If not, it is obtained through the public network and saved locally. (The mirror is built with yum source and version compatibility is the best)
The commonly used method to build a private yum source is createrepo to generate a local warehouse.

Local sources are generally used for intranet machines. When there are a large number of machines, it is more convenient to have a self-built source for batch updates or when the public network cannot be accessed. For example, if you upgrade a thousand servers at the same time, if you use the public network , your network administrator wants to beat you to death. To install software on each server, you must first upload the installation disk and then configure the local yum service, which is troublesome and time-consuming. You can install the yum service on a Linux server on the intranet, and then other servers can directly modify the repo file to use the yum service. The installation steps are as follows:

Reference documentation:
[Selected] Build local yum source in Linux (only offline yum warehouse in intranet environment)_Linux cannot be updated through the public network, how to use offline yum library to upload to offline liunx-CSDN blog icon-default.png?t=N7T8https://blog.csdn.net/weixin_43404595/article/details/117964034

1.RHEL version

[root@oracle ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)

Server: 192.168.134.205
Client: 192.168.134.208

Build server local YUM:

1. Upload the reht installation CD file to the home directory and name it rhel.iso

That is, upload the system image file to the specified directory on the server through MobaXterm (you can find this directory later, I chose the /home directory, as shown in the picture)

2. Create directory /home/rhel/

mkdir /home/rhel/

3. Mount the system image to the /mnt directory and check whether the mounting is successful
  1. cd /home #switch user
  2. mount -o loop /home/rhel-server-7.9-x86_64-dvd.iso /home/rhel
  3. df-h

After restarting, it will become invalid. You can set it to mount automatically at boot.

  1. Open a terminal or command line interface and log in to the system as root or a user with sudo privileges.

  2. Use a text editor to create a new script file, such as mount_iso.sh:

    sudo vi /etc/init.d/mount_iso.sh
    
  3. Copy and paste the following into the script file:

    #!/bin/bash
    
    # Define the image file and target mounting directory
    ISO_FILE="/home/rhel-server-7.9-x86_64-dvd.iso"
    MOUNT_DIR="/home/rhel"
    
    # Check whether the mounting directory exists, if not, create it
    if [ ! -d "$MOUNT_DIR" ]; then
        mkdir "$MOUNT_DIR"
    fi
    
    # Mount image file
    mount -o loop "$ISO_FILE" "$MOUNT_DIR"
    

    Please make sure to replace the paths of ISO_FILE and MOUNT_DIR with the correct image file and target mount directory paths.

  4. :wq saves and closes the file.

  5. Next, make the script executable:

    sudo chmod + x /etc/init.d/mount_iso.sh
    
  6. Add the script to the startup process using the following command:

    sudo ln -s /etc/init.d/mount_iso.sh /etc/rc.d/rc.local
    sudo chmod +x /etc/rc.d/rc.local
    

    This will execute the /etc/init.d/mount_iso.sh script every time the system boots.

  7. Finally, restart the system to verify whether the script successfully mounted the image file.

Also possible:

Add it directly during the startup process

Install the FTP service (generally, this service will be available directly after installing the system, so write as follows)

1. Execute the installation command

 yum install vsftpd*

2. After the installation is complete, copy all files in the /home/rhel/ directory to the /var/ftp/pub directory

cd /home/rhel
cp -rv */var/ftp/pub

3. Switch to the /var/ftp/pub directory

Delete *.html
Delete CentOS/repodata/TRANS.TBL
cd /var/ftp/pub
rm -rf *.html

rm -rf repodata/TRANS.TBL

Install the createrepo tool and generate YUM universal database

1. Install createrepo

1. yum -y install createrepo#Download createrepo
2.createrepo -g /var/ftp/pub/repodata/3df90817a193baef023d53222cc4ce8f4d15209e593bee361bf72016022008fb-comps-Server.x86_64.xml /var/ftp/pub

Note: The name of 3df90817a193baef023d53222cc4ce8f4d15209e593bee361bf72016022008fb-comps-Server.x86_64.xml may be different in each system. Just make sure it is followed by comps-rhel6-Server.xml.

Client yum configuration

First turn off the firewall
  1. Log in to the Red Hat system with administrator privileges.

  2. Open a terminal or command line interface.

  3. Enter the following command to stop the firewall service:

    sudo systemctl stop firewalld
    
  4. Enter the following command to disable automatic startup of the firewall service:

    sudo systemctl disable firewalld
    

    This will ensure that the firewall service does not start automatically the next time the system boots.

  5. Finally, you can verify that the firewall service was successfully stopped and disabled. Enter the following command:

    sudo systemctl status firewalld
    

    If the output shows the firewall service as “inactive”, the firewall has been shut down successfully.

Enter the /etc/yum.repos.d/ directory, back up the original repo file, and create a new repo file, rhel.repo
  1. cd /etc/yum.repos.d/
  2. mkdir bak/
  3. cp*bak/
  4. vi rhel.repo
[redhut7] //Warehouse description (customizable)
name=redhut //Description of the software source (consistent with the above)
baseurl=ftp://192.168.134.208/pub/ //The mounting address of the image file:// --Format
gpgcheck=0 //Do not check gpgkey
enabled=1 //This yum source statement block takes effect immediately

baseurl=ftp://192.168.134.208/pub/ The baseurl here is the address of your server. Set it according to your own situation.

Execute after saving rhel.repo
  1. yum clean all
  2. yum update
  3. yum makecache
Encountered a problem:

This error message indicates that another application (yum) is currently holding the yum lock and is accessing the package manager. You can try the following methods to resolve this issue:

  1. Wait for a while: According to the error message, the application has been running for a while and may be performing some tasks. You can wait for some time for the application to complete its operation and release the yum lock. Normally, it will be released automatically after a period of time.

  2. End related processes: If waiting for too long has no effect, you can try to manually terminate related processes. The yum process can be found and killed using the following command:

    sudo pkill yum
    

    Please note that doing so may cause unfinished package operations to be interrupted, so make sure you back up important data before proceeding and ensure that aborting the process will not negatively impact the stability and security of the system.

  3. Delete the yum lock file: If the above method still does not work, you can try to delete the yum lock file manually. Run the following command to find and delete the yum lock file:

    sudo rm /var/run/yum.pid
    

    After deleting the lock file, you can try re-running the yum command to see if the problem has been resolved.

Question 2:

Restarting the ftp on the server side can solve the problem:

  • If you are using vsftpd (Very Secure FTP Daemon) server, you can use the following command to restart the service:

    sudo systemctl restart vsftpd

Construction completed

Commonly used yum commands

1.Installation

yum install package installs the specified installation package package1
yum localinstall package local installation package

2.Update and upgrade

yum update all updates
yum update package updates the specified package package
yum check-update checks for updateable programs

3. Search and display

yum info displays installation package information
yum list displays all installed and installable packages
yum list displays the installation status of the specified package
yum search to find software packages

4. Delete program

yum remove | erase package1 delete package
yum will store the downloaded software packages and headers in the cache and will not delete them automatically. If we feel that they are taking up disk space, we can use the yum clean command to clear them.
yum clean headers clear headers
yum clean packages clears downloaded rpm packages
yum clean all clears headers and rpm packages