mkdir /data/16.04
mkdir /data/16.04/mirror
mkdir /data/16.04/var
mkdir /data/16.04/skel
mkdir /data/14.04
mkdir /data/14.04/mirror
mkdir /data/14.04/var
mkdir /data/14.04/skel
mkdir /data/12.04
mkdir /data/12.04/mirror
mkdir /data/12.04/var
mkdir /data/12.04/skel
2、安装mirror
apt-get install apt-mirror
3、修改配置文件
vim /etc/apt/mirror.list
cp /etc/apt/mirror.list /etc/apt/mirror.list.14.04
cp /etc/apt/mirror.list /etc/apt/mirror.list.16.04
cp /etc/apt/mirror.list /etc/apt/mirror.list.12.04
mirror.list修改如下(16.04为例)
#指定下载目录
set base_path /data/16.04
#指定下载的版本
set defaltarch amd64
#指定同步源(找的aliyun的)
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
clean http://mirrors.aliyun.com/ubuntu
其他文件按此修改,不同的是下载目录和同步源中 xenial 代表16.04,需替换成对应版本的Codename
网上找了下,各版本对应如下
版本号 Codename
11.04: natty16.10: yakkety
或者在ubuntu中允许 lsb_release -a查询
4、启动同步及编辑同步定时任务
apt-mirror 即可立刻同步
vi /etc/crontab
增加一行,每天凌晨1点开始同步(需建立对应的日志目录)
0 1 * * * root /etc/apt/mirrorcron.sh &>/var/log/mirror/cron.log 2>&1
在/etc/apt/下建立mirrorcron.sh,内容如下:
#!/bin/bash
/bin/cp -rf /etc/apt/mirror.list.16.04 /etc/apt/mirror.list
/usr/bin/apt-mirror
/bin/cp -rf /etc/apt/mirror.list.14.04 /etc/apt/mirror.list
/usr/bin/apt-mirror
/bin/cp -rf /etc/apt/mirror.list.12.04 /etc/apt/mirror.list
/usr/bin/apt-mirror
5、安装apache2
具体不描述了,更改端口为8080,更改目录为/data
至此,可通过http://你的ip:8080 访问页面
6、安装nginx
安装过程不描述,修改配置文件如下
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
gzip on;
gzip_disable "msie6";
upstream apt-yum
{
server 10.100.6.7:8080;
}
在 server { 中增加
location /ubuntu/14.04/ {
proxy_pass http://apt-yum/14.04/mirror/mirrors.aliyun.com/ubuntu/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
location /ubuntu/16.04/ {
proxy_pass http://apt-yum/16.04/mirror/mirrors.aliyun.com/ubuntu/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
location /ubuntu/12.04/ {
proxy_pass http://apt-yum/12.04/mirror/mirrors.aliyun.com/ubuntu/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
7、修改sources.list
其他安装源都注释掉,增加如下行(以14.04为例)
deb [arch=amd64] http://服务器IP或域名/ubuntu/14.04 trusty main restricted universe multiverse
deb [arch=amd64] http://服务器IP或域名/ubuntu/14.04 trusty-security main restricted universe multiverse
deb [arch=amd64] http://服务器IP或域名/ubuntu/14.04 trusty-updates main restricted universe multiverse
deb [arch=amd64] http://服务器IP或域名/ubuntu/14.04 trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://服务器IP或域名/ubuntu/14.04 trusty-backports main restricted universe multiverse
8、替换客户端
将修改后的sources.list替换至其他ubuntu,执行apt update即可