DEV Community

Zheng Zengtao
Zheng Zengtao

Posted on

Building a Private Repository

In the architecture of cloud services, multiple network planes are generally deployed, and the management plane is usually in the intranet environment, accessible through a jump server or VPN technology. This brings significant inconvenience to the installation, upgrade, or system upgrade of applications for the infrastructure of the server. Today, I will introduce a simple method to build a self-built Linux private repository.

Before we begin, you need to prepare a virtual host with dual network cards, or a physical host will work as well. The host should run the Linux operating system; here, we'll use CentOS 7.9 as an example. If you are using a Debian-based Linux system, just replace the commands with apt commands; the principle is exactly the same.

Once the system is installed, connect one network card to the external network and another to the intranet, complete the relevant configurations and tests. Now let's officially start building the private repository.

Step 1: Install and Configure Nginx

Install Nginx

sudo yum install -y nginx
Enter fullscreen mode Exit fullscreen mode

This is a basic operation, and installing Nginx may require additional steps, such as installing the EPEL repository. If you encounter any issues installing Nginx, please search online for related tutorials.

Configure Nginx

Configuring Nginx is straightforward. Just add three lines under the server section:

vim /etc/nginx/nginx.conf
Enter fullscreen mode Exit fullscreen mode
    server {
        autoindex on;    # Add this line
        autoindex_exact_size on;    # Add this line
        autoindex_localtime on;    # Add this line
        listen       80;    # Listening port
Enter fullscreen mode Exit fullscreen mode

Then restart Nginx:

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Directory for Sync

This directory is configured in the /etc/nginx/nginx.conf file from the previous step. Here, we create it in the default working directory of Nginx:

mkdir -p /usr/share/nginx/html/rsync/
Enter fullscreen mode Exit fullscreen mode

Step 3: Download Sources

You can download applications individually or synchronize downloads in batches.

Download a Single Application

As an example, let's download haproxy:

mkdir -p /usr/share/nginx/html/rsync/haproxy
sudo yum -y install --downloadonly --downloaddir=/usr/share/nginx/html/rsync/haproxy/ haproxy
Enter fullscreen mode Exit fullscreen mode

Note: This method downloads only applications that have not been installed on the local machine before. If you try to download an application that has been previously installed, such as nginx, you will get nothing.

Batch Download

Here we use the EPEL repository as an example:

mkdir -p /usr/share/nginx/html/rsync/epel/7/x86_64/
rsync -vrt --bwlimit=3000 --exclude=debug/ rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64/ /usr/share/nginx/html/rsync/epel/7/x86_64/
Enter fullscreen mode Exit fullscreen mode

Create an Index

When creating the index for the first time, install createrepo:

sudo yum install -y createrepo
Enter fullscreen mode Exit fullscreen mode

Create the index; you need to use this command every time you update the content.

createrepo /usr/share/nginx/html/rsync/
Enter fullscreen mode Exit fullscreen mode

Usage

After these steps, the sync source is successfully installed. On the intranet host, modify the repo file's baseurl:

baseurl = http://xxx.xxx.xxx.xxx/rsync
Enter fullscreen mode Exit fullscreen mode

Alternatively, transfer it to the relevant host and install using the following command:

sudo yum install -y http://xxx.xxx.xxx.xxx/rsync/haproxy/haproxy-1.5.18-9.el7_9.1.x86_64.rpm
Enter fullscreen mode Exit fullscreen mode

Top comments (0)