1. 程式人生 > >Ubuntu16.04.02 本地源

Ubuntu16.04.02 本地源

由於某些特殊的原因,需要在ubuntu下安裝一些包,但是網路環境特差,或者根本上不了外網(比如去某些礦裡做專案),這時候只能製作本地源解決這些問題了
優點:

  • 速度快
  • 使用方便
  • 能夠保證安裝的版本絕對一致

環境準備

  • 建一個ubuntu虛擬機器(乾淨的系統,這個系統和生產環境的要一樣)
  • 更改sources.list
# 備份一下
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

安裝包下載

這裡沒有多說的地方,只有一條,要使用下載模式,如果不用的話,可能會有很多包不在/var/cache/apt/archives/ 下面
例如,下載一個pip
~:sudo apt-get -d install python-pip
注意 -d 別忘記新增

本地源指令碼

#!/bin/bash

# 移除soft和dists(這樣做是以後新增新的包準備的)
rm -r /var/www/html/soft

rm -r /var/www/html/dists

mkdir /var/www/html/dists

mkdir /var/www/html/dists/lucid

mkdir /var/www/html/dists/lucid/main

mkdir /var/www/html/dists/lucid/main/binary-i386

mkdir /var/www/html/dists/lucid/main/binary-amd64

# 連結
mkdir /var/www/html/soft/
ln -s /var/cache/apt/archives/* /var/www/html/soft/

cd /var/www/html/

dpkg-scanpackages soft/ /dev/null | gzip > /var/www/html/dists/lucid/main/binary-i386/Packages.gz

dpkg-scanpackages soft/ /dev/null | gzip > /var/www/html/dists/lucid/main/binary-amd64/Packages.gz

cd -

儲存為build_local_packages.sh
執行指令碼 . build_local_packages.sh 這樣,你可以通過瀏覽器驗證本地源是否可以訪問
http://ip/soft

客戶端使用

客戶端使用很簡單 vi /etc/apt/sources.list 清空,新增下面這句話

deb [arch=amd64] http://192.168.10.198 lucid main

之後
apt-get update

注意:add-apt-repository 這個功能在客戶機上最好別用,因為不能上網,會影響apt-get update
ps:我沒細研究