搭建一个树莓派的开源镜像站

本地搭建一个镜像站,可以大大提高更新系统和安装软件的速度,本文以Ubuntu为例,使用apt-mirror软件,搭建一个自己的镜像站,提高树莓派更新系统的速度。

一、条件

由于树莓派的镜像大小有70多G,所以在搭建前需要保证一个100G以上的硬盘空间,否则会由于硬盘容量太小而搭建失败。

同时首次同步镜像需要的时间比较长,所以时间由服务器的带宽决定。

二、开始搭建

首先安装apt-mirror软件:

sudo apt-get install apt-mirror

接着配置镜像站设置:

打开/etc/apt/mirror.list文件,进行如下配置:

############# config ##################
#
set base_path /mnt
#
# set mirror_path $base_path/mirror
# set skel_path $base_path/skel
# set var_path $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads 20
set _tilde 0
#
############# end config ##############
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
#deb http://archive.ubuntu.com/ubuntu artful main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu artful-security main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu artful-updates main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu artful-proposed main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu artful-backports main restricted universe multiverse

#deb-src http://archive.ubuntu.com/ubuntu artful main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu artful-security main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu artful-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu artful-proposed main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu artful-backports main restricted universe multiverse

clean http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/

其中:

set base_path 表示要下载到哪个目录

然后开始同步镜像:

sudo apt-mirror

我使用的是华为云服务器同步,同步带宽大约在30Mbps。

大约用了7个小时才首次同步完,树莓派镜像的容量大约为80G。

最后为了能通过http访问到刚搭建的镜像站,需要在服务器上安装nginx服务器软件。

安装nginx :

sudo apt install nginx

建立连接,使得可以访问到镜像站:

sudo ln -s /mnt/mirror/
mirrors.tuna.tsinghua.edu.cn/raspbian/ /var/www/html/

这样镜像站就搭建完成了,可以在树莓派上将换源更新了。

三、开始使用

连接树莓派,修改镜像源配置。

编辑/etc/apt/sources.list文件。删除原文件所有内容,用以下内容取代:

deb http://121.36.81.4/raspbian/ buster main contrib non-free rpi

编辑此文件后,请使用sudo apt-get update命令,更新软件列表。

按理说应该可以了,但是有一些问题我用了一天也没有解决,这里记录下,等下次解决了才能修改。


目前存在的问题:

1.使用apt-mirror同步镜像源存在问题:

同步过程提示:

# apt-mirror
Downloading 38 index files using 20 threads...
Begin time: Fri May 1 19:47:35 2020
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Fri May 1 19:47:41 2020

Processing translation indexes: [T]

Downloading 0 translation files using 0 threads...
Begin time: Fri May 1 19:47:41 2020
[0]...
End time: Fri May 1 19:47:41 2020

Processing DEP-11 indexes: [D]

Downloading 0 dep11 files using 0 threads...
Begin time: Fri May 1 19:47:41 2020
[0]...
End time: Fri May 1 19:47:41 2020

apt-mirror: can't open index raspbian.raspberrypi.org/raspbian//dists/buster/main/binary-arm64/Packages in process_index at /usr/bin/apt-mirror line 800, <STREAM> chunk 1504.
apt-mirror: can't open index raspbian.raspberrypi.org/raspbian//dists/buster/contrib/binary-arm64/Packages in process_index at /usr/bin/apt-mirror line 800, <STREAM> chunk 1504.
apt-mirror: can't open index raspbian.raspberrypi.org/raspbian//dists/buster/non-free/binary-arm64/Packages in process_index at /usr/bin/apt-mirror line 800, <STREAM> chunk 1504.
apt-mirror: can't open index raspbian.raspberrypi.org/raspbian//dists/buster/rpi/binary-arm64/Packages in process_index at /usr/bin/apt-mirror line 800, <STREAM> chunk 1504.
Processing indexes: [P]

0 bytes will be downloaded into archive.
Downloading 0 archive files using 0 threads...
Begin time: Fri May 1 19:47:41 2020
[0]...
End time: Fri May 1 19:47:41 2020

0 bytes in 0 files and 0 directories can be freed.
Run /mnt/var/clean.sh for this purpose.

Running the Post Mirror script ...
(/mnt/var/postmirror.sh)

/bin/sh: 0: Can't open /mnt/var/postmirror.sh

Post Mirror script has completed. See above output for any possible errors.

出现了无法下载的情况,导致镜像源同步不完全。

2.可能由于镜像源同步 不完全的原因,造成树莓派更新出问题,如下:

$ sudo apt-get update
获取:1 http://121.36.81.4/raspbian/raspbian buster InRelease [15.0 kB]
忽略:2 http://121.36.81.4/raspbian/raspbian buster/main armhf Packages                      
命中:3 http://archive.raspberrypi.org/debian buster InRelease
忽略:4 http://121.36.81.4/raspbian/raspbian buster/contrib armhf Packages
忽略:5 http://121.36.81.4/raspbian/raspbian buster/non-free armhf Packages
忽略:6 http://121.36.81.4/raspbian/raspbian buster/rpi armhf Packages
忽略:2 http://121.36.81.4/raspbian/raspbian buster/main armhf Packages
忽略:4 http://121.36.81.4/raspbian/raspbian buster/contrib armhf Packages
忽略:5 http://121.36.81.4/raspbian/raspbian buster/non-free armhf Packages
忽略:6 http://121.36.81.4/raspbian/raspbian buster/rpi armhf Packages
错误:2 http://121.36.81.4/raspbian/raspbian buster/main armhf Packages
  404  Not Found [IP: 121.36.81.4 80]
忽略:4 http://121.36.81.4/raspbian/raspbian buster/contrib armhf Packages
忽略:5 http://121.36.81.4/raspbian/raspbian buster/non-free armhf Packages
忽略:6 http://121.36.81.4/raspbian/raspbian buster/rpi armhf Packages
正在读取软件包列表... 完成
E: 无法下载 http://121.36.81.4/raspbian/raspbian/dists/buster/main/binary-armhf/Packages  404  Not Found [IP: 121.36.81.4 80]
E: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。

原创文章,转载请注明: 转载自科技爱好者博客

本文链接地址: 搭建一个树莓派的开源镜像站 (https://www.lxx1.com/5106)

如果博客对您有帮助,请给我 赞助


热度:474℃

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据