天天看點

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