1 mirror本地倉庫
1.1 背景
如果存在無法連接公網的情況並且有多臺服務器需要安裝多個軟件,可以使用mirror做一個本地倉庫,使其其他機器可以通過本地倉庫下載需要的軟件,本地倉庫需要使用Apache2,具體配置可以參考下面的Apache2。
1.2 配置過程
- 安裝mirror
sudo apt-get install apt-mirror #安裝mirror
- 修改配置文件
sudo vim /etc/apt/mirror.list #修改mirror配置文件
按照如下的配置修改地址,軟件園下載的地址爲阿里的,此地址不包含src源碼文件
############# 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 <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
# 下載線程數
set nthreads 20
set _tilde 0
#
############# end config ##############
#deb http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
#clean http://archive.ubuntu.com/ubuntu
# Aliyun(這裏沒有添加deb-src的源)
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
clean http://mirrors.aliyun.com/ubuntu
- 執行apt-mirror
sudo apt-mirror
注:執行完成後會下載mirrors.aliyun.com的包到/var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu的默認目錄上。
2 apache2
- 安裝apache2
sudo apt-get instal
如果Apache2安裝完成,可以通過瀏覽器訪問IP+port形式訪問(默認的port是80),如果安裝成功會出現Apache2的頁面
- 建立軟連接
由於Apache2的默認網頁文件目錄位於/var/www/html,因此,可以需要做個軟鏈接,這樣就可以直接訪問了,無需將其直接導入該目錄
sudo ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu /var/www/html/Ubuntu
如果想要刪除軟連接的話,執行sudo rm -rf /var/www/html/Ubuntu
即可
- 客戶端配置
修改/etc/apt/source.list配置,將之前的訪問地址註釋,新增自己的地址
# Local Source ip和port是自己本機的,其中端口默認爲80
deb [arch=amd64] http://ip:port/ubuntu/ trusty main restricted universe multiverse
deb [arch=amd64] http://ip:port/ubuntu/ trusty-security main restricted universe multiverse
deb [arch=amd64] http://ip:port/ubuntu/ trusty-updates main restricted universe multiverse
deb [arch=amd64] http://ip:port/ubuntu/ trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://ip:port/ubuntu/ trusty-backports main restricted universe multiverse
- 客戶端執行apt update
sudo apt-get update # 或者 sudo apt update