ubuntu下的apt內網本地源的正確搭建

爲什麼說正確搭建,是因爲搭建過程照搬網上的遇坑了,而且一次就是100g的量。不僅如此,16.04的系統使用14.04的源,提示執行apt-get install -f,這條命令千萬不要執行,我以後感覺都不敢使用這條命令了。在此記錄一下


參考至->,如果你係統是ubuntu14.04,照搬完全沒問題,但是現在ubuntu都18.04了,還要繼續更新,下面教你如何搭建所有版本的apt本地源。

APT本地源的搭建(可用於局域網apt-get源搭建或者本地源)

本文檔介紹使用apt-mirror軟件搭建apt本地源

需求:內網開發環境由於其特定原因不能上外網,所以需要本地環境下的內網源來方便開發人員下載安裝軟件
建議:單獨使用一塊磁盤來存放源文件或者單獨一個目錄下,避免混淆

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章