公司有多台Ubuntu機器,而且不能連接互聯網,導致安裝軟件和更新都比較麻煩,需要建立一台本地更新源服務器。
1.安裝apt-mirror工具
sudo apt-get install -y apt-mirror
2.配置apt-mirror工具
sudo gedit /etc/apt/mirror.list
修改更新源地址為阿里雲鏡像地址,下載速度更快。
如果只下載64位的更新,在執行apt-get update時會報錯,因此把32位的一起加進來,這樣就不會報錯了。
下面注釋掉的5行是源碼,一般不需要,如果有需要,去掉注釋就可以一起下載了。
3.開始制作,64位的更新大約有114G,32位的大約有58G。
sudo apt-mirror
4.添加定時任務每日自動更新鏡像
sudo crontab -e
Choose 1-3 [2]:2
在文件最下面加入如下配置:每天1:30自動更新,並且把更新日志記錄在cron.log
30 1 * * * /usr/bin/apt-mirror >> /var/spool/apt-mirror/var/cron.log
5.作為本機源
下載到本機的更新內容在 /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu,執行如下命令修改sources.list
sudo gedit /etc/apt/sources.list
把原有內容替換為以下內容:
deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu xenial main restricted universe multiverse
deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu xenial-security main restricted universe multiverse
deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu xenial-updates main restricted universe multiverse
deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu xenial-proposed main restricted universe multiverse
deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu xenial-backports main restricted universe multiverse
6.作為局域網源
安裝apache2(如果沒有的話)
sudo apt-get install -y apache2
將鏡像目錄鏈接到apache2的根目錄(/var/www/html/)下
ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu
7.修改局域網內其他ubuntu主機的sources.list文件
執行如下命令修改sources.list
gedit /etc/apt/sources.list
把原有內容替換為以下內容,其中xxx.xxx.xxx.xxx為本地更新源服務器的IP地址
deb http://xxx.xxx.xxx.xxx/ubuntu xenial main restricted universe multiverse
deb http://xxx.xxx.xxx.xxx/ubuntu xenial-security main restricted universe multiverse
deb http://xxx.xxx.xxx.xxx/ubuntu xenial-updates main restricted universe multiverse
deb http://xxx.xxx.xxx.xxx/ubuntu xenial-proposed main restricted universe multiverse
deb http://xxx.xxx.xxx.xxx/ubuntu xenial-backports main restricted universe multiverse