[LINUX] Set up a yum repository server on CentOS7 system and refer to it locally and from other servers.

Introduction

I don't think there are many other articles like this that are commonplace. I don't know if anyone has a local yum repository at this time, Since I recently built my own rpm distribution server, In addition to the memo of the contents at that time, I decided to participate in Linux Advent Calender 2019.

In addition, I will omit the details of building the repository public part on the Web for the time being, so Please use apache, nginx, etc. to set the repository folder to be public. The contents are beginner level contents. It's easy to create.

This environment

Get ready to create a repository

Install the create repo package to create the repository.

# yum install createrepo

The following packages are also installed as dependencies.

deltarpm
python-deltarpm

Click here for the version of create repo installed this time

[[email protected] ~]# rpm -qa | fgrep createrepo
createrepo-0.9.9-28.el7.noarch
[[email protected] ~]#

Let's create a repository

Preparation

First, consider the area where you want to create the repository database. Considering the disk size, I think it is recommended to create a place.

If it is an on-premise server, it is an area with many disk balls. Or if it is AWS etc., it may be good to insert an additional area. Apart from that, I think that there is no problem if I / O is not used locally, so it is your own policy.

Create a directory

This time, we will secure the area below. /var/yum-repo

In addition, this time it will be possible to publish for multiple CentOS versions I will also try the following policy.

/ var / yum-repo / centos / [CentOS version number] / rpms

If you want to divide by architecture, you can use x86_64 after CentOS version number. I think it would be better to divide by noarch etc. (If you do rpmbuild, rpm will be created in arch hierarchy units, so that seems to be good)

Actually place the rpm

For example, if you have rebuilt it yourself, put it down.

This time, I will use it as a sample by dropping the rpm from the CentOS-Base repository. It is convenient to use # yumdownloader [package name] etc. when downloading rpm. This time, we will use the wget rpm, which is easy to understand and has no dependencies.

[[email protected] rpms]# ls -ltr
total 548
-rw-r--r-- 1 root root 560272 May 17 00:48 wget-1.14-18.el7_6.1.x86_64.rpm
[[email protected] rpms]#

Create repository metadata information

Finally, the createrpo command comes into play.

Since the rpm file information in the directory under the specified scan is imported, I think it will take some time depending on the number. This time it was one, so it was completed immediately.

# createrepo -d [hierarchy to create metadata]

[[email protected] 7]# pwd
/var/yum-repo/centos/7

[[email protected] 7]# createrepo -d ./
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] 7]#

If you perform create repo, repo data will be created under the directory specified by the argument. The rpm information under the directory specified by the argument is fetched. The xml related information is stored as follows.

[[email protected] 7]# ls -ltr
total 4
drwxr-xr-x 2 root root   45 Nov  8 19:41 rpms
drwxr-xr-x 2 root root 4096 Nov  8 19:43 repodata
[[email protected] 7]# cd repodata/
[[email protected] repodata]# ls -ltr
total 28
-rw-r--r-- 1 root root 1139 Nov  8 19:43 dedbecb0ef25ebe6b8646e2589dc48e9a2adb34d1d6a677eed9e100ad2cbca54-primary.xml.gz
-rw-r--r-- 1 root root  523 Nov  8 19:43 29d912df4c348eba529c6a9845827f02a8160c094ab0da8892a398fab70c27e0-filelists.xml.gz
-rw-r--r-- 1 root root  893 Nov  8 19:43 b7d1045f4692acfa996b581a68c9483103e0c4edd5b14ae96e92640aeaa68351-other.xml.gz
-rw-r--r-- 1 root root 1512 Nov  8 19:43 d9410596837121203e82f0dabbf83afc8d467d16b15d73c8436bdcfac86db0d6-other.sqlite.bz2
-rw-r--r-- 1 root root 1880 Nov  8 19:43 b80afe3ab58edef03d0043b69da54e041574ee17f3e717ef53d04926194cc67b-filelists.sqlite.bz2
-rw-r--r-- 1 root root 2620 Nov  8 19:43 dc35f95c517d1b9014fa0b21d80be4c28483bfab6dac993443ba195dd232d07a-primary.sqlite.bz2
-rw-r--r-- 1 root root 2969 Nov  8 19:43 repomd.xml
[[email protected] repodata]#

