ubuntu16.04本地軟件源搭建


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

 

 

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

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

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

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

服務端安裝下載鏡像,安裝apache 來共享,也可以用FTP

客戶端配置服務端的地址 來安裝軟件包

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/ubu... xenial  main restricted universe multiverse
deb  http://mirrors.aliyun.com/ubu... xenial-security  main restricted universe multiverse
deb  http://mirrors.aliyun.com/ubu... xenial-updates  main restricted universe multiverse
deb  http://mirrors.aliyun.com/ubu... xenial-proposed  main restricted universe multiverse
deb  http://mirrors.aliyun.com/ubu... 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

然后等待很長時間(該鏡像差不多150G左右,具體時間看網絡環境),同步的鏡像文件目錄為/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

 

(3)將原來的文件進行備份,配置ubuntu軟件源地址。

    

//備份文件

cp /etc/apt/sources.list /etc/apt/sources.list.bak

//配置文件

gedit /etc/apt/sources.list

將里面的文件內容全部替換成如下內容后,保存退出:

deb [arch=amd64] http://10.2.4.119/ubuntu/ xenial main restricted universe multiverse

deb [arch=amd64] http://10.2.4.119/ubuntu/ xenial-security main restricted universe multiverse

deb [arch=amd64] http://10.2.4.119/ubuntu/ xenial-updates main restricted universe multiverse

deb [arch=amd64] http://10.2.4.119/ubuntu/ xenial-proposed main restricted universe multiverse

deb [arch=amd64] http://10.2.4.119/ubuntu/ xenial-backports main restricted universe multiverse

 

(4)清除更新軟件緩存

     rm -rf /etc/apt/sources.list.d/*

 

2、更新apt-get源

sudo apt-get update     

 

 測試軟件可以正常離線安裝

 

 



 

 



參考和轉載https://segmentfault.com/a/1190000019829407?utm_source=tag-newest 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM