1. 环境准备
安装nginx,reprepro,gnupg软件。
工具名称 | 作用 | 备注 |
---|---|---|
nginx | 高性能的Web服务器。 | 必须 |
reprepro | 生成和管理Debian软件包系统信息库的工具。 | 必须 |
gnupg | 用于加密、 数字签名及产生非对称钥匙对的软件。 | 非必须 |
$ sudo apt-get install nginx reprepro gnupg
2. 配置nginx
删除nginx默认的index.html文件。
$ sudo rm /var/www/html/index.nginx-debian.html
修改默认配置。
$ sudo vim /etc/nginx/sites-enabled/default
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
修改完配置文件后,通过如下命令,检查配置是否正确。需要注意从其他地方拷贝配置文件可能会引入特殊的不可见的字符,导致检查配置失败,根据错误提示修改配置文件。
sudo nginx -t
nginx的停止和重启命令如下。
$ sudo nginx -g reload # 重新加载配置文件
$ sudo nginx -g stop # 停止nginx服务
修改nginx文件夹的主属和组属,方便后续在该目录下建立文件夹和各种操作。
$ ls /var/www/html -al
总用量 8
drwxr-xr-x 2 root root 4096 1月 14 14:17 .
drwxr-xr-x 3 root root 4096 1月 14 14:05 ..
$ sudo chown xiao:xiao /var/www/html -R
$ ls /var/www/html -al
总用量 8
drwxr-xr-x 2 xiao xiao 4096 1月 14 14:17 .
drwxr-xr-x 3 root root 4096 1月 14 14:0
3. 配置Deb软件仓库
3.1 仓库配置文件
在/var/www/html/ppa/uranus/conf/目录下新建配置文件,名为distributions。基础配置参考如下:
Codename: uranus
Update: update_from_base
Architectures: amd64 source
Components: main contrib non-free
#SignWith:
Description: private debian packages
Log: ppa.log
重要的配置字段解释:
字段 | 说明 |
---|---|
Codename | 版本的代号,对应/etc/apt/source.list中URL的相关字段,非常重要。 |
Update | 仓库同步的策略,会在conf/updates文件中寻找对应Name的同步策略配置。如果配置了多个同步策略,则依次执行。 |
Architectures | 仓库中deb包支持的架构,包括i386,amd64,mips64,sw_64 source。需要根据实现情况填写,支持什么架构添加什么架构。 |
Components | 仓库中deb包的组件类型,包括main,contrib,non-free。 |
3.2 仓库同步配置文件
在/var/www/html/ppa/uranus/conf/目录下新建同步配置文件,名为updates。基础配置参考如下:
Name: update_from_base
Suite: testing
Architectures: amd64 source
Components: main contrib non-free
#Method: file:///...
Method: http://...
VerifyRelease: blindtrust
重要的配置字段解释:
字段 | 说明 |
---|---|
Name | 同步策略名称,对应conf/distributions文件中的Update字段,用于区分不同的同步策略。 |
Suite | 发型版本。可以简单理解为上游仓库的Codename的值。 |
Architectures | 同步的架构,需要确认上游仓库支持的架构和当前仓库需要同步的架构。 |
Components | 同步的组件,需要确认上游仓库支持的组件和当前仓库需要同步的组件。 |
Method | 同步的上游仓库URL地址或是本地仓库地址。 |
4. Deb仓库相关操作
仓库的主要目录结构如下所示,
uos@uos-PC:/var/www/html/ppa$ tree -d -L 3
.
└── uranus
├── conf
├── db
├── dists
│ └── uranus
├── lists
└── pool
├── contrib
├── main
└── non-free
则仓库的地址为 ${DEB_ARCHIVE} = /var/www/html/ppa/uranus
在终端中,将当前目录移动到${DEB_ARCHIVE},后续相关命令都将基于这个路径进行操作,或者在紧接着reprepro后添加-b ${DEB_ARCHIVE}选项,指定仓库地址。
4.1 添加Deb包
Syntax: reprepro [--delete] includedeb <distribution> <.deb-file>
4.2 删除Deb包
Syntax: reprepro [-C <component>] [-A <architecture>] [-T <type>] remove <codename> <package-names>
4.3 同步Deb仓库
Syntax: reprepro update <codename>
4.4 查看Deb仓库中的Deb包
Syntax: reprepro [-C <component>] [-A <architecture>] [-T <type>] list <codename> [<package-name>]
5. 测试Deb仓库
修改测试机器上的/etc/apt/source.list文件为你需要测试的Deb仓库地址。
$ cat /etc/apt/sources.list
deb [trusted=yes] http://10.4.11.182/ppa/uranus uranus main contrib non-free
deb-src [trusted=yes] http://10.4.11.182/ppa/uranus uranus main contrib non-free
之后执行相关命令,检查仓库是否搭建成功。
$ sudo apt-get update
$ sudo apt-cache policy deepin-terminal
6. FAQ
6.1 同步上游仓库时,没有显示同步进度,如何确认是否在同步中?
当我们同步上游仓库时,如果上游仓库很大,终端页面会一直卡在Getting packages…阶段。
如果在conf/distributions文件中配置了Log属性,则可以在conf的同级目录中找一个名为logs的目录,可以查看目录中的日志,日志中输出当前同步的时间和deb包名。
如果没有在conf/distributions文件中配置了Log属性,则在conf上级目录中执行如下命令:
du -h . --max-depth=0
如果文件夹大小一直在增加,则说明同步仍在继续,耐心等待即可。