使用本地包搭建私有 apt 仓库
这里的 server 指的是提供 apt 仓库服务的机器,client 指的是要访问 apt 仓库的机器
- (server) 生成 GPG 私钥
- (server) 使用 aptly 添加包,并生成仓库的 snapshot
- (server) 使用 nginx 搭建私有的服务器,存放生成的 snapshot
- (client) 修改 apt 配置
运行命令:gpg --full-gen-key
,按照提示操作。
最后将在~/.gnupg/openpgp-revocs.d/
目录下生成.rev
的 key 文件
安装 aptly 后,创建仓库,本步骤执行后将生成~/.aptly
目录
# 请拓展尖括号的内容, 示例如下
# aptly repo create -architectures riscv64 -comment 'private riscv64 repo' -component main -distribution rockos-private my_repo
aptly repo create -architectures <arch> -comment <your_comment> -component <component> -distribution <distrubution> <repo_name>
向仓库内添加若干包,本步骤执行后将在~/.aptly/pool
目录下存放所添加包的拷贝
aptly repo add <repo_name> <pkg_path>
创建仓库 snapshot 并发布,此过程会要求使用 GPG 私钥签名,所以会提示输入生成 GPG 私钥时的密码
snapshot 发布后的目录为~/.aptly/public
aptly snapshot create <snapshot_name> from repo <repo_name>
aptly publish -architectures <arch> snapshot <snapshot_name>
使用 nginx 搭建文件服务器,使得外部网络可以访问仓库内容
sudo apt-get install nginx -y
编辑/etc/nginx/sites-enabled/default
,将root /var/www.html;
中的地址修改为 snapshot 发布后的目录。并在其下方添加autoindex on;
一项
重启 nginx
sudo systemctl restart nginx.service
最后用浏览器访问一下服务器IP,验证是否搭建成功
在/etc/apt/sources.list
中写入如下一行
# 例如,我这边的是 deb [trusted=yes] http://10.9.127.200/public/ unstable main
deb [trusted=yes] <server_path> <distrubution> <component>
# 如果添加了源码包的话,还可以继续添加如下一行
# deb-src [trusted=yes] <server_path> <distrubution> <component>
需要先 drop 掉原先已经 publish 的 snapshot
aptly publish drop <distrubution> .
直接repo add
目标包的.dsc
文件即可,aptly 会自动添加源码包
最后附上自己在用的脚本,可以较为方便地添加新包并发布,使用前请适当修改
#!/bin/bash
set -x
# please modify this
REPO="rerererererepo"
DISTRIBUTION="dididididistribution"
SNAPSHOT=$(date "+%m%d_%M%S")
aptly publish drop $DISTRIBUTION .
aptly repo add $REPO $(ls | grep -E "\.deb$" | tr "\n" " ") $(ls | grep -E "\.dsc$" | tr "\n" " ")
aptly snapshot create $SNAPSHOT from repo $REPO
aptly publish -distribution=$DISTRIBUTION snapshot $SNAPSHOT