Menu
Is free
registration
home  /  Multimedia/ Create a local repository from deb packages. Debian - Create local repository (apt-mirror) Ubuntu local repository

We create a local repository of deb packages. Debian - Create local repository (apt-mirror) Ubuntu local repository

Creating a local repository using the apt-mirror utility.
This mirroring method is recommended by WiKi Debian as much more reliable than debmirror.
So let's start, install apt-mirror: apt-get install apt-mirror Create a directory / mnt / repo / debian, in which a local package repository will be created. It is desirable that this is a mounted logical partition of the hard disk, so that in case of reinstalling the distribution kit from scratch, when formatting the root partition (/), it does not lose the repository altogether. And service directories:
mkdir -p / mnt / repo / debian / (mirror, var, skel)
Customization apt-mirror
Let's say we need a mirror with ready-to-install (binary) packages for x64 Wheezy.
() Edit the configuration file /etc/apt/mirror.list: nano /etc/apt/mirror.list ############# config ############### ### # Base directory where a local mirror of the Debian repository will be created set base_path / mnt / repo / debian # # Paths to mirror files, temporary files and execution log apt-mirror # set mirror_path $ base_path / mirror # set skel_path $ base_path / skel # set var_path $ base_path / var # set cleanscript $ var_path / clean.sh # # Architecture for which the mirror is being created. By default, this is the architecture # of the system on which apt-mirror is running (amd64, i386 or others). It is not unnecessary to change, # since below we will explicitly indicate both the mirror and the architecture. # set defaultarch # # Let's go to the post-processing script, the default is absent until we need it. # set postmirror_script $ var_path / postmirror.sh # # Do not run post-processing script set run_postmirror 0 set nthreads 20 set _tilde 0 # ############# end config ########## #### # Mirror with wheezy x64 packages + sources deb-amd64 ftp://debian.nsu.ru/debian wheezy main contrib non-free deb-src ftp://debian.nsu.ru //debian wheezy main contrib non-free # Mirror with wheezy security updates + sources deb-amd64 http://security.debian.org/ wheezy / updates main contrib non-free deb-src http://security.debian.org/ wheezy / updates main contrib non-free # Mirror required for network installation (udebs) deb-amd64 ftp://debian.nsu.ru/debian wheezy main / debian-installer # Remove files not indexed in Release clean ftp: //debian.nsu. ru / debian clean http://security.debian.org # Disable cleaning the selected folder skip-clean ftp://debian.nsu.ru/debian/dists/wheezy/main/installer-amd64/ If you need to keep multiple mirrors for different releases and architectures, then we add new e lines like: # deb-alpha http://ftp.us.debian.org/debian unstable main contrib non-free # deb-amd64 http://ftp.us.debian.org/debian unstable main contrib non-free # deb-armel http://ftp.us.debian.org/debian unstable main contrib non-free # deb-hppa http://ftp.us.debian.org/debian unstable main contrib non-free # deb-i386 http://ftp.us.debian.org/debian unstable main contrib non-free # deb-ia64 http://ftp.us.debian.org/debian unstable main contrib non-free # deb-m68k http: // ftp.us.debian.org/debian unstable main contrib non-free # deb-mips http://ftp.us.debian.org/debian unstable main contrib non-free # deb-mipsel http://ftp.us. debian.org/debian unstable main contrib non-free # deb-powerpc http://ftp.us.debian.org/debian unstable main contrib non-free # deb-s390 http://ftp.us.debian.org/ debian unstable main contrib non-free # deb-sparc http://ftp.us.debian.org/debian unstable main contrib non-free Start and automate apt-mirror
To manually start creating / updating the mirror, run the command:
# apt-mirror After downloading the index files, apt-mirror will tell you how many packages you need to get:
Downloading 47 index files using 20 threads ... Begin time: Wed Jan 8 21:41:11 2014 ... ... ... ... ... ... ... ... .... .. ... ... ... ... ... ... ... ... ... ... ... End time: Wed Jan 8 21:41:33 2014 Proceed indexes: 84.2 GiB will be downloaded into archive. Downloading 90890 archive files using 20 threads ... Begin time: Wed Jan 8 21:41:50 2014 ... ... ... ... All that remains is to wait for the download to complete.
For automatic synchronization and cleaning of mirrors, you need to add a line to the cron settings and set the appropriate time. The official mirrors are updated every 6 hours: 3: 00.9: 00.15: 00.21: 00. For example like this:
crontab -l 05 01 * * * apt-mirror >> /var/log/apt-mirror.log 05 03 * * * /mnt/repo/debian/var/clean.sh >> / var / log / apt-mirror .log Configuring Mirror Access
When finished, local copies of all the specified repositories will be in the / mnt / repo / debianmirror / repository_name directories. Thus, a copy of the repository that was defined in mirror.list as
deb-amd64 ftp://debian.nsu.ru/debian wheezy main contrib non-free
will be in the /mnt/repo/debian/mirror/debian.nsu.ru/debian/ directory. Access to this particular directory should be opened by any Web or FTP server convenient for you. For correct operation it is necessary to add symbolic links "stable", "testing", "unstable" if any ...
ln -s /mnt/repo/debian/mirror/debian.nsu.ru/debian/dists/wheezy /mnt/repo/debian/mirror/debian.nsu.ru/debian/dists/stable Further it is highly advisable to sign the newly created repository

