方法一

缓存deb包

# apt install XXX
# mkdir -p /usr/local/mydebs
# find /var/cache/apt/archives/ -name *.deb | xargs -i mv {} /usr/local/mydebs/

搭建repo服务

# apt install nginx
# rm -rf /etc/nginx/sites-enabled/default
# vim /etc/nginx/sites-enabled/openstack-slushee.vhost
server {
listen 80;
server_name openstack-slushee; # Logging
access_log /var/log/nginx/openstack-slushee.access.log;
error_log /var/log/nginx/openstack-slushee.error.log; location / {
root /var/www/repo/;
autoindex on;
expires 5h;
}
}
# ln -s /usr/local/mydebs/ /var/www/repo
# systemctl restart nginx

创建GPG KEY

### 生成随机数
# apt install rng-tools
# rngd -r /dev/urandom ### 创建密钥
# gpg --gen-key
gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 4
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 1024
Requested keysize is 1024 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>" Real name: Repository
Email address:
Comment:
You selected this USER-ID:
"Repository" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key. gpg: gpg-agent is not available in this session
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
...+++++
+++++
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 3F21CDF4 marked as ultimately trusted
public and secret key created and signed. gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 1024R/3F21CDF4 2017-04-13
Key fingerprint = 2207 F410 60C5 D2D8 8168 60D0 E21E 0ADD 3F21 CDF4
uid Repository Note that this key cannot be used for encryption. You may want to use
the command "--edit-key" to generate a subkey for this purpose.

导出key文件

# cd /var/www/repo
# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub 1024R/3F21CDF4 2017-04-13
uid Repository
# gpg --output keyFile --armor --export 3F21CDF4

生成Packages.gz、Release、InRelease、Release.gpg文件

### 每次添加新deb包后都需要重新执行下面命令
# cd /var/www/repo
# 生成索引文件
# apt-ftparchive packages . > Packages
# gzip -c Packages > Packages.gz
# apt-ftparchive release . > Release
### 输入前面设置的GPG KEY密码
# gpg --clearsign -o InRelease Release
# gpg -abs -o Release.gpg Release

设置软件源

# apt-key add /var/www/repo/keyFile
# vim /etc/apt/sources.list
deb http://192.168.200.15/ ./

问题处理

  • gpg --gen-key失败
Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 300 more bytes)

解决办法

# apt install rng-tools
# rngd -r /dev/urandom

方法二

使用apt-cacher-ng制作缓存

  • 安装apt-cacher-ng
# apt install apt-cacher-ng
# vim /etc/apt-cacher-ng/acng.conf
CacheDir: /var/www/repo/pkg-cache
LogDir: /var/log/apt-cacher-ng
Port: 3142
BindAddress: 0.0.0.0
Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian # Debian Archives
Remap-uburep: file:ubuntu_mirrors /ubuntu ; file:backends_ubuntu # Ubuntu Archives
Remap-debvol: file:debvol_mirror*.gz /debian-volatile ; file:backends_debvol # Debian Volatile Archives
Remap-cygwin: file:cygwin_mirrors /cygwin # ; file:backends_cygwin # incomplete, please create this file or specify preferred mirrors here
Remap-sfnet: file:sfnet_mirrors # ; file:backends_sfnet # incomplete, please create this file or specify preferred mirrors here
Remap-alxrep: file:archlx_mirrors /archlinux # ; file:backend_archlx # Arch Linux
Remap-fedora: file:fedora_mirrors # Fedora Linux
Remap-epel: file:epel_mirrors # Fedora EPEL
Remap-slrep: file:sl_mirrors # Scientific Linux
ReportPage: acng-report.html
PidFile: /var/run/apt-cacher-ng
ExTreshold: 4
LocalDirs: acng-doc /usr/share/doc/apt-cacher-ng
PassThroughPattern: .*
  • 修改软件源
# echo "Acquire::http::Proxy \"http://192.168.200.10:3142\";" > /etc/apt/apt.conf.d/00apt-cacher-proxy
  • 下载软件
# apt update
### deb将被缓存到/var/www/repo/pkg-cache目录
# apt install vim

将apt-cacher缓存的源做成镜像

  • 复制目录结构
