Инструменты пользователя

Инструменты сайта


software:linux_server:local_or_private_ubuntu_mirror

Создание локального зеркала Ubuntu

Введение

Локальные копии репозиториев нужны для установки программ на машины с Ubuntu, не подключённые к интернету. В этом случае можно создать копию нужных репозиториев на внешнем диске или на компьютере, у которого есть доступ к интернету, а затем подключить эту копию в качестве репозитория к машинам, на которых интернета нет. Для этого вам потребуется компьютер с установленной Ubuntu и безлимитным доступом к интернету.

Локальная копия официального репозитория Ubuntu deb http://ru.archive.ubuntu.com/ubuntu/ focal main restricted занимает 135+ GiB, учтите это.

Создание дерева папок

Создаём несколько папок в домашней дирректории, в которой будет храниться наш срез репозитория (или даже несколько), к примеру, согласно нижеприведенной схемы:

Для этого введем ниже приведенные команды

sudo mkdir /home/alisa/repo
sudo mkdir /home/alisa/repo/debmirror
sudo mkdir /home/alisa/repo/debmirror/amd64
sudo mkdir /home/alisa/repo/debmirror/mirrorkeyring
sudo mkdir /home/alisa/repo/scripts



В итоге у нас получиться:

Настроим права доступа к нашей главной папке

sudo chown -R root:alisa /home/alisa/repo
sudo chmod -R 571 /home/alisa/repo



Установка зависимостей

Установим web server Apache2 и настроим брандмауэр по аналогии в этой статье.
Обновим список пакетов

sudo apt-get update



и установим небходимое ПО
Если web server Apache2 уже установлен, то

sudo apt install debmirror gnupg xz-utils


Иначе

sudo apt install apache2 debmirror gnupg xz-utils


Gnupg нужен для связки ключей. Xz – необходимость декомпрессии.

Откройте список источников (sources.list)

sudo sensible-editor /etc/apt/sources.list




и добавьте следующую строку:

#############################################################
########## Ubuntu 22.04 LTS (Jammy Jellyfish)  ##############
#############################################################

deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu/ jammy partner
deb-src http://archive.canonical.com/ubuntu/ jammy partner


CTRL+O → ENTER → CTRL+X (Сохранить и выйти)

После редактирования списка репозиториев не забудьте обновить список пакетов.

sudo apt-get update
sudo apt-get dist-upgrade



c

Скрипт mirrorkernel.sh

Теперь создадим mirrorkernel.sh, открыв предпочитаемый вами редактор таким образом

sudo sensible-editor /home/alisa/repo/scripts/mirrorkernel.sh



Скопируйте текст из поля ниже в редактор.

#!/bin/bash -x
/usr/bin/debmirror --source -m --passive --host=archive.ubuntu.com \
--root=ubuntu --method=http --progress \
--dist=focal,focal-security,focal-updates,focal-backports,jammy,jammy-security,jammy-updates,jammy-backports,noble,noble-security,noble-updates,noble-backports \
--ignore-release-gpg --section=main,restricted,universe,multiverse \
--arch=amd64 /home/alisa/repo/debmirror/amd64/


  • –host=archive.ubuntulinux.org - это адрес репозитория (без слеша на конце,здесь archive.ubuntulinux.org)
  • –root=ubuntu - это тот каталог, от которого начнётся зеркалирование пакетов. Короче - это каталог, который виден сразу после захода на адрес, указанный в –host
  • –method=ftp - ftp или http
  • –dist=hardy,hardy-security,hardy-updates,hardy-backports - название версии дистрибутива, который нас интересует. Если вы всё еще используете старую версию Ubuntu 7.10 (Gutsy Gibbon), то вам необходимо немного подправить этот скрипт, в частности, необходимо изменить значения параметра –dist с hardy на gutsy.
  • –section=main,restricted,multiverse,universe - название секции, которая нам нужна (если не одна - разделитель запятая без пробелов)
  • –arch=i386 - архитектура. Значение i386 говорит о том, что будут скачаны пакеты для компьютера с архитектурой x86. Этот параметр также может принимать значение amd64 для 64-битных AMD или Intel компьютеров.



CTRL+O → ENTER → CTRL+X (Сохранить и выйти)
Перейдем в директорию с нашим новым скриптом mirrorkernel.sh и дадим ему разрешение на выполнение:

cd /home/alisa/repo/scripts/
sudo chmod +x mirrorkernel.sh

chmod (от англ. change mode) — команда для изменения прав доступа к файлам и каталогам, используемая в Unix-подобных операционных системах.



Запуск и Автоисполнение

Находясь в папке с скриптом, запустим его на выполнение:

sudo apt install screen
sudo screen /home/alisa/repo/scripts/mirrorkernel.sh


