This article contains the following topics:
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 22.04.4 LTS (Jammy Jellyfish) |
Software | Apache http 2.x, apt-mirror |
Other | Privileged access to your Linux system as root or via the sudo command, Minimum 600 GB of disk space for the repository(allocate 550 GB for /var mount path). Local repository storage requirements are based on the number of endpoints connecting to the repo. |
STEP 1 : Setting Up the Ubuntu Local Repository
1. Install the Apache HTTP Server with the following command:
sudo apt install apache2
2 Ensure that the service runs at startup:
sudo systemctl enable apache2
3. After you have checked the service is working as expected move to the default DocumentRoot Directory :
cd /var/www/html
4. Created the ubuntu sub directory
sudo mkdir -p /var/www/html/ubuntu
5. Assign the directory to the appropriate owner , in this case www-data ( the user under which Apache HTTP runs )
sudo chown www-data:www-data /var/www/html/ubuntu
6. Install the main tool which allows you to create a local repository - 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/mirro.list
10. Uncomment the lines you would like to get packages from. For example, if you would like to sync with deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse then 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 the 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 in background simply execute the command:
nohup sudo apt-mirror &
To monitor the mirroring progress use below,
tail nohup.out
Great, the above output confirms that the mirroring is completed.
Check the overview of your filesystem's disk space usage using below command
Df -hT
In Ubuntu 22.04, there are some issues noticed with apt-mirror command like it does not mirror CNF folder, icon tar files and binary-i386, so to fix these issues, create a script with following content and execute it.
Command to create the script
vi fix-errors.sh
#!/bin/bash
# Set the base directory
base_dir="/var/www/html/ubuntu/mirror/archive.ubuntu.com/ubuntu/dists"
# Change to the base directory
cd $base_dir
# Download dep11 icons
for dist in jammy jammy-updates jammy-security jammy-backports; do
for comp in main multiverse universe; do
for size in 48 64 128; do
wget http://archive.ubuntu.com/ubuntu/dists/$dist/$comp/dep11/icons-${size}x${size}@2.tar.gz -O $dist/$comp/dep11/icons-${size}x${size}@2.tar.gz
done
done
done
# Change to /var/tmp directory
cd /var/tmp
# Download commands and binaries
for p in "${1:-jammy}"{,-{security,updates,backports}}/{main,restricted,universe,multiverse}; do
>&2 echo "${p}"
wget -q -c -r -np -R "index.html*" "http://archive.ubuntu.com/ubuntu/dists/${p}/cnf/Commands-amd64.xz"
wget -q -c -r -np -R "index.html*" "http://archive.ubuntu.com/ubuntu/dists/${p}/cnf/Commands-i386.xz"
wget -q -c -r -np -R "index.html*" "http://archive.ubuntu.com/ubuntu/dists/${p}/binary-i386/"
done
# Copy the downloaded files to the appropriate location
sudo cp -av archive.ubuntu.com/ubuntu/ /var/www/html/ubuntu/mirror/archive.ubuntu.com
save and close the file.
Make the script executable using below command
sudo chmod +x fix-errors.sh
Run the script using below command
sudo bash fix-errors.sh
Note: We need to execute the above script only once.
Creating the Symbolic Link
Next create the following symbolic link so that you can access the repository over the browser as well.
1.Verify the Path
ls -l /var/www/html/ubuntu/mirror/archive.ubuntu.com
2.Create the symbolic link
sudo ln -s /var/www/html/ubuntu/mirror/archive.ubuntu.com /var/spool/apt-mirror/mirror/archive.ubuntu.com
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.
Access Local APT Repository Using Web browser
In case Firewall is running on your Ubuntu system then allow port 80 using following command
sudo ufw allow 80
Now, try to access locally configured apt repository using web browser, type the following URL:
http://<Server-IP>/ubuntu/mirror/archive.ubuntu.com/ubuntu/dists/
STEP 3: Setting Up Client Servers
1. SSH your client server
2. Go to the path cd /etc/apt/
3. Configure the local repository by executing the below command
sed -i 's|archive\.ubuntu\.com/ubuntu|30.30.4.108/ubuntu/mirror/archive.ubuntu.com/ubuntu/|g' sources.list
Note:
1.Replace 30.30.4.108 with your mirror server IP
2.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.
Now run ‘apt update’ command to verify that client machine is getting update from our local apt repository server,
sudo apt update
You're all set !
Comments
0 comments
Please sign in to leave a comment.