This completes the metadata creation.

If you go with this repository creation policy, I think that you created directories for each version of CentOS, so If you have a CentOS 6 version, please do create repo there as well.

Yum.conf settings for each client server

Local server edition

I'm a little wondering if it needs to be used on a local server, but it can be read by creating a yum repository file like the one below.

Set
[[email protected] yum.repos.d]# pwd
/etc/yum.repos.d
[[email protected] yum.repos.d]#
[[email protected] yum.repos.d]# vim local.repo
[local-repo]
enabled=0
name= local-repo of the year.
baseurl=file:///var/yum-repo/centos/$releasever
[[email protected] yum.repos.d]#

Specify the local file path (the hierarchy where the metadata exists) for the baseurl part. Also, if you use $ releasever, the Major version of the OS will be assigned. Probably it is used in CentOS-Base repository etc., so I think that it is understood somehow. You can check the details of the details in man yum.conf. By the way, since ʻenabled = 0`, it is not normally read.

See the repository

I have set up for local reference under yum.repos.d, so let's check if it can be read.

Since it is troublesome to change the valid flags of other Base repositories etc. on the file, Disable other than the repository added this time with a wildcard on the yum command, Only enable the name of the repository you created and make sure you have a repository reference.

[[email protected] 7]# yum --disablerepo=* --enablerepo=local-repo repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                    repo name                                                              status
local-repo/7                                               local-repo of the year.                                                1
repolist: 1
[[email protected] 7]#

I was able to confirm that there is only one package that is safely referenced and managed.

If you want to install and check it, you can also install it.

[[email protected] 7]# yum --disablerepo=* --enablerepo=local-repo install wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
local-repo                                                                                                       | 2.9 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================
 Package                    Arch                         Version                                 Repository                        Size
========================================================================================================================================
Installing:
 wget                       x86_64                       1.14-18.el7_6.1                         local-repo                       547 k

Transaction Summary
========================================================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Is this ok [y/d/N]:

Remote server edition

And for remote references. Basically, just set the repository information in the client you want to refer to the created repository in the same way as the local reference.

Publish the repository

First, publish the repository directory on the Web on the server where you created the repository earlier so that you can refer to it remotely. Please use whatever you like, such as apache or nginx.

As mentioned at the beginning, the procedure here is omitted. Screen Shot 2019-11-08 at 20.10.17.png

Set yum on the client side

It is a setting that feels like it was set locally.

[[email protected] ~]# cat /etc/yum.repos.d/local.repo
[local-repo]
enabled=0
name= local-repo of the year.
baseurl=http://[Public web address]/centos/$releasever
[[email protected] ~]#

Also check if the repository can be read here as well.

[[email protected] ~]# yum --disablerepo=* --enablerepo=local-repo repolist
Loaded plugin:fastestmirror
Loading mirror speeds from cached hostfile
local-repo                                                                                                       | 2.9 kB  00:00:00
local-repo/7/primary_db                                                                                          | 2.6 kB  00:00:00
Repository ID Repository name Status
local-repo/7                                                  local-repo of the year.                                               1
repolist: 1
[[email protected] ~]#

I was able to refer to it remotely!

Finally, let's install wget.

[[email protected] ~]# yum --disablerepo=* --enablerepo=local-repo install wget
Loaded plugin:fastestmirror
Loading mirror speeds from cached hostfile
Resolving dependencies
-->Performing transaction confirmation.
--->Package wget.x86_64 0:1.14-18.el7_6.Install 1
-->Dependency resolution finished.

Resolved the dependency

========================================================================================================================================
Package architecture version repository capacity
========================================================================================================================================
During installation:
 wget                       x86_64                       1.14-18.el7_6.1                         local-repo                       547 k

Transaction summary
========================================================================================================================================
Installation 1 package

Total download capacity: 547 k
Installation capacity: 2.0 M
Is this ok [y/d/N]: y
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                                                                  | 547 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
During installation: wget-1.14-18.el7_6.1.x86_64                                                                             1/1
During verification: wget-1.14-18.el7_6.1.x86_64                                                                             1/1

Installation:
  wget.x86_64 0:1.14-18.el7_6.1

Has completed!
[[email protected] ~]#

Add packages to reflect information in the database

If you want to add the package to the repository, you need to update it.

# createrepo --update ./
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 1 pkgs
Spawning worker 2 with 1 pkgs
Spawning worker 3 with 1 pkgs
Spawning worker 4 with 1 pkgs
Spawning worker 5 with 0 pkgs
Spawning worker 6 with 0 pkgs
Spawning worker 7 with 0 pkgs
Spawning worker 8 with 0 pkgs
Spawning worker 9 with 0 pkgs
Spawning worker 10 with 0 pkgs
Spawning worker 11 with 0 pkgs
Spawning worker 12 with 0 pkgs
Spawning worker 13 with 0 pkgs
Spawning worker 14 with 0 pkgs
Spawning worker 15 with 0 pkgs
Spawning worker 16 with 0 pkgs
Spawning worker 17 with 0 pkgs
Spawning worker 18 with 0 pkgs
Spawning worker 19 with 0 pkgs
Spawning worker 20 with 0 pkgs
Spawning worker 21 with 0 pkgs
Spawning worker 22 with 0 pkgs
Spawning worker 23 with 0 pkgs
Spawning worker 24 with 0 pkgs
Spawning worker 25 with 0 pkgs
Spawning worker 26 with 0 pkgs
Spawning worker 27 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
#

at the end

――If you are creating your own build or need to publish it in-house, you can easily create it, so let's do it. --It seems that you can refer to the repository of git as long as you can read the metadata (although it seems to be a load)

Recommended Posts

Set up a yum repository server on CentOS7 system and refer to it locally and from other servers.
From installing Flask on CentOS to making it a service with Nginx and uWSGI
I want to pass an argument to a python function and execute it from PHP on a web server
How to set up a local development server
I set up TensowFlow and was addicted to it, so make a note
Set up a simple local server on your Mac
Set up a file server on Ubuntu 20.04 using Samba
Set up a free server on AWS in 30 minutes
[Part 1] Let's set up a Minecraft server on Linux
When it is troublesome to set up an SMTP server locally when sending mail with Python.
How to set up WSL2 on Windows 10 and create a study environment for Linux commands
How to set up a simple SMTP server that can be tested locally in Python
I made a server with Python socket and ssl and tried to access it from a browser
Steps to set up Pipenv, create a CRUD app with Flask, and containerize it with Docker
Set up a web server with CentOS7 + Anaconda + Django + Apache
Setting up a CentOS 7 server hosted on Alibaba Cloud ECS
Install mecab on Sakura shared server and call it from python
Set up Ubuntu as a Linux cheat sheet and https server
Set up a node to do MNIST on ROS using Tensorflow
Everything from building a Python environment to running it on Windows
Set up a dummy SMTP server in Python and check the operation of sending from Action Mailer
Introduction and usage of Python bottle ・ Try to set up a simple web server with login function
Set up Python environment on CentOS
A story about trying to run JavaScripthon on Windows and giving up.
Set up a Lambda function and let it work with S3 events!
How to set up a jupyter notebook on ssh destination (AWS EC2)
Set up reverse proxy to https server with CentOS Linux 8 + Apache mod_ssl
A story about a beginner trying hard to set up CentOS 8 (procedure memo)
Start the webcam to take a still image and save it locally
[python] Send the image captured from the webcam to the server and save it