close

現場(環境):Ubuntu 14.04

專案套件: apt-repository、apt-mirror

 

 

筆錄(原因):

網路上的APT平台 穩定的時候都沒事,但一當有狀況的時候要更新或下載都有困難。

舊的系統在網路上的資源平台位置還會隨著時代修正,之後還得一直去改apt內的設定才能抓到資源,太麻煩了。

所以自己建立自己的資源平台吧。

注意事項: Ubuntu 14.04  版本的套件大小要同步下來大約需要155GB的空間。(當APT伺服器的主機空間要夠大)


處理:

同步APT 套件

下載用來同步線上APT Server 的套件

joe@joe-OptiPlex-7010:~$ sudo apt-get install apt-mirror

建立一個資料夾做為存放APT套件的路徑

本例存放於:/debinfo

修改資料儲存路徑

joe@joe-OptiPlex-7010:~$ sudo vim /etc/apt/mirror.list

############# config ##################

# set base_path    /var/spool/apt-mirror

set base_path    /debinfo


開始同步(因為是第一次同步,所以需要花很多時間,大概半天~一天不等)

joe@joe-OptiPlex-7010:~$ sudo apt-mirror

Downloading 162 index files using 20 threads...

Begin time: Wed Apr 12 10:31:29 2017

[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...

End time: Wed Apr 12 10:35:03 2017

Processing tranlation indexes: [TTT]

Downloading 201 translation files using 20 threads...

Begin time: Wed Apr 12 10:35:03 2017

[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...

End time: Wed Apr 12 10:36:30 2017

Processing indexes: [SSSPPP]

155.1 GiB will be downloaded into archive. 

(會抓下來155.1GB的檔案資料; 當APT伺服器的空間要夠大!)

Downloading 124295 archive files using 20 threads...

Begin time: Wed Apr 12 10:36:36 2017

[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...

End time: Thu Apr 13 05:23:55 2017

0 bytes in 0 files and 0 directories can be freed.

Run /debinfo/var/clean.sh for this purpose.

Running the Post Mirror script ...

(/debinfo/var/postmirror.sh)

出現問題:

/bin/sh: 0: Can't open /debinfo/var/postmirror.sh

Post Mirror script has completed. See above output for any possible errors.


joe@joe-OptiPlex-7010:~$

網路上提供的解法:

Troubleshooting

If you get this error when the mirroring is done,

/bin/sh: 0: Can't open /var/www/ubuntu_mirror/var/postmirror.sh

create the postmirror script as shown below,

cd /var/www/ubuntu_mirror/var/

vi postmirror.sh

#!/bin/sh

/var/www/ubuntu_mirror/var/clean.sh

#rsync -avz --bwlimit=512 rsync://fr.archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64 /var/www/

rsync -avz --bwlimit=512 rsync://de.archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64 /var/www/

chmod +x postmirror.sh

Note. you cannot put installer-amd64 into the mirror otherwise it will get wiped out by clean.sh.

所以先創建這個檔案

joe@joe-OptiPlex-7010:~$ vim /debinfo/var/postmirror.sh

再裡面輸入上述內容

###!###################################################

/debinfo/var/clean.sh

 

#rsync -avz --bwlimit=512 rsync://fr.archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64 /var/www/

 

rsync -avz --bwlimit=512 rsync://de.archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64 /var/www/

###!###################################################


接著再使用一次apt-mirror進行同步

joe@joe-OptiPlex-7010:/debinfo/var$ sudo apt-mirror

Downloading 162 index files using 20 threads...

Begin time: Thu Apr 13 08:56:25 2017

[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...

End time: Thu Apr 13 08:56:42 2017

Processing tranlation indexes: [TTT]

Downloading 201 translation files using 20 threads...

Begin time: Thu Apr 13 08:56:42 2017

[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...

End time: Thu Apr 13 08:56:51 2017

Processing indexes: [SSSPPP]

0 bytes will be downloaded into archive.

Downloading 0 archive files using 0 threads...

Begin time: Thu Apr 13 08:56:57 2017

[0]...

End time: Thu Apr 13 08:56:57 2017

0 bytes in 0 files and 0 directories can be freed.

Run /debinfo/var/clean.sh for this purpose.

Running the Post Mirror script ...

(/debinfo/var/postmirror.sh)

Removing 0 unnecessary files [0 bytes]...

done.

Removing 0 unnecessary directories...

done.

Welcome to the FTP Server of the Department of Computer Science,

                                  Technische Universitaet Dresden, Germany.

Contact: ftpadm@inf.tu-dresden.de

 Hint: Don't use checksum'ing (-c), it's disabled.

Module          | Content and size

----------------+------------------------------------------------

成功就會開始跑下列下載及安裝

receiving incremental file list

installer-amd64/

installer-amd64/current -> 20101020ubuntu399

installer-amd64/20101020ubuntu397/

...

...

...

installer-amd64/20101020ubuntu399/images/netboot/xen/vmlinuz -> ../ubuntu-installer/amd64/linux

installer-amd64/20101020ubuntu399/images/netboot/xen/xm-debian.cfg

sent 2,957 bytes  received 535,286,850 bytes  321,013.38 bytes/sec

total size is 573,132,382  speedup is 1.07

Post Mirror script has completed. See above output for any possible errors.

到這邊就APT 檔案就算同步完成。


設定每天排程

因為未來仍會有後續跟新檔的問題,所以要設定排程進行每天同步。

然後將排程更新狀況寫入日誌當中,讓我們去確認狀況。

#vim /etc/crontab

30 5 * * * root  /usr/bin/apt-mirror >> /var/spool/apt-mirror/var/cron.log

 


設定Web Service

接著就是做讓他人下載的web Service

#apt-get install apache2

 

一、直接做LINK/var/www下面比較簡單 (比較建議)

joe@joe-OptiPlex-7010:/debinfo/var$ sudo ln -s /debinfo/mirror/archive.ubuntu.com/ubuntu /var/www/ubuntu

然後一樣修改路徑

把下面框起來的地方的 # 拿掉。

 ServerAdmin webmaster@localhost

 DocumentRoot /var/www

 

二、

或者修改路徑

joe@joe-OptiPlex-7010:/debinfo/var$ vim /etc/apache2/sites-enabled/000-default.conf

#!###########################################################

        ServerAdmin webmaster@localhost

#       DocumentRoot /var/www/html

重點是這一行,其他的可以考慮加進來。

        DocumentRoot /debinfo/mirror/archive.ubuntu.com/

        <Directory />

                Options Indexes FollowSymLinks

                AllowOverride None

        </Directory>

        <Directory /debinfo/mirror/archive.ubuntu.com/>

                Options FollowSymLinks MultiViews

                AllowOverride None

                Order allow,deny

                allow from all

        </Directory>

 

#!#############################################################

修改完後重啟apache

#/etc/init.d/apache2 start

 

修改看看能不能取得自己的更新檔。


測試階段

1、本地連線測試

將APT伺服器的APT來源端修改為本地檔案位置 (所以前面是用file:來表示)

sudo vim /etc/apt/sources.list

修改成如下内容:

deb [ arch=amd64 ] file:/debinfo/mirror/archive.ubuntu.com/ubuntu trusty main restricted universe

deb [ arch=amd64 ] file:/debinfo/mirror/archive.ubuntu.com/ubuntu trusty-updates  main restricted universe

deb [ arch=amd64 ] file:/debinfo/mirror/archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse

更新软件源:

#sudo apt-get update

#######

發現錯誤。

W: Failed to fetch file:/debinfo/mirror/archive.ubuntu.com/dists/wheezy/main/binary-amd64/Packages  File not found

這樣表示路徑找不到,要修正一下

後面加上ubuntu資料夾位置才對。

/debinfo/mirror/archive.ubuntu.com/ubuntu

其他的錯誤。

W: Failed to fetch file:/debinfo/mirror/archive.ubuntu.com/ubuntu/dists/trusty/Release  Unable to find expected entry 'contrib/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)

代表我在client端的 /etc/apt/source.list路徑設定有錯誤

這邊要比照/etc/apt/mirror.list內的內容設定才對

###

deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse

###

因為ubuntu 14 是用trusty而非 contrib

修改完後目前都僅剩i386的檔案無法更新。

W: Failed to fetch file:/debinfo/mirror/archive.ubuntu.com/ubuntu/dists/trusty/universe/binary-i386/Packages  File not found

所以我們要再修改設定,讓他僅支援amd64位元,而不管i386

再我們的source.list的檔案上再加上

deb [ arch=amd64 ] http://local_apt_mirror/ubuntu/ trusty main restricted

下一個問題

W: Failed to fetch file:/debinfo/mirror/archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease  Unable to find expected entry 'multiversei/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)

發現是路徑設定錯誤,不小心多一個i

本機檔案設定測試成功後就要來看WEB端。


隨便找一台一樣是Ubuntu 14.04 版本的主機來測試看看。

看有沒有正確的透過web介面進行連接。

先透過瀏覽器確認能不能使用。

如果web瀏覽器打開發現下面錯誤

You don't have permission to access / on this server.

你再apt-update的時候會有一樣的狀況

W: Failed to fetch http://10.10.10.14/ubuntu/dists/trusty-security/universe/binary-amd64/Packages  403  Forbidden

這邊就要再去找文件解決apache2的問題。

如果更新狀況如下,就算是完成了。

joe@joe-OptiPlex-7010:~$ sudo apt-get updateIgn http://10.10.10.14 trusty InRelease

Hit http://10.10.10.14 trusty-updates InRelease               

Hit http://10.10.10.14 trusty-security InRelease               

Hit http://10.10.10.14 trusty Release.gpg                                  

Hit http://10.10.10.14 trusty Release                                      

Hit http://10.10.10.14 trusty-updates/main amd64 Packages                  

Hit http://10.10.10.14 trusty-updates/restricted amd64 Packages            

Hit http://10.10.10.14 trusty-updates/universe amd64 Packages              

Hit http://10.10.10.14 trusty-updates/main Translation-en                  

Hit http://10.10.10.14 trusty-updates/restricted Translation-en            

..................

Reading package lists... Done

 

這樣就WEB端就算完成了,可以開始試著從這台自己建立的APT Server更新或下載套件包來安裝了。

(專案結束)

 

 

 

 

arrow
arrow
    全站熱搜

    IT001 發表在 痞客邦 留言(0) 人氣()