This article will show you how to setup an Ubuntu Local Repository in order to retrieve all relevant packages for you client servers.
Please note that the instructions below are for setting up local repositories and are not related to JetPatch functionality.
In this tutorial you will learn
- How to setup the local repository
- How to configure the Linux client servers to use the Local Repository.
Software and Hardware requirements
System | Ubuntu 18.04.2 (Bionic Beaver) LTS |
Software | Apache http 2.x, apt-mirror |
Other | Privileged access to your Linux system as root or via the sudo command, Minimum 200 GB of disk space for the repository. Local repository storage requirements are based on the number of endpoints connecting to the repo. |
Conventions | # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ - requires given linux commands to be executed as a regular non-privileged user |
STEP 1 : Setting Up the Ubuntu Local Repository
1. Install the Apache HTTP Server which is under the package named apache2
, with the following command:
$ sudo apt install apache2
$ sudo systemctl enable apache2
$ cd /var/www/html
$ sudo mkdir -p /var/www/html/ubuntu
www-data
( the user under which Apache HTTP runs ).$ sudo chown www-data:www-data /var/www/html/ubuntu
apt-mirror
, :$ sudo apt install apt-mirror
7. If the apt-mirror package is not found refresh your package list with the following command (and then repeat step 6
$ sudo apt update
Now, it's time to select which repositories to mirror the local - repo server.
8. Make a backup copy of the mirror.list configuration file
$ sudo cp /etc/apt/mirror.list /etc/apt/mirror.list.org
9. Edit the config file using vi or nano and change the base_path to the default document root we have created earlier (/var/www/html/ubuntu)
$ vi /etc/apt/mirror.list
10. Unmark the lines you would like to get packages from. For example, if you would like to sync with var than erase the # symbol from the line.
11. Copy a script into /var/www/html/ubuntu/var/
$ sudo mkdir -p /var/www/html/ubuntu/var $ sudo cp /var/spool/apt-mirror/var/postmirror.sh /var/www/html/ubuntu/var/
12. Remove the existing "deb sources" examples in the mirror.list configuration file and replace the with the "Deb sources" from /etc/apt/sources.list
Create local Mirrors
Now is time to create a local mirror, keep in mind that an initial mirroring can take many hours and will probably slow down your connection. Our suggestion is to run this at night / during the weekend.
13. To start mirroring the remote repos packages to the local server simply execute the command:
$ sudo apt-mirror
Once the clean.sh and postmirror.sh scripts are executed, the mirroring process has been completed!
STEP 2: Setup CronJob to update your repositories
Now that you've created a local repository, it's important to keep it updated with all new packages. In order to do so, we will configure a sync process by using cron scheduler.
$ sudo crontab -e
Now, edit the crontab and add the following line
00 03 * * * /usr/bin/apt-mirror
Since the sync process might take some time and resources, we might want to run it at night. Hence, this line is configured to run at 3AM. (You can easily change the numbers and do it whenever you want).
Save and Exit.
STEP 3: Setting Up Client Servers
1. SSH your client server
2. Configure the local repository list by editing the sources.list configuration file.
$ vi /etc/apt/sources.list
3. Specify the local repo we have created in step 1 and disable any remote one by commenting the lines. Please Note: If you do not comment the remote repos a "Release file has not been found" might occur while running the command apt update on the client.
4. Replace any string archive.ubuntu.com with our local mirror IP.
$ sudo sed -i.bak0 "s/archive\.ubuntu\.com/10\.10\.0\.42/g" /etc/apt/sources.list
This command will create the backup file /etc/apt/sources.list.bak0
and replace any archive.ubuntu.com
string with 10.0.0.42
. A further adjustment is running again sed in this way:
$ sudo sed -i.bak1 "s/ubuntu/ubuntu\/mirror\/archive\.ubuntu\.com\/ubuntu/g" /etc/apt/sources.list
This command will create the backup file /etc/apt/sources.list.bak1
and replace any ubuntu
string with ubuntu/mirror/archive.ubuntu.com/ubuntu
. A further adjustment is running again sed in this way.
This is necessary as apt-mirror appends the path mirror/archive.ubuntu.com/ubuntu
to our base path. Here it will be created a further backup file
/etc/apt/sources.list.bak1.
Note: For the purpose of this tutorial we are only mirroring packages or repositories from archive.ubuntu.com; of course you can add other unofficial repositories in the mirror.list file in the server, but then you have to re-run apt-mirror there and edit on any client the sources.list file accordingly.
Update local repository index:
Make sure the port 80 is not blocked by the client firewall and then you can run:
$ sudo apt update
You're all set !
Comments
0 comments
Please sign in to leave a comment.