当前位置:   article > 正文

本地源制作_ubuntu本地源搭建

ubuntu本地源搭建

根据软件的来源,制作本地源大致可分为3情况:

1.使用操作系统的官方镜像;

2.使用软件包;

3.使用网络源;

下面依次介绍三种情况:

一、使用官方镜像

ubuntu 18.04 LTS

此处又可以细分为两种方式:

使用CD/DVD

①新建本地目录,并挂载镜像到本地目录

# mkdir /media/cdrom
# mount /dev/cdrom /media/cdrom
  • 1
  • 2

②添加本地目录到软件源

# cp /etc/apt/source.list /etc/apt/source.list.bak //备份/etc/apt/source.list
# >  /etc/apt/source.list  //清空原内容
# apt-cdrom   ident  //扫描光盘信息
# apt-cdrom add -m -d=/media/cdrom   //将/media/cdrom写入到/etc/apt/source.list
# cat /etc/apt/source.list //确认/media/cdrom已在/etc/apt/source.list
# apt-get -y update      //更新apt信息
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

apt-cdrom 参数说明:

使用apt-cdrom 命令将CD添加到源文件中。

ident 命令是一个调试工具,可以报告当前光盘和存储的文件名的信息

add命令可以向source.list中添加一个新的光盘源文件。

-d : 挂载点。挂载点必需在 /etc/fstab文件中并且正确配置。

-m:禁止挂载; 防止apt-cdrom挂载和卸载挂载点。

③修改/etc/fstab,增加如下行:

# vim /etc/fstab
.....
/dev/cdrom     /media/cdrom     iso9660 defaults        0       0
  • 1
  • 2
  • 3
使用ISO文件

①新建本地目录,挂载ISO文件到本地目录(假设ISO文件位于/opt目录)

# mkdir /media/cdrom
# mount /opt/iso_name /media/cdrom
  • 1
  • 2

②添加本地目录到软件源

# cp /etc/apt/source.list /etc/apt/source.list.bak //备份/etc/apt/source.list
# >  /etc/apt/source.list  //清空原内容
# vim /etc/apt/source.list //增加/media/cdrom已在/etc/apt/source.list
....
deb file:///media/cdrom/  bionic main restricted
# apt -y update      //更新apt信息
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

③修改/etc/fstab,增加如下行:

# vim /etc/fstab
.....
/opt/iso_name     /media/cdrom     iso9660 defaults        0       0
  • 1
  • 2
  • 3

CentOS 7.x

重命名网络源repo

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  • 1
使用CD/DVD

①新建本地目录,并挂载镜像到本地目录

# mkdir /media/CentOS
# mount /dev/cdrom /media/CentOS
  • 1
  • 2

②修改CentOS-Media.repo文件,将enable=0修改为enable=1

# vim /etc/yum.repos.d/CentOS-Media.repo
....
enabled=1
  • 1
  • 2
  • 3

③更新仓库源

# yum -y update
  • 1

④修改/etc/fstab,增加如下行:

# vim /etc/fstab
.....
/dev/cdrom     /media/CentOS     iso9660 defaults        0       0
  • 1
  • 2
  • 3
使用ISO文件

①新建本地目录,并挂载ISO到本地目录(假设ISO文件位于/opt目录)

# mkdir /media/CentOS
# mount /opt/iso_name /media/CentOS
  • 1
  • 2

②修改CentOS-Media.repo文件

# vim /etc/yum.repos.d/CentOS-Media.repo
....
enabled=1
gpgcheck=0 
  • 1
  • 2
  • 3
  • 4

③更新仓库源

# yum -y update
  • 1

④修改/etc/fstab,增加如下行:

# vim /etc/fstab
.....
/opt/iso_name     /media/CentOS     iso9660 defaults        0       0
  • 1
  • 2
  • 3

二、使用软件包

ubuntu 18.04 LTS

Ubuntu 18.04中的apt版本为1.6.11,必需进行签名。

前期准备

创建目录,将所需的deb文件拷贝到目录

# mkdir /opt/debs
# cp /debs-path/*.deb /opt/debs
  • 1
  • 2

进入目录生成索引文件及Release文件

# cd /opt/debs 
# apt-ftparchive packages . > Packages 
# apt-ftparchive release . > Release
  • 1
  • 2
  • 3
生成key

注:只需生成一次key,若已经生成过key,则无需再次生成

# gpg --full-generate-key
gpg (GnuPG) 2.2.4; Copyright (C) 2017 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? 
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 2048
Requested keysize is 2048 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

GnuPG needs to construct a user ID to identify your key.

Real name: caohf
Email address: caohf@toyou.com.cn
Comment: cc
You selected this USER-ID:
    "caohf (cc) <caohf@toyou.com.cn>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
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.
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: key CB7EF49AC8328682 marked as ultimately trusted
gpg: revocation certificate stored as '/root/.gnupg/openpgp-revocs.d/7DD009174499615E734CEBAECB7EF49AC8328682.rev'
public and secret key created and signed.

pub   rsa2048 2020-01-08 [SC]
       C4AD7615BCCA35C042E64799317274E4C974C4D5
uid                      caohf (ubuntu 18.04.3 gpg sign) <caohf@toyou.com.cn>
sub   rsa2048 2020-01-08 [E]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

如果生成签名卡住(原因详见:https://www.cnblogs.com/styshoo/p/6415939.html),执行如下命令:

# apt install rng-tools
# rng -r /dev/urandom  
  • 1
  • 2

查看key信息

# gpg --list-keys
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
/root/.gnupg/pubring.kbx
------------------------
pub   rsa2048 2020-01-12 [SC]
      C4AD7615BCCA35C042E64799317274E4C974C4D5
uid           [ultimate] caohf (cc) <caohf@toyou.com.cn>
sub   rsa2048 2020-01-12 [E]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

​ 导出公钥并添加至apt key

#  gpg -a --export pub_id | apt-key add -    
#  gpg -a --export C4AD7615BCCA35C042E64799317274E4C974C4D5 | apt-key add - 
  • 1
  • 2
生成签名

以下操作在/opt/debs目录下进行

# gpg --clearsign -o InRelease Release
# gpg -abs -o Release.gpg Release
  • 1
  • 2

修改电脑上的source.list文件

# cp /etc/apt/source.list /etc/apt/source.list.bal
# vim /etc/apt/source.list
...
deb file:///opt/debs/ /
# apt -y update
  • 1
  • 2
  • 3
  • 4
  • 5

CentOS7.x

创建目录,将所需的rpm文件拷贝到目录

# mkdir /opt/rpms
# cp /rpms-path/*.rpm /opt/rpms
  • 1
  • 2

安装createrepo命令

# yum -y install createrepo
  • 1

生成符合要求的yum仓库

# yum clean all
# createrepo /opt/rpms
  • 1
  • 2

/opt/rpms中新增一个repodata的仓库数据文件,说明创建仓库成功。

# ll -t /opt/rpms
  • 1

repodata是软件仓库,其目录下有四个必要文件:

filelists.xml.[gz],other.xml.[gz],primary.xml.[gz]和repomd.xml(md代表 metadata),

其中最主要的是repomd.xml文件。

一般出现找不到repodata目录或文件的错误,原因通常有三个:

①路径问题;

②无repodata目录;

③*.repo配置文件冲突。

添加或者删除rpm包后,不需要再次重新create,只需使用–update

# createrepo --update /opt/rpms
  • 1

更新缓存文件

# yum clean all
# yum makecache 
  • 1
  • 2

三、使用网络源

此种方式比较简单。

在本地创建与网络源相同的目录结构,下载网络源的有关文件,并放置到相关位置;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/255989
推荐阅读
相关标签
  

闽ICP备14008679号