欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用apt-mirror搭建Ubuntu軟件源的實(shí)例教程

williamsang   發(fā)布時(shí)間:2016-01-26 11:51:01   作者:William_Sang   我要評(píng)論
這篇文章主要介紹了使用apt-mirror搭建Ubuntu軟件源的實(shí)例教程,包括使用Nginx配置HTTP訪問(wèn)的軟件源發(fā)布方法,非常全面,需要的朋友可以參考下

搭建自有Ubuntu源的原因有很多

節(jié)省外網(wǎng)帶寬
提前下載,緩解國(guó)外源下載緩慢
私有定制軟件包發(fā)布

本文測(cè)試環(huán)境

ubuntu 14.04(LTS) 64位
apt-mirror 版本 0.5.1-1
nginx 版本 1.4.6-1ubuntu3.1


安裝apt-mirror

復(fù)制代碼
代碼如下:

# sudo apt-get update
# sudo apt-get install apt-mirror=0.5.1-1

配置apt-mirror

apt-mirror的配置文件位置為 /etc/apt/mirror.list
根據(jù)注釋修改相應(yīng)內(nèi)容,一般只需要修改 base_path和更改、添加軟件源。以下配置文件我只添加了Ubuntu 14.04和MongoDB的軟件源,你可以根據(jù)你的需要添加Ubuntu其他版本軟件源。

復(fù)制代碼
代碼如下:

############# config ##################
#
# 配置數(shù)據(jù)基目錄
set base_path /data/apt-mirror
# 配置鏡像存儲(chǔ)位置
# set mirror_path $base_path/mirror
# 配置臨時(shí)下載索引位置
# set skel_path $base_path/skel
# 配置日子,URLs和MD5校驗(yàn)信息存儲(chǔ)位置
# set var_path $base_path/var
# 配置刪除過(guò)期源腳本位置(默認(rèn)不刪除,方便安裝舊版本軟件)
# set cleanscript $var_path/clean.sh
# 設(shè)置默認(rèn)架構(gòu), 可填: amd64 或 i386,默認(rèn)是和本機(jī)一個(gè)架構(gòu)
# set defaultarch <running host architecture>
#
# 設(shè)定下載后運(yùn)行的腳本位置
# set postmirror_script $var_path/postmirror.sh
# 設(shè)置是否執(zhí)行 下載后的腳本操作,默認(rèn)是1(但是默認(rèn)沒(méi)有postmirror.sh腳本)
set run_postmirror 0
# 設(shè)置下載線程數(shù)
set nthreads 20
# 是否替換URL中的波浪線,替換成%7E(HTML代碼),否則會(huì)跳過(guò)不進(jìn)行下載
set _tilde 0
#
############# end config ##############
# 配置Ubuntu trusty 源
deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
# clean http://archive.ubuntu.com/ubuntu
# 配置MongoDB源
# 官方地址 http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
#
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
# clean http://localhost/downloads-distro.mongodb.org

因?yàn)槲易远x了apt-mirror的數(shù)據(jù)目錄,所以需要賦予 apt-mirror用戶權(quán)限,否則同步不會(huì)正確運(yùn)行:

復(fù)制代碼
代碼如下:

# sudo chown -R apt-mirror:apt-mirror /data/apt-mirror


運(yùn)行第一次同步

確保你的基目錄下磁盤(pán)空間足夠,如上所配置,則至少保證150G的磁盤(pán)空間,建議200G以上,以后版本更新,添加軟件源等會(huì)需要很多磁盤(pán)空間。
因?yàn)橐螺d135G的內(nèi)容,時(shí)間比較漫長(zhǎng),建議切換到apt-mirror用戶用以下命令放在后臺(tái)運(yùn)行

復(fù)制代碼
代碼如下:

# sudo su apt-mirror
# nohup /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log &


安裝Nginx,配置HTTP訪問(wèn)

通過(guò)以上配置,已經(jīng)可以在 /data/apt-mirror 目錄下看到生成的幾個(gè)數(shù)據(jù)文件。/data/apt-mirror/mirror下存放的就是軟件鏡像。但是如何向其他計(jì)算機(jī)發(fā)布這些數(shù)據(jù)呢?很明顯通過(guò)HTTP服務(wù)可以做到這一點(diǎn)。我們通過(guò)使用Nginx將mirror目錄下的內(nèi)容通過(guò)HTTP協(xié)議發(fā)布。

安裝Nginx

復(fù)制代碼
代碼如下:

# sudo apt-get install nginx=1.4.6-1ubuntu3.1

nginx配置文件位置: /etc/nginx/sites-enabled/default,將其替換為以下文件:

復(fù)制代碼
代碼如下:

server {
listen 80;
# 這里填寫(xiě)你的域名,填寫(xiě)localhost就直接通過(guò)IP地址訪問(wèn)
server_name localhost;
# 顯示目錄
autoindex on;
location / {
index index.html index.htm;
# 這里填寫(xiě)鏡像保存位置
root /data/apt-mirror/mirror;
}
access_log /var/log/nginx/localhost.log;
}

更改完配置,先測(cè)試配置,如果測(cè)試通過(guò),則重啟nginx

復(fù)制代碼
代碼如下:

# sudo nginx -t
# sudo service nginx restart

此時(shí)訪問(wèn) http://服務(wù)器IP 即可訪問(wèn)到你發(fā)布的鏡像

配置定時(shí)同步

我們當(dāng)然不能,每天自己手動(dòng)同步鏡像啦。我們需要配置apt-mirror每天定時(shí)同步,其實(shí)就是配置cron。
這里apt-mirror提供了cron模板文件,在/etc/cron.d/apt-mirror 中,取消最后一行的#注釋即可生效:

0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log
以上設(shè)置每日4點(diǎn)同步一次

客戶端配置

現(xiàn)在我們已經(jīng)配置好了服務(wù)端,找個(gè)Ubuntu 14.04 64位的來(lái)測(cè)試一下

備份source.list

復(fù)制代碼
代碼如下:

# sudo mv /etc/apt/source.list /etc/apt/source.list.bak

新建/etc/apt/source.list, 寫(xiě)入以下內(nèi)容(上述服務(wù)器DNS或IP 替換”自建源IP”)

復(fù)制代碼
代碼如下:

deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse


復(fù)制代碼
代碼如下:

deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse


復(fù)制代碼
代碼如下:

# 配置MongoDB源
deb [arch=amd64] http://自建源IP/downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

通過(guò)比較apt-mirror和source.list文件,其實(shí)就是把原有域名變成了一個(gè)目錄。注意:以上客戶端配置也多添加了[arch=amd64],用于指定架構(gòu),否則會(huì)出現(xiàn)

Err http://192.168.1.71 trusty/main i386 Packages
  404  Not Found
Err http://192.168.1.71 trusty/restricted i386 Packages
  404  Not Found
Err http://192.168.1.71 trusty/universe i386 Packages
  404  Not Found
...
類(lèi)似錯(cuò)誤,因?yàn)槲业臏y(cè)試環(huán)境是x64,只同步了64位架構(gòu)源,所以必須指定架構(gòu)為64,現(xiàn)在客戶端也無(wú)需i386的軟件。
添加過(guò)source.list后,運(yùn)行

復(fù)制代碼
代碼如下:

# sudo apt-get update

ubuntu部分正常更新,但是發(fā)現(xiàn)會(huì)出現(xiàn)以下錯(cuò)誤提示

W: GPG error: http://192.168.1.111 dist Release:
 The following signatures couldn't be verified
 because the public key is not available: NO_PUBKEY 9ECBEC467F0CEB10
需要添加GPG key,添加某些package時(shí),基本都需要添加GPG key,官方網(wǎng)站一般都會(huì)給出

復(fù)制代碼
代碼如下:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

此時(shí)你就可以使用自建源安裝軟件啦~~
以下安裝了MongoDB和htop來(lái)進(jìn)行測(cè)試

復(fù)制代碼
代碼如下:

sudo apt-get install -y mongodb-org=2.6.5 htop

相關(guān)文章

最新評(píng)論