Debian OS本地及局域网apt源搭建

一、本地apt源搭建

1.1、上传ISO镜像到本地OS

上传dvd1.iso,dvd2.iso,dvd3iso镜像到系统下

# mkdir /root/ISO
# ls -l debian-10.6.0-amd64-DVD-*
-rw-r--r-- 1 root root 3972317184 Apr 18 08:55 debian-10.6.0-amd64-DVD-1.iso
-rw-r--r-- 1 root root 4686921728 Apr 18 08:55 debian-10.6.0-amd64-DVD-2.iso
-rw-r--r-- 1 root root 4640186368 Apr 18 08:54 debian-10.6.0-amd64-DVD-3.iso

1.2、挂载ISO镜像

  • 手动挂载
# mkdir /mnt/source{1..3}
mount -o loop  /root/ISO/debian-10.6.0-amd64-DVD-1.iso /mnt/source1
mount -o loop  /root/ISO/debian-10.6.0-amd64-DVD-2.iso /mnt/source2
mount -o loop  /root/ISO/debian-10.6.0-amd64-DVD-3.iso /mnt/source3
  • 设置开机自动挂载
    在/etc/fstab后追加如下内容设置开机自动挂载
# vim /etc/fstab
/root/ISO/debian-10.6.0-amd64-DVD-1.iso /mnt/source1 udf,iso9660 user,loop 0 0
/root/ISO/debian-10.6.0-amd64-DVD-2.iso /mnt/source2 udf,iso9660 user,loop 0 0
/root/ISO/debian-10.6.0-amd64-DVD-3.iso /mnt/source3 udf,iso9660 user,loop 0 0

1.3、编辑apt配置文件

# vim /etc/apt/sources.list

deb [trusted=yes] file:///mnt/source1 buster contrib main
deb [trusted=yes] file:///mnt/source2 buster contrib main
deb [trusted=yes] file:///mnt/source3 buster contrib main

配置文件中 buster 是debian10的代号,若为其他版本需要改为对应代号

  • Debian 11 (bullseye) — 當前的穩定(stable)版
  • Debian 10(buster) — 當前的舊的穩定(oldstable)版,現有長期支持
  • Debian 9(stretch) — 更舊的穩定(oldoldstable)版,現有擴展長期支持
  • Debian 8(jessie) — 已存檔版本,現有擴展長期支持

1.4、验证apt源

apt update
apt install vim

二、局域网apt源搭建

此文搭建apt源的http Server配置如下

OS: CentOS 7U6,
IP: 192.168.15.10

2.1、 安装Http服务和xml生成工具,由于安装系统时已经顺便安装了相应的安装包,所以此处无须再进行安装。

[root@simonlinux ~]# yum install httpd createrepo
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository base is listed more than once in the configuration
Package httpd-2.4.6-88.el7.x86_64 already installed and latest version
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do

2.2、 新建存放yum源文件的目录并将相关文件复制进去

[root@simonlinux smb]# ls -l
-rw-r--r-- 1 root root 3972317184 Apr 18 08:55 debian-10.6.0-amd64-DVD-1.iso
-rw-r--r-- 1 root root 4686921728 Apr 18 08:55 debian-10.6.0-amd64-DVD-2.iso
-rw-r--r-- 1 root root 4640186368 Apr 18 08:54 debian-10.6.0-amd64-DVD-3.iso
[root@simonlinux smb]# mkdir  /mnt/source{1..3}
[root@simonlinux smb]# mount -o loop debian-10.6.0-amd64-DVD-1.iso /mnt/source1
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux smb]# mount -o loop debian-10.6.0-amd64-DVD-2.iso /mnt/source2
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux smb]# mount -o loop debian-10.6.0-amd64-DVD-3.iso /mnt/source3
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux ~]# mkdir -p /var/www/html/apt_sosurce/debian/10u6/source{1..3}
[root@simonlinuxt ~]# rsync -avh /mnt/source1 /var/www/html/apt_source/debian/10u6/source1
[root@simonlinux ~]# rsync -avh /mnt/source2 /var/www/html/apt_source/debian/10u6/source2
[root@simonlinux ~]# rsync -avh /mnt/source3 /var/www/html/apt_source/debian/10u6/source3

2.3、启动http服务

[root@simonlinux ~]# systemctl restart httpd
[root@simonlinux ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-04-19 22:26:29 CST; 7s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 15983 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 15989 (httpd)
   Status: "Processing requests..."
    Tasks: 8
   CGroup: /system.slice/httpd.service
           ├─15989 /usr/sbin/httpd -DFOREGROUND
           ├─15990 /usr/libexec/nss_pcache 491523 off
           ├─15994 /usr/sbin/httpd -DFOREGROUND
           ├─15995 /usr/sbin/httpd -DFOREGROUND
           ├─15996 /usr/sbin/httpd -DFOREGROUND
           ├─15997 /usr/sbin/httpd -DFOREGROUND
           └─15998 /usr/sbin/httpd -DFOREGROUND

Apr 19 22:26:29 simonlinux.com systemd[1]: Starting The Apache HTTP Server...
Apr 19 22:26:29 simonlinux.com systemd[1]: Started The Apache HTTP Server. 

发现网页端无法打开,将网站端口添加到防火墙规则里并重启防火墙

[root@simonlinux ~]# firewall-cmd --add-port=80/tcp --permanent 
success
[root@simonlinux ~]# systemctl restart firewalld.service
[root@simonlinux ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eno1
sources: 
services: dhcpv6-client ssh
ports: 5901-5905/tcp 80/tcp
protocols: 
masquerade: no
forward-ports: 
source-ports: 
icmp-blocks: 
rich rules: 

设置http服务开机启动

[root@simonlinux ~]# systemctl enable httpd

2.3、编辑本地apt配置文件

# vim /etc/apt/sources.list

deb [trusted=yes] http://192.168.15.10/apt_source/debian/10u6/source1 buster contrib main
deb [trusted=yes] http://192.168.15.10/apt_source/debian/10u6/source2 buster contrib main
deb [trusted=yes] http://192.168.15.10/apt_source/debian/10u6/source3 buster contrib main

配置文件中 buster 是debian10的代号,若为其他版本需要改为对应代号

  • Debian 11 (bullseye) — 當前的穩定(stable)版
  • Debian 10(buster) — 當前的舊的穩定(oldstable)版,現有長期支持
  • Debian 9(stretch) — 更舊的穩定(oldoldstable)版,現有擴展長期支持
  • Debian 8(jessie) — 已存檔版本,現有擴展長期支持

2.4、验证apt源

apt update
apt install vim
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
搭建本地apt镜像是为了提高软件包下载速度并减轻网络流量,特别是在网络状况较差或者需要频繁更新的环境中。以下是搭建本地apt镜像的步骤: 1. 确保已经安装了一个可用的Linux发行版,如Ubuntu,Debian等,并且已经连接到互联网。 2. 打开终端,在命令行下执行以下命令以安装所需的软件包: ``` $ sudo apt-get install apt-mirror ``` 3. 编辑`/etc/apt/mirror.list`文件,创建一个新的镜像配置文件。配置文件中的注释提供了每个设置的说明,根据自己的需求进行相应的修改。确保设置`mirror_dir`为要存储镜像的本地目录。 4. 运行以下命令以启动apt-mirror并开始下载软件包: ``` $ sudo apt-mirror ``` apt-mirror将根据配置文件中的设置下载软件包并保存到本地目录。这可能需要一些时间,具体的时间取决于镜像的大小以及当前的网络速度。 5. 当下载完成后,你可以通过将本地镜像添加为apt来使用它。编辑`/etc/apt/sources.list`文件,并将以下行添加到文件中: ``` deb file:/path/to/local/mirror ``` 将`/path/to/local/mirror`替换为实际镜像存储目录的路径。 6. 最后,执行以下命令以更新apt缓存并开始使用本地镜像: ``` $ sudo apt-get update ``` 现在,你可以使用本地apt镜像来安装软件包,它将从本地目录中读取软件包,而不是从互联网上下载。 通过搭建本地apt镜像,你可以显著提高软件包下载速度,减轻网络负载,并获得更好的软件包管理体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值