前言
因外网不稳定,下载经常断连失败,所以需要用一台主机当服务器存放deb软件包,局域网内的其他主机可以通过这台主机下载安装包
在服务器上搭建apt源
1.在/usr/local/目录下新建一个localrepo文件夹存放本地deb包

2.将预先的准备好的deb包复制到该目录下

3.进入本地源目录,生成Packages和Release
cd /usr/local/localrepo
apt-ftparchive packages . > Packages
apt-ftparchive release . > Release
4.Ubuntu20版本,APT要求所有软件源都要经过数字签名,以确保软件包的完整性和安全性。我们要先安装gnupg软件包,为本地源创建GPG签名
sudo apt-get install gnupg
安装rng-tools,加快gpg密钥的生成速度,并设置让其在后台运行
apt install rng-tools
rngd -r /dev/urandom
生成GPG密钥
gpg --gen-key
注册时需要输入自己的用户名和邮箱,成功后输入ok(邮箱必须填真实的,之后他会向你发邮件)

进入密钥生成界面,输入自己想要设置的密钥

成功生成密钥

将密钥上传至GPG服务器,我这里选择的服务器是keys.openpgp.org

登录keys.openpgp.org,可以查询到密钥已经上传到服务器

过一段时间邮箱会收到一封信,告诉你有人用你的账户上传了密钥,点击信里的链接

继续向邮箱发送邮件

邮箱里收到一封新的邮件,点击确认,至此,GPG密钥配置完成


4.将公钥导入到本地,并为本地源配置数字签名
sudo apt-key adv --keyserver keys.openpgp.org --recv-keys 99EA1EF96C040B25

gpg -abs -o /usr/local/localrepo/Release.gpg /usr/local/localrepo/Release
输入刚才设置的密钥

5.编辑source.list,vim /etc/apt/source.list,向里面填加你本地存放源的地址
deb file:///usr/local/localrepo/ ./

6.输入命令apt update,测试本地源是否配置成功

测试本地源中的软件能否顺利安装

至此,本地源已经配置成功
在服务端配置apache2服务器,开放文件下载
1.在服务器上下载apache2服务器
apt install apache2
2.更改apache2.conf配置文件,vim /etc/apache2/apache2.conf,将目录访问权限都改成granted
<Directory />
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>


3.更改000-default.conf配置文件,vim /etc/apache2/sites-available/000-default.conf,在里面添加如下内容
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

重启apache2服务器
systemctl restart apache2
打开浏览器输入服务器ip地址发现apache2服务已经正常启动

在客户端配置,能通过服务端下载
1.将刚才在服务端生成的gpg公钥导入到客户端
sudo apt-key adv --keyserver keys.openpgp.org --recv-keys 99EA1EF96C040B25

2.更改source.list文件,vim /etc/apt/source.list,在里面添加服务器端的本地源地址
deb http://10.10.111.223/ /

3.执行apt update

4.通过apt install安装放在局域网服务器仓库里的deb包

至此,便完成了Ubuntu20局域网源的配置!
文章讲述了如何在Ubuntu20系统中建立本地APT源,包括创建存放deb包的目录,生成Packages和Release文件,使用gnupg生成GPG签名以确保安全,然后配置Apache2服务器以开放文件下载。在客户端,需要导入GPG公钥,修改source.list并更新源,从而实现通过服务端下载软件包。
&spm=1001.2101.3001.5002&articleId=129873143&d=1&t=3&u=1d60697932b247bcb16300125b3364e6)
3421

被折叠的 条评论
为什么被折叠?



