Ubuntu 12.04 創建源服務器

需求:在本地搭載一個更新源作爲服務器,這樣在局域網內的其他虛擬機就可以通過在服務器端下載軟件包,可以節省很多時間


首先要確保要作爲服務器的主機能連上網絡,下面是具體的配置步驟

1、使用apt-mirror創建Ubuntu Source服務器的本地鏡像服務器

    sudo apt-get install apt-mirror

2、sudo apt-get install apache2

需要以上兩個軟件來構建我們的Ubuntu12.04的服務器

3、修改/etc/apt/mirror.list的配置文件爲以下情況:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
############# 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  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
setnthreads     20
set_tilde 0
#
############# end config ##############
deb http://debian.ustc.edu.cn/ubuntu/precise main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/precise-backports main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/precise-proposed main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/precise-security main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/precise-updates main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/precise main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/precise-backports main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/precise-proposed main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/precise-security main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/precise-updates main multiverse restricted universe
deb-i386 http://debian.ustc.edu.cn/ubuntu/precise main multiverse restricted universe
deb-i386 http://debian.ustc.edu.cn/ubuntu/precise-backports main multiverse restricted universe
deb-i386 http://debian.ustc.edu.cn/ubuntu/precise-proposed main multiverse restricted universe
deb-i386 http://debian.ustc.edu.cn/ubuntu/precise-security main multiverse restricted universe
deb-i386 http://debian.ustc.edu.cn/ubuntu/precise-updates main multiverse restricted universe

備註:debian.ustc.edu.cn爲我們使用的中國科技大學的Ubuntu Source服務器作爲的我們的源服務器。

 deb-i386 http://* 表示下載32位版本的deb軟件。

因爲之前也修改了/etc/apt/source.list,但是兩個配置文件都修改了之後,後續的步驟不能下載成功,所以把source.list又還原成了系統自帶的,結果成功了

4、執行 sudo apt-mirror

這會啓動20個線程到設置中的地址去下載響應的deb包,這個會運行很長時間,因爲要下載的東西很多

執行完成後,/var/spool/apt-mirror目錄下就有了所有需要的deb包和相應的配置


我們需要一個web服務器來啓動我們本地的ubuntu source服務器,這裏選擇的是apache2。apache2服務器安裝後,默認使用/var/www/目錄作爲

web的根目錄。

5、

cd/var/www/
 
 ln/var/spool/apt-mirror/mirror/debian.ustc.edu.cn/ubuntu/-s
在/var/www目錄下創建一個Ubuntu超鏈接,鏈接到/var/spool/apt-mirror/mirror/debian.ustc.edu.cn/ubuntu/上
6、sudo /etc/init.d/apache2 start/restart/stop/status 命令可以管理apache2服務器。
sudo service apache2 restart 重啓apache2服務器
sudo service apache2 stop 停止apache2服務器
sudo service apache2 start 啓動apache2服務器

7、測試apache2是否成功啓動
在web服務器中輸入 http://服務器ip地址 若顯示 it works 則成功開啓了apache2服務

8、修改客戶機的/etc/atp/source.list文件以使用本地Ubuntu Source服務器作爲apt源,如,服務器的Ip地址爲222.24.24.175
deb http://222.24.24.175/ubuntu/precise main multiverse restricted universe
deb http://222.24.24.175/ubuntu/precise-backports main multiverse restricted universe
deb http://222.24.24.175/ubuntu/precise-proposed main multiverse restricted universe
deb http://222.24.24.175/ubuntu/precise-security main multiverse restricted universe
deb http://222.24.24.175/ubuntu/precise-updates main multiverse restricted universe
deb-src http://222.24.24.175/ubuntu/precise main multiverse restricted universe
deb-src http://222.24.24.175/ubuntu/precise-backports main multiverse restricted universe
deb-src http://222.24.24.175/ubuntu/precise-proposed main multiverse restricted universe
deb-src http://222.24.24.175/ubuntu/precise-security main multiverse restricted universe
deb-src http://222.24.24.175/ubuntu/precise-updates main multiverse restricted universe


然後執行sudo apt-get update更新,以重建本地索引。以後就會使用本地的ubunt source服務器


這些全部做完了之後,以後所需要做的就是,定時更新服務器的deb包,sudo apt-mirror ,而本地局域網內的計算機執行sudo apt-get update即可
在這之前,本地局域網中的計算機需要修改source.list

debhttp://192.168.1.199/ubuntu/ precise main multiverse restricted universe

debhttp://192.168.1.199/ubuntu/ precise-backports main multiverse restricteduniverse

debhttp://192.168.1.199/ubuntu/ precise-proposed main multiverse restricteduniverse

debhttp://192.168.1.199/ubuntu/ precise-security main multiverse restricteduniverse

debhttp://192.168.1.199/ubuntu/ precise-updates main multiverse restricteduniverse

deb-srchttp://192.168.1.199/ubuntu/ precise main multiverse restricted universe

deb-srchttp://192.168.1.199/ubuntu/ precise-backports main multiverse restricteduniverse

deb-srchttp://192.168.1.199/ubuntu/ precise-proposed main multiverse restricteduniverse

deb-srchttp://192.168.1.199/ubuntu/ precise-security main multiverse restricteduniverse

deb-srchttp://192.168.1.199/ubuntu/ precise-updates main multiverse restricteduniverse

其中,192.168.1.199爲服務器計算機的ip地址。






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章