screen это терминальный мультиплексор. Процесс, запущенный внутри сессии через screen, будет продолжаться даже тогда, когда вы отключитесь от самой первой сессии. См. подробнее...
После выполнения команды пойдет загрузка файлов в наше локальное зеркало:

Cron – планировщик задач. Если подробнее, то это утилита, позволяющая выполнять скрипты на сервере в назначенное время с заранее определенной периодичностью.

sudo crontab -e


Select an editor. To change later, run 'select-editor'.

1. /bin/nano        <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed

Choose 1-4 [1]: 1


Для nano выберем 1

0 0 1 * * /home/alisa/repo/scripts/mirrorkernel.sh


запускать скрипт 1 числа каждого месяца



Настройка доступа к зеркалу

Создадим символическую ссылку из /home/alisa/repo/debmirror/amd64 на /var/www/ubuntu.

cd /var/www/html
sudo ln -s /home/alisa/repo/debmirror/amd64 ubuntu




Перезапустим Apache:

sudo service apache2 restart

Проверим работу нашего веб-сервера

sudo systemctl status apache2



перейдем на главную страницу в браузере нашего сервера (в примере http://192.168.1.152/)

И наконец перейдем в папку для которой мы ранее указали символическую ссылку (в примере http://192.168.1.152/ubuntu/):

Файлы и Дополнения

Официальные репозитарии Ubuntu

deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu/ jammy partner
deb-src http://archive.canonical.com/ubuntu/ jammy partner

Настройка клиенских системы

Просмотреть все репозитории:

sudo nano /etc/apt/sources.list

Они также могут находиться в одном из файлов в папке /etc/apt/sources.list.d/ Сделаем архивную копию нашего оригинального файла sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
См. запись оригинального файла sources.list
#deb cdrom:[Ubuntu 22.04 LTS _Jammy Jellyfish_ - Release amd64 (20220419)]/ jammy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ru.archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ru.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ru.archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy universe
deb http://ru.archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. 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://ru.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://ru.archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://ru.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy-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://ru.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://ru.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

Удалим подключенные репозитории, замени их на наше зеркало и сохраним файл:

deb http://192.168.1.20/ubuntu/ jammy main restricted
deb http://192.168.1.20/ubuntu/ jammy-updates main restricted
deb http://192.168.1.20/ubuntu/ jammy universe
deb http://192.168.1.20/ubuntu/ jammy-updates universe

Получим обновленные списки пакетов:

sudo apt-get update

обновить список пакетов. sudo apt update обновим пакеты

sudo apt-get dist-upgrade

Удалим подключенные репозитории на машине с Ubuntu 24.04, заменим их на наше зеркало и сохраним файл:

deb http://192.168.1.20/ubuntu/ noble main restricted
deb http://192.168.1.20/ubuntu/ noble-updates main restricted
deb http://192.168.1.20/ubuntu/ noble universe
deb http://192.168.1.20/ubuntu/ noble-updates universe
См. запись полного файла sources.list для Ubuntu 24.04 LTS noble Jellyfish
#deb cdrom:[Ubuntu 24.04 LTS _noble Jellyfish_ - Release amd64 (20220419)]/ noble main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://192.168.1.20/ubuntu/ noble main restricted
# deb-src http://192.168.1.20/ubuntu/ noble main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://192.168.1.20/ubuntu/ noble-updates main restricted
# deb-src http://192.168.1.20/ubuntu/ noble-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://192.168.1.20/ubuntu/ noble universe
# deb-src http://192.168.1.20/ubuntu/ noble universe
deb http://192.168.1.20/ubuntu/ noble-updates universe
# deb-src http://192.168.1.20/ubuntu/ noble-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. 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://192.168.1.20/ubuntu/ noble multiverse
deb http://192.168.1.20/ubuntu/ noble multiverse
# deb-src http://192.168.1.20/ubuntu/ noble multiverse
deb http://192.168.1.20/ubuntu/ noble-updates multiverse
# deb-src http://192.168.1.20/ubuntu/ noble-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://192.168.1.20/ubuntu/ noble-backports main restricted universe multiverse
# deb-src http://192.168.1.20/ubuntu/ noble-backports main restricted universe multiverse

deb http://192.168.1.20/ubuntu noble-security main restricted
# deb-src http://192.168.1.20/ubuntu noble-security main restricted
deb http://192.168.1.20/ubuntu noble-security universe
# deb-src http://192.168.1.20/ubuntu noble-security universe
deb http://192.168.1.20/ubuntu noble-security multiverse
# deb-src http://192.168.1.20/ubuntu noble-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

Получим обновленные списки пакетов:

sudo apt-get update

обновить список пакетов. sudo apt update обновим пакеты

sudo apt-get dist-upgrade

Дополнения и Файлы

Только авторизованные участники могут оставлять комментарии.
software/linux_server/local_or_private_ubuntu_mirror.txt · Последнее изменение: 2025/02/01 09:45 — 127.0.0.1