Linux and Shell Programming

0 of 30 lessons complete (0%)

Module 4 Software Management

Implementing a Server Own Package

Setting Up a Local Package Repository

Creating Repository Directory Structure:

  • To create a local repository, start by creating a directory structure. For example, on CentOS, you can do this as follows:
sudo mkdir -p /var/www/html/repos/centos/8/updates/x86_64/Packages

This creates the necessary directory structure to host your packages.

Populating the Repository:

  • Once the structure is in place, you can copy your packages into the appropriate directories. For example:
sudo cp /path/to/your/packages/*.rpm /var/www/html/repos/centos/8/updates/x86_64/Packages/

This command copies all .rpm packages to the repository.

Repository Configuration:

  • Next, you need to configure your system to recognize the local repository. Edit the repository configuration file, for example:
sudo nano /etc/yum.repos.d/local.repo

Add the following lines:

[local] name=Local Repository baseurl=file:///var/www/html/repos/centos/8/updates/x86_64/ enabled=1 gpgcheck=0

This sets up a local repository called “Local Repository” using the directory structure we created earlier.

Configuring Package Management for Custom Repositories

Adding Custom Repositories:

  • Open the repository configuration file, for example:
sudo nano /etc/yum.repos.d/local.repo

Add the following lines to include your custom repository:

[local] name=Local Repository baseurl=file:///var/www/html/repos/centos/8/updates/x86_64/ enabled=1 gpgcheck=0

Prioritizing Repositories:

  • If you have multiple repositories configured, you can set priorities. Install the yum-plugin-priorities package:
sudo yum install yum-plugin-priorities

Then, edit the priority of your custom repository in the repository configuration file.

sudo nano /etc/yum.repos.d/local.repo

Add:

priority=1

This gives your local repository the highest priority.

Automating Repository Maintenance

Updating Packages:

  • To update packages in your local repository, you can use a script that checks for new versions and adds them to the repository. For example, a script could look like this:
#!/bin/bash cp /path/to/new/packages/*.rpm /var/www/html/repos/centos/8/updates/x86_64/Packages/

Managing Metadata:

  • To update repository metadata, you can use the createrepo tool. For example:
sudo createrepo /var/www/html/repos/centos/8/updates/x86_64/

This command updates the metadata for your repository.

These commands and steps demonstrate how to set up and manage a local package repository on CentOS for custom packages. Remember to adapt paths and repository names according to your specific setup.