Instead of using dpkg -i package_name.deb to install, you can create a local repository for packages brought in on a USB stick or other medium, and then use synaptic / kynaptic (or apt-get install package_name).

1. All actions are best done as root

sudo su

2.Now install the dpkg-dev package. It will contain the dpkg-scanpackages utility, which is what we need.

apt-get install dpkg-dev

3.Place all .deb packages in a directory, for example, / myrepo (and not directly in this directory, but in subdirectories located in this directory)

4. Execute

cd / myrepo dpkg-scanpackages. / dev / null | gzip -9c> Packages.gz

5. Now you need to add the new repository to /etc/apt/sources.list. Insert a line into /etc/apt/sources.list (it is better to insert closer to the beginning, since apt-get (synaptic / kynaptic) prioritizes the source before the others)

deb file: / myrepo ./

6. Updating the list of repositories

apt-get update

If the contents of the packages directory change, repeat steps 1.4.

In order to be able, if suddenly something happens to the Linux system, not to download the programs again, but to install from what has already been downloaded.

So I thought about how to make it so that we could install these downloaded programs in the most usual way using the command apt-get? Thinking about this, I came to the idea of ​​why not create a local repository from these very packages? Thought, googled, took the main system administrator tool, the admin tambourine, and started doing it.

So the deb packages are in the same place where I left them, before I reinstalled the system as an experiment, namely in the home directory in the folder deb... I have it / home / dante / deb, I described all this, you have the same directory where you saved the packages. Open a terminal and go to the folder with deb packages. In my case, in the terminal, the command looks like this:

cd / home / dante / deb

You must enter the path to your deb packages.
After you went to the folder with the saved deb-packages. Enter the following command:

sudo apt-ftparchive packages ./ | gzip -9> Packages.gz

Next, enter the password and wait until the file is created Packages.gz
Now our repository is practically set, it remains to add it to source.list... We take the terminal back. Opening the file:

sudo nano /etc/apt/sources.list

My given file looks like this:

deb file: /// home / dante / deb ./
# deb cdrom: / oneiric main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu oneiric main restricted
deb-src http://archive.ubuntu.com/ubuntu oneiric restricted main multiverse universe #Added by software-properties

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu oneiric-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu oneiric-updates restricted main multiverse universe #Added by software-properties


## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu oneiric universe
deb http://archive.ubuntu.com/ubuntu oneiric-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free license. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu oneiric multiverse
deb http://archive.ubuntu.com/ubuntu oneiric-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu oneiric-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu oneiric-backports main restricted universe multiverse #Added by software-properties

deb http://archive.ubuntu.com/ubuntu oneiric-security main restricted
deb-src http://archive.ubuntu.com/ubuntu oneiric-security restricted main multiverse universe #Added by software-properties
deb http://archive.ubuntu.com/ubuntu oneiric-security universe
deb http://archive.ubuntu.com/ubuntu oneiric-security multiverse

## Uncomment the following two lines to add software from Canonical "s
## "partner" repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
deb http://archive.canonical.com/ubuntu oneiric partner
deb-src http://archive.canonical.com/ubuntu oneiric partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu oneiric main
deb http://archive.ubuntu.com/ubuntu/ oneiric-proposed restricted main multiverse universe
deb-src http://archive.ubuntu.com/ubuntu/ oneiric-proposed restricted main multiverse universe
deb-src http://extras.ubuntu.com/ubuntu oneiric main

In order to add our folder with deb-packages to the application sources, we need to add the following line.

deb file: /// home / dante / deb ./

It is better to add it to the very top of the file, since the system first queries those repositories that are at the beginning. What I, as you have already seen, I did. Your path to the folder may be different, just do not forget at the end ./

All repository added. You can look at this in the application source. Now all you have to do is update the package lists. This can be done in the terminal using the command:

sudo apt-get update

Now we can install programs from our repository, which we created from the saved deb packages. It is also quite convenient if we downloaded deb packages on one computer and install them on another.

An idle interest arose (it will definitely come in handy, I'm sure, but so far idle), let's say there is a n-th number of machines on Ubuntu, and if there are a lot of them, then the traffic of calls to the repositories of all machines will in fact be directly proportional to their number and if one machine is updated - that's all right, then 20 or more, this is already serious. With unlims for a corporate party in our country, it is bad, so the issue of traffic is often very acute. And it's not worth loading the channel for nothing, when there are simple and elegant solutions.

If you google on this topic, then first of all 2 popular solutions come out: apt-mirror and apt-proxy. Both solutions are attractive in their own way, but since in order to translate all this into a practical plane, one must realize and make a choice, I will briefly describe the features.

Apt-mirror is a package that makes a complete local mirror of the repositories. It is installed, configured, then launched and downloads all the contents of the repositories that you specified in the settings. In principle, good, because all possible packages will be available immediately and at high speed. But on the other hand, we will have to pump out EVERYTHING that is needed and not needed. At least this nuance put an end to the choice of apt-mirror.

Apt-proxy works in a slightly different way, I liked it better. I think the principle is even more intellectual. It does not download everything, but downloads only what was requested, that is, in fact, at the first call, it downloads the required package from the Internet, so you have to wait, and on subsequent calls it gives a local copy of it. In general, repository caching proxying is our choice!

In my hands, for experiments, there were 2 cars. A small, unimportant servo on Debian Squeese and a desktop with Ubuntu 9.10 Karmic. (On debian, I decided to deploy a proxy for karmik's reps, on the desktop, adjust sources.list accordingly)

But SUDDENLY I did not find the apt-proxy package in Squeese's turnips. After wandering around the Internet, on the apt-proxy project page, I learned that life is difficult and that someone there crashed in a car accident, returning from some IT party. As a result, the promised refactoring is not finished and in general fig knows it. However, there I saw a list of project clones, and lo and behold, one of them appeared in the Debian: apt-cacher.

ON SERVER:

Installation:
$ sudo apt-get install apt-cacher
Setting:
$ sudo vim /etc/apt-cacher/apt-cacher.conf

Since our client machines use ubuntu, we write path_map in the config:
path_map = ubuntu ru.archive.ubuntu.com/ubuntu; ubuntu-updates ru.archive.ubuntu.com/ubuntu; ubuntu-security security.ubuntu.com/ubuntu; ubuntu-partner archive.canonical.com/ubuntu

The default port of apt-caher is 3142. In order to hang it on the port<1024, надо запускать его из под рута, что в целом не нужно.

Thus, we get the following bundles:
http: // localrepo: 3142 / ubuntu => http://ru.archive.ubuntu.com/ubuntu http: // localrepo: 3142 / ubuntu-updates => http://ru.archive.ubuntu.com/ubuntu http: // localrepo: 3142 / ubuntu-security => http://security.ubuntu.com/ubuntu http: // localrepo: 3142 / ubuntu-partner => http://archive.canonical.com/ubuntu

Moreover, what pleased us, unlike many packages, there is no need to specify a specific distribution kit, that is, with these settings we will be able to serve machines with any ubuntu distribution kit.

We enable autostart of the daemon:
$ sudo vim / etc / default / apt-cacher
Set the value: AUTOSTART = 1
Restart:
$ sudo /etc/init.d/apt-cacher restart
Voila. Everything is ready to go.

BY DESKTOP MACHINE:

Now we add our repository to the sources.list of the desktop machine:
$ sudo vim /etc/apt/sources.list

If you are a system administrator, then you need to frequently install new software, security updates and other patches on your systems. If there was only one computer, then this would not cause problems, but usually there are several computers on the network and they all need updates. This can reduce network bandwidth. On every system, applications will be downloaded and installed directly from the Ubuntu repositories.

But there is a way out, you can save all applications on a server in the local network, and then distribute them to other computers on this network when needed. The Ubuntu Local Repository is a really fast and efficient way to deploy applications, as all the applications you need will be pulled instantly from the local server at great speed. Thus, you can reduce Internet traffic and, as a result, reduce the annual cost of paying for the Internet.

In this tutorial, I will show you how to set up a local Ubuntu 16.04 repository in two ways.

In this method, we will download all packages from the public repository to the hard drive of the Ubuntu server. First you need to install the Apache web server. It is required to distribute packages over a local network:

sudo apt-get install apache2

Now install apt-mirror:

sudo apt-get install apt-mirror

Create a directory where all packages will be downloaded:

sudo mkdir / myrepo

Now open the file /etc/apt/mirror.list and add the following line:

sudo vi /etc/apt/mirror.list

############# config ##################
#
# set base_path / var / spool / apt-mirror

set base_path / myrepo

Here / myrepo is the address of the folder you just created. Also in this configuration file you can specify the repositories that you want to use, we will use the standard ones, but you can add PPA as well. If you want to use both x64 and x32 architectures, the repositories for them must be specified separately in the file.

For example, for x32 the line will start with deb-i386 and for x64: deb-amd64. When you're done with the configuration, start downloading the packages with the command:

The terminal will display something like:

Downloading 162 index files using 20 threads ...
Begin time: Wed Aug 5 16:09:16 2015
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

Currently, all packages from the Ubuntu public repository are downloaded and stored in a local folder. In our case, in the / myrepo folder. Depending on your internet speed, this can take several hours. You can cancel the download at any time, when you resume it, it will continue where you interrupted it.

You don't have to manually run this command every day to update the repository, you can schedule a cron job. To do this, uncomment the following line in the /etc/cron.d/apt-mirror file:

sudo vi /etc/cron.d/apt-mirror

# Regular cron jobs for the apt-mirror package
#
0 4 * * * apt-mirror / usr / bin / apt-mirror> /var/spool/apt-mirror/var/cron.log

In this example, Cron will run a package update at four in the morning every day.

After the download is complete, check if there are any packages in the / myrepo directory

Now you need to make the packages available over the network. To do this, let's create a symbolic link:

sudo ln -s /myrepo/mirror/us.archive.ubuntu.com/ubuntu/ ubuntu

Client configuration

Configuring on a client machine is straightforward. Just open the file /etc/apt/sources.list and add your local repository, just like you added the remote one, just use your ip address of your machine:

sudo vi /etc/apt/sources.list

[...]
deb http://192.168.1.102/ubuntu trusty universe
deb http://192.168.1.102/ubuntu trusty main restricted
deb http://192.168.1.102/ubuntu trusty-updates main restricted
[...]

That's it, here 192.168.1.102 - address of the server with the repository. Now let's update the package lists:

sudo apt-get update

To install the program, just run the standard command:

sudo apt-get install package-name

The apt-mirror ubuntu 16.04 setup is now complete. Now clients do not need an internet connection to download packages. They will receive all packages and updates from their local Ubuntu repository.

Method 2: APT-Cacher

There is more than one way to create a local ubuntu repository. Apt-cacher is slightly different from apt-mirror. It does not download all packages from the repository, but only saves and makes available to everyone, those that were requested once.

First, install the Apache server:

sudo apt-get install apache2

Then apt-cahcer:

sudo apt-get install apt-cacher

Select the launch method - daemon and press ok:

Now you need to edit / etc / default / apt-cacher, setting the autostart parameter to 1.

sudo vi / etc / default / apt-cacher

apt-cacher daemon startup configuration file

# Set to 1 to run apt-cacher as a standalone daemon, set to 0 if you are going
# to run apt-cacher from / etc / inetd or in CGI mode (deprecated). Alternatively,
# invoking "dpkg-reconfigure apt-cacher" should do the work for you.
#
AUTOSTART = 1

# extra settings to override the ones in apt-cacher.conf
# EXTRAOPT = "daemon_port = 3142 limit = 30"

You can also configure from which ip it will be possible to access the cache, for this open the file /etc/apt-cacher/apt-cacher.conf and edit the corresponding line: For example, we will allow connection only to computers with ip from 192.168.1.20 to 192.168.1.30 :

sudo vi /etc/apt-cacher/apt-cacher.conf

[...]
## Uncomment and set the IP range ##
allowed_hosts = 192.168.1.20 - 192.168.1.30
#denied_hosts =
[...]

After completing the settings, restart apache:

sudo systemctl restart apache2

sudo service apache2 restart

Client side customization

Create a file sudo nano /etc/apt/apt.conf.d/01proxy and add the following line to it:

sudo nano /etc/apt/apt.conf.d/01proxy

Acquire :: http :: Proxy "http://192.168.1.102:3142";

Here 192.168.1.102 is the address of our local repository. It remains to update the package lists:

sudo apt-get update

We are not adding a local Ubuntu repository here, we are just using a proxy to download packages.

conclusions

That's all. This technology will be very useful for system administrators, as well as for ordinary users who have a weak Internet. If you have any questions, ask in the comments!