1. 程式人生 > 其它 >Ubuntu2004製作本地源併發布

Ubuntu2004製作本地源併發布

1、安裝apt-mirror
apt-get install apt-mirror
2、修改apt-mirror配置檔案
在修改配置檔案之前,我們首先要確定自己系統的版本,命令:sudo lsb_release -a

$sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial
Codename代號的意思,16.04代號xenial,所以我們接下來的配置檔案跟xenial有關,當然14.04代號是trusty,一樣的操作。
開啟 阿里雲源(也可以使用別的源,網址可以自己百度)
進入dists目錄,在目錄下找到跟系統代號相關問資料夾,一般是5個,將下面規則文字複製出來,把加粗部分替換成相應的5個檔案目錄名。進入這5個目錄,裡面有4個跟源有關的目錄(by-hash除外),目錄名與下面斜體部分比較,如果不一樣請修改。

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

然後

vim /etc/apt/mirror.list

參考以下配置檔案:
清空原有的配置檔案,修改以下配置檔案相應代號部分即可,如果想新增多個版本的源,可以依次在下面增加相應的規則(就是增加對應代號的源地址)

############# config ##################
# 以下注釋的內容都是預設配置,如果需要自定義,取消註釋修改即可
set base_path /var/spool/apt-mirror
#
# 映象檔案下載地址
# set mirror_path $base_path/mirror
# 臨時索引下載檔案目錄,也就是存放軟體倉庫的dists目錄下的檔案(預設即可)
# set skel_path $base_path/skel
# 配置日誌(預設即可)
# set var_path $base_path/var
# clean指令碼位置
# set cleanscript $var_path/clean.sh
# 架構配置,i386/amd64,預設的話會下載跟本機相同的架構的源
set defaultarch amd64
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
# 下載執行緒數
set nthreads 20
set _tilde 0
#
############# end config ##############
# Ali yun(這裡沒有新增deb-src的源)
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

3、開始同步
執行 apt-miiror

然後等待很長時間(該映象差不多100G左右,具體時間看網路環境),同步的映象檔案目錄為/var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu/,當然如果增加了其他的源,在/var/spool/apt-mirror/mirror目錄下還有其他的地址為名的目錄。

注意:當apt-mirror 被意外中斷時,只需要重新執行即可,apt-mirror支援斷點續存;另外,意外關閉,需要在/var/spool/apt-mirror/var目錄下面刪除 apt-mirror.lock檔案【 sudo rm apt-mirror.lock 】,之後執行apt-mirror重新啟動

4、安裝apache2
apt-get install apache2

由於Apache2的預設網頁檔案目錄位於/var/www/html,因此,可以做個軟連結(這樣我們就可以直接訪問了,無需將其直接匯入該目錄)

ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu

然後就可以通過如下地址訪問了

http://127.0.0.1/ubuntu
#ip和port是自己本機的,其中埠預設為80
在測試時可能遇到打不開的情況,檢視下iptables規則是否限制或者selinux的問題(這點相信大家在學習lanmp的時候都已經瞭解過了)

客戶端配置:
1、編輯/etc/apt/source.list,參考以下內容(以下是64位機,ubuntu16.04),修改相應的代號,硬體架構arch,加入檔案中

# Local Source      #ip和port是自己本機的,其中埠預設為80
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-security main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-updates main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-proposed main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-backports main restricted universe multiverse

2、更新apt-get源

sudo apt-get update    #這步很重要
sudo apt-get upgrade

執行apt-get update時,本身amd64的系統,竟然找i386的package,例如:

Reading package lists... Done
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-security/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-updates/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-proposed/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-backports/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.

此時,需要修改/etc/apt/sources.list檔案,指定架構即可

# Local Source      #ip和port是自己本機的,其中埠預設為80
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-security main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-updates main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-proposed main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-backports main restricted universe multiverse