1. 程式人生 > >Ubuntu建立本地apt源

Ubuntu建立本地apt源

參考連結:

根據實際的部署,總結兩條apt本地源配置方法。
本地主機IP:
lo: 127.0.0.1
eth0: 10.10.1.5

一、reprepro方式

(1) 安裝支援包reprepro, nginx

$ sudo apt-get install reprepro nginx 

(2) 建立目錄及配置reprepro

$ sudo mkdir -p /srv/reprepro/ubuntu/{conf,dists,incoming,indices,logs,pool,project,tmp}
$ cd /srv/reprepro/ubuntu/
$ sudo chown -R `whoami` . 
$ cat /srv/reprepro/ubuntu/conf/distributions

Origin: Vivid
Label: Main
Codename: vivid
Architectures: i386 amd64 source
Components: main
Description: Ubuntu Main
SignWith: YOUR-KEY-ID
$ cat /srv/reprepro/ubuntu/conf/options

ask-passphrase
basedir .

(3) 匯入下載的deb包

$ reprepro includedeb vivid /path/to/my-package_0.1-1.deb

\

(4)配置nginx服務

# cat /etc/nginx/sites-available/vhost-packages.conf

server {
  listen 8082;
  server_name packages.ubuntu;

  access_log /var/log/nginx/aptSource-access.log;
  error_log /var/log/nginx/aptSource-error.log;

  location / {
    root /srv/reprepro;
    index index.html;
  }

  location ~ /(.*)/conf
{ deny all; } location ~ /(.*)/db { deny all; } }
# cat  /etc/nginx/conf.d/server_names_hash_bucket_size.conf

server_names_hash_bucket_size 64;

載入配置檔案,重啟nginx服務

# ln -s /etc/nginx/sites-available/packages.ubuntu.conf /etc/nginx/site-enabled/
# service nginx restart

(5) 配置客戶端apt原始檔

# cat /etc/hosts
...
<IPADDRESS of apt source>    packages.ubuntu
...

# cat /etc/apt/sources.list.d/packages.ubuntu.list 

deb http://packages.ubuntu/ubuntu/ vivid main
$ sudo apt-get update

二、 apt-mirror方式

(1) 安裝apt-mirror、nginx

$ sudo apt-get install apt-mirror nginx -y

(2) 配置apt-mirror

# cat /etc/apt/mirror.list | egrep -v '^$|^#' 
set base_path    /var/spool/apt-mirror
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 nthreads     20
set _tilde 0
deb http://ubuntu-cloud.archive.canonical.com/ubuntu trusty-updates/kilo main
clean http://ubuntu-cloud.archive.canonical.com/ubuntu

(3) 從雲端同步deb包

# apt-mirror -c apt-mirror

Downloading 14 index files using 14 threads...
Begin time: Mon Jun 22 21:40:05 2015
[14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... 
End time: Mon Jun 22 21:40:17 2015

Processing tranlation indexes: [T]

Downloading 0 translation files using 0 threads...
Begin time: Mon Jun 22 21:40:17 2015
[0]... 
End time: Mon Jun 22 21:40:17 2015

Processing indexes: [P]

1.3 GiB will be downloaded into archive.
Downloading 491 archive files using 20 threads...
Begin time: Mon Jun 22 21:40:17 2015
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... 

(4) 新增目錄軟連線,配置nginx

# ln -s /var/spool/apt-mirror/mirror/ubuntu-cloud.archive.canonical.com/ubuntu/ /var/www/html/ubuntu-cloud

# ls -l /var/www/html
lrwxrwxrwx 1 root root    65 Jun 29 21:17 ubuntu-cloud -> /var/spool/apt-mirror/mirror/ubuntu-cloud.archive.canonical.com/ubuntu/

Configured file: /etc/nginx/site-available/default
# egrep -v '^$|^#|#' /etc/nginx/site-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
+++
+++ location /ubuntu-cloud {
+++          autoindex on;
+++ }
}

# service nginx restart

(6) 從本地apt源安裝軟體包

# echo  "10.10.1.5    cn.archive.ubuntu.com" >> /etc/hosts
# mv /etc/apt/sources.list{,.off}
# echo "deb http://cn.archive.ubuntu.com/ubuntu trusty-updates/kilo main" > /etc/apt/sources.list
# apt-get update 

其他可以正常訪問apt源主機的Ubuntu主機均可將源指向它。