技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 硬件教程 >

怎么搭建本地Ubuntu鏡像服務(wù)器

來源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2018-06-28 00:09┆點(diǎn)擊:

  想要在電腦中安裝和搭建本地Ubuntu鏡像服務(wù)器,使得在安裝其他的常用工具時(shí)能減少時(shí)間!那么要怎么的搭建呢!我們一起來看看吧!

  一.需求分析

  最近公司軟件Team 有個(gè)需求是這樣的:能不能在局域網(wǎng)搭建一個(gè)Ubuntu 鏡像服務(wù)器,

  這樣作的好處是可以節(jié)省Ubuntu某些常用工具的安裝時(shí)間。

  二.部署過程

  2.1 測(cè)試環(huán)境

  目前在公司內(nèi)有一臺(tái)能連接到外網(wǎng)的Ubuntu機(jī)器, IP : 192.168.8.173 ,

  Ubuntu版本為Ubuntu 9.04 i686。

  2.2 搭建步驟

  為了創(chuàng)建Ubuntu mirror 服務(wù)器,最少需要60G硬盤空間,Ubuntu每個(gè)版本都有32 bit

  和64 bit兩個(gè)版本,有兩組deb包。當(dāng)然可以創(chuàng)建Ubuntu一個(gè)版本的32 bit 和64 bit 的

  鏡像服務(wù)器,也可以創(chuàng)建全部版本的鏡像。

  這里使用sohu 公司的mirror地址作為本地Ubuntu Source 服務(wù)器,使用sohu的原因是:

  1. sohu的Ubuntu Source 服務(wù)器速度相當(dāng)快

  2. sohu 的ubuntu Source 服務(wù)器每天會(huì)和Ubuntu官方服務(wù)器同步一次,這樣可以保

  證我們使用的是最新的軟件包。

  修改方式如下:

  root@ms ~: cat /etc/apt/sources.list

  deb jaunty main restricted universe multiverse

  deb jaunty-security main restricted universe multiverse

  deb jaunty-updates main restricted universe multiverse

  deb jaunty-proposed main restricted universe multiverse

  deb jaunty-backports main restricted universe multiverse

  deb-src jaunty main restricted universe multiverse

  deb-src jaunty-security main restricted universe multiverse

  deb-src jaunty-updates main restricted universe multiverse

  deb-src jaunty-proposed main restricted universe multiverse

  deb-src jaunty-backports main restricted universe multiverse

  安裝下面工具:

  root@ms ~: apt-get install apt-mirror

  root@ms ~: apt-get install apache2

  下面就構(gòu)建Ubuntu 9.04 32bit 的本地Ubuntu mirror 服務(wù)器為例子,來說明如何配置:

  修改配置文件:

  root@ms ~: cat /etc/apt/mirror.list

  ############# config ##################

  #

  # set base_path /var/spool/apt-mirror

  #

  # set mirror_path $base_path/mirror

  # set skel_path $base_path/skel

  # set var_path $base_path/var

  # set cleanscript $var_path/clean.sh

  # set defaultarch

  # set postmirror_script $var_path/postmirror.sh

  set run_postmirror 0

  set nthreads 20

  set _tilde 0

  #

  ############# end config ##############

  deb-i386 jaunty main restricted universe multiverse

  deb-i386 jaunty-security main restricted universe multiverse

  deb-i386 jaunty-updates main restricted universe multiverse

  #deb jaunty-proposed main restricted universe multiverse

  #deb jaunty-backports main restricted universe multiverse

  deb-src jaunty main restricted universe multiverse

  deb-src jaunty-security main restricted universe multiverse

  deb-src jaunty-updates main restricted universe multiverse

  #deb-src jaunty-proposed main restricted universe multiverse

  #deb-src jaunty-backports main restricted universe multiverse

  #clean

  備注:

  deb-i386 表示下載32 bit 版本的deb 軟件

  deb 表示下載64bit 版本的deb 軟件

  jaunty 表示Ubuntu 9.04的代號(hào)

  設(shè)置完成后,輸入下面命令:

  root@ms ~: apt-mirror

  這時(shí)系統(tǒng)會(huì)啟動(dòng)20個(gè)線程運(yùn)行wget 到 下面下載相應(yīng)的

  deb包。時(shí)間比較的長(zhǎng),該命令執(zhí)行完成后,/var/spool/apt-mirror目錄下就有了所有需

  要的deb包和相應(yīng)的配置文件。

  由于我是從sohu下載的,所以實(shí)際的文件在 :

  /var/spool/apt-mirror/mirror/mirrors.sohu.com/ubuntu 目錄下。

  這樣,本地就有了所有Ubuntu Source 服務(wù)器所需要的文件,然后開啟相應(yīng)的服務(wù):

  這里使用apache2作為Web服務(wù)器,默認(rèn)根目錄在/var/www/,所以可以在該目錄下做

  個(gè)鏈接,如下所示:

  root@ms ~: cd /var/www

  root@ms ~: ln /var/spool/apt-mirror/mirror/mirrors.sohu.com/ubuntu -s

  開啟web服務(wù):

  root@ms ~: apache2ctl start

  打開瀏覽器輸入下面地址即可看到和sohu mirror一樣的頁面:

  

  同時(shí)也可以使用crontab進(jìn)行每天的更新,修改配置文件:

  root@ms ~: cat /etc/cron.d/apt-mirror

  #

  # Regular cron jobs for the apt-mirror package

  #

  #0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log

  把命令前面的“#”去掉即可,這樣系統(tǒng)會(huì)自動(dòng)使用apt-mirror去和sohu服務(wù)器更新。

  最后,我們所要做得就是在客戶端的機(jī)器上修改更新源配置文件,將地址改成本地

  mirror服務(wù)器的地址即可,如下所示:

  root@ms ~: cat /etc/apt/sources.list

  deb jaunty main restricted universe multiverse

  deb jaunty-security main restricted universe multiverse

  deb jaunty-updates main restricted universe multiverse

  deb jaunty-proposed main restricted universe multiverse

  deb jaunty-backports main restricted universe multiverse

  deb-src jaunty main restricted universe multiverse

  deb-src jaunty-security main restricted universe multiverse

  deb-src jaunty-updates main restricted universe multiverse

  deb-src jaunty-proposed main restricted universe multiverse

  deb-src jaunty-backports main restricted universe multiverse

  執(zhí)行“apt-get update”來重建本地索引,這樣以后就會(huì)使用本地的Mirror 服務(wù)器進(jìn)行更新。

  小結(jié):以上就是安裝和搭建本地Ubuntu鏡像服務(wù)器的具體方法,希望對(duì)網(wǎng)友們能有所幫助哦!