# cd /var/www/repo
### 打印apt-cacher-ng缓存的deb
# tree pkg-cache ├── mirror.rackspace.com
│ └── mariadb
│ └── repo
│ └── 10.0
│ └── ubuntu
│ ├── dists
│ │ └── xenial
│ │ ├── InRelease
│ │ ├── InRelease.head
│ │ └── main
│ │ ├── binary-amd64
│ │ │ ├── Packages.gz
│ │ │ └── Packages.gz.head
│ │ └── binary-i386
│ │ ├── Packages.gz
│ │ └── Packages.gz.head
│ └── pool
│ └── main
│ ├── g
│ │ └── galera-3
│ │ ├── galera-3_25.3.19-xenial_amd64.deb
│ │ └── galera-3_25.3.19-xenial_amd64.deb.head
│ └── m
│ └── mariadb-10.0
│ ├── libmariadbclient18_10.0.30+maria-1~xenial_amd64.deb
│ ├── libmariadbclient18_10.0.30+maria-1~xenial_amd64.deb.head
│ ├── libmariadbclient-dev_10.0.30+maria-1~xenial_amd64.deb
│ ├── libmariadbclient-dev_10.0.30+maria-1~xenial_amd64.deb.head
│ ├── libmysqlclient18_10.0.30+maria-1~xenial_amd64.deb
│ ├── libmysqlclient18_10.0.30+maria-1~xenial_amd64.deb.head
│ ├── mariadb-client-10.0_10.0.30+maria-1~xenial_amd64.deb
│ ├── mariadb-client-10.0_10.0.30+maria-1~xenial_amd64.deb.head
│ ├── mariadb-client_10.0.30+maria-1~xenial_all.deb
│ ├── mariadb-client_10.0.30+maria-1~xenial_all.deb.head
│ ├── mariadb-client-core-10.0_10.0.30+maria-1~xenial_amd64.deb
│ ├── mariadb-client-core-10.0_10.0.30+maria-1~xenial_amd64.deb.head
│ ├── mariadb-common_10.0.30+maria-1~xenial_all.deb
│ ├── mariadb-common_10.0.30+maria-1~xenial_all.deb.head
│ ├── mariadb-galera-server-10.0_10.0.30+maria-1~xenial_amd64.deb
│ ├── mariadb-galera-server-10.0_10.0.30+maria-1~xenial_amd64.deb.head
│ ├── mysql-common_10.0.30+maria-1~xenial_all.deb
│ └── mysql-common_10.0.30+maria-1~xenial_all.deb.head
├── ubuntu-cloud.archive.canonical.com
│ └── ubuntu
│ ├── dists
│ │ └── xenial-updates
│ │ └── newton
│ │ ├── main
│ │ │ ├── binary-amd64
│ │ │ │ ├── Packages.gz
│ │ │ │ └── Packages.gz.head
│ │ │ └── binary-i386
│ │ │ ├── Packages.gz
│ │ │ └── Packages.gz.head
│ │ ├── Release
│ │ ├── Release.gpg
│ │ ├── Release.gpg.head
│ │ └── Release.head
│ └── pool
│ └── main
│ ├── d
│ │ └── dnsmasq
│ │ ├── dnsmasq_2.76-4~cloud0_all.deb
│ │ ├── dnsmasq_2.76-4~cloud0_all.deb.head
│ │ ├── dnsmasq-base_2.76-4~cloud0_amd64.deb
│ │ ├── dnsmasq-base_2.76-4~cloud0_amd64.deb.head
│ │ ├── dnsmasq-utils_2.76-4~cloud0_amd64.deb
│ │ └── dnsmasq-utils_2.76-4~cloud0_amd64.deb.head
│ └── p
│ ├── pyopenssl
│ │ ├── python-openssl_16.1.0-1~cloud0_all.deb
│ │ └── python-openssl_16.1.0-1~cloud0_all.deb.head
│ ├── python-cryptography
│ │ ├── python-cryptography_1.5-2ubuntu0.1~cloud0_amd64.deb
│ │ └── python-cryptography_1.5-2ubuntu0.1~cloud0_amd64.deb.head
│ └── python-setuptools
│ ├── python-pkg-resources_26.1.1-1~cloud0_all.deb
│ ├── python-pkg-resources_26.1.1-1~cloud0_all.deb.head
│ ├── python-setuptools_26.1.1-1~cloud0_all.deb
│ └── python-setuptools_26.1.1-1~cloud0_all.deb.head ### 复制源目录结构
# cp -r pkg-cache/mirror.rackspace.com/mariadb/repo/10.0/ubuntu/ mariadb
# cp -r pkg-cache/ubuntu-cloud.archive.canonical.com/ubuntu/ ubuntu-cloud
  • 修改软件源
# tree mariadb/dists
# tree ubuntu-cloud/dists
### 1.deb url中的url指向的是dists和pool的父目录
### 2.deb url后面的格式规范:第一个是能找到Release/InRelease文件的目录结构,例如mariadb的就是xenial,ubuntu-cloud就是xenial-updates/newton;第二个就是第一个的子目录名,例如mariadb的就是main,ubuntu-cloud也是main
### 3.如果apt update的时候提示对应deb源的packages没找到,则需要删除对应项,例如"deb http://172.29.248.10:8181/ubuntu-repo xenial-security main universe multiverse"提示"Err:14 http://172.29.248.10:8181/ubuntu-repo xenial-security/multiverse Translation-en 404",则修改源为"deb http://172.29.248.10:8181/ubuntu-repo xenial-security main universe"即可 # vim /etc/apt/sources.list
deb http://172.29.248.10:8181/mariadb xenial main
deb http://172.29.248.10:8181/ubuntu-cloud xenial-updates/newton main ### 如果更新失败,去ubuntu keyserver上下载对应gpg添加上即可
# apt update

参考资料

官方文档

官方文档

官方文档

Apt本地源制作的更多相关文章

  1. YUM本地源制作与yum网络版仓库

    1.修改本机上的YUM源配置文件,将源指向自己 cd /etc/yum.repos.d/ 备份原有的YUM源的配置文件 rename .repo .repo.bak * rename CentOS-M ...

  2. 【linux】yum本地源制作

    在/etc/yum.repos.d/ 目录下,有两个文件  CentOS-Base.repo和 CentOS-Media.repo 其中CentOS-Base.repo 记录着网络上的 yum 源的地 ...

  3. CentOS 6.5 PYPI本地源制作

    转载:blog.csdn.net/tantexian   一.安装pip2pi工具: pip install pip2pi 或 git clone https://github.com/wolever ...

  4. Yum本地源制作

    参考文档 环境准备 # cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID=" ...

  5. centos 7_本地源制作

    1.安装工具 yum install yum-utils createrepo yum-plugin-priorities   2.自己创建一个阿里源 vim /etc/yum.repos.d/ope ...

  6. ubuntu制作本地源

    背景 平时apt-get install安装软件时,下载的deb文件都会存放在/var/cache/apt/archives/下,为了今后重装或给别人用,特别是没有网络时,这些deb文件实际上是可以派 ...

  7. Ubuntu 16.04 LTS制作本地源

    平时apt-get install安装软件时,下载的deb文件都会存放在/var/cache/apt/archives/下,没有网络时就需要将这些deb制作成本地源.另外,如果在本机架一个简单的网络服 ...

  8. ubuntu下的apt-get内网本地源的搭建

    APT本地源的搭建(可用于局域网apt-get源搭建或者本地源) 本文档介绍使用apt-mirror软件搭建apt本地源 需求:内网开发环境由于其特定原因不能上外网,所以需要本地环境下的内网源来方便开 ...

  9. Linux软件源书写格式解析及本地yum源制作

    1.Debian类系统 配置文件:/etc/apt/sources.list 例子:deb https://mirrors.aliyun.com/kali kali-rolling main cont ...

随机推荐

  1. TensorFlow运行时出现warning如何设置禁止打印方法

    有时候运行TensorFlow时比较烦人,经常报一些warning或者版本更新了之类的一些警告,如下: 那么如何去掉或者说不显示这些东西呢,可以通过简单添加几行代码搞定,来看一下. 这样就不会报警告了 ...

  2. Android Weekly Notes Issue #322

    Android Weekly Issue #322 August 12th, 2018 Android Weekly Issue #322. 本期内容包括: 键盘的图像支持; 网络安全实现; Kotl ...

  3. 郝健: Linux内存管理学习笔记-第1节课【转】

    本文转载自:https://blog.csdn.net/juS3Ve/article/details/80035751 摘要 MMU与分页机制 内存区域(内存分ZONE) LinuxBuddy分配算法 ...

  4. java2 -宏观了解

    java2 -宏观了解 2016-01-24 16:17 308人阅读 评论(38) 收藏 举报  分类: JAVA(2)  版权声明:本文为博主原创文章,未经博主允许不得转载. Java2平台包括: ...

  5. 无法远程连接阿里云的Mysql

    问题描述:昨天使用阿里云安装了Mysql,无法远程连接,排除端口号错误.防火墙.Mysql权限问题后,最后发现是阿里云安全组规则限制问题: 解决方式: 1.访问阿里云控制台,实例-->管理 2. ...

  6. Mac安装 Storm 小结

    Strom 安装&部署 本地执行:Storm Topology是可进行本地运行的, 必须在发布前进行本地测试, 以确保代码本身业务逻辑没有问题( Windows也可执行, 但是由于权限等原因, ...

  7. spring属性注入DI

    spring setter方式注入: 注入对象属性: 前提: 在bean对应实体中有对应的setter方法. 基础代码: 在bean中有另一个bean属性的setter方法. package cn.i ...

  8. BZOJ_4025_二分图_线段树按时间分治+并查集

    BZOJ_4025_二分图_线段树按时间分治+并查集 Description 神犇有一个n个节点的图.因为神犇是神犇,所以在T时间内一些边会出现后消失.神犇要求出每一时间段内这个图是否是二分图.这么简 ...

  9. 「LuoguP1725」琪露诺(dp 单调队列

    题目描述 在幻想乡,琪露诺是以笨蛋闻名的冰之妖精. 某一天,琪露诺又在玩速冻青蛙,就是用冰把青蛙瞬间冻起来.但是这只青蛙比以往的要聪明许多,在琪露诺来之前就已经跑到了河的对岸.于是琪露诺决定到河岸去追 ...

  10. MySql 官方存储引擎

    存储引擎是为不同的表类型处理 SQL 操作的 MySql 组件.InnoDB 是默认的.最通用的存储引擎,也是官方推荐使用的存储引擎,除非一些特定案例.MySql 5.6 中的 CREATE TABL ...