中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

架設Ubuntu源的腳本

2020-03-27    來源:愛站科技

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

由于工作需要我們在需要在服務器中架設Ubuntu源,那么你知道架設Ubuntu源的腳本是什么嗎?接下來我們就和愛站小編一起去看看具體的相關(guān)介紹吧,希望對你有所幫助。

最近在折騰新的Ubuntu的源,向公司申請了一臺配置一般的服務器,另外買了一塊硬盤,硬件就有了。

然后裝了個Ubuntu 9.04 Server,裝上ssh,再裝上Nginx,稍微配置一下,服務就好了,這個過程還是蠻簡單的,也很順利,就不多說了。

接下來就可以開始同步數(shù)據(jù)了。由于我的目標是一個完整的源,所以就沒有用apt-mirror之類的工具,而是直接拿rsync抓取上游的數(shù)據(jù)了。這個數(shù)據(jù)量是很大的,所以想盡量選擇一個速度最快的帶rsync的源,但是在茫茫的Ubuntu官方源列表里,這么多源哪個最快呢?當然沒有人會告訴你答案,因為每個人的網(wǎng)絡環(huán)境都不一樣啊。所以,最好的辦法還是實地測試,所謂磨刀不誤砍柴功啊,后面有250G的數(shù)據(jù)要下載呢,這個測試絕對有價值。

上腳本(不是很完美,夠用就行):

#!/bin/bash
urls=`curl https://launchpad.net/ubuntu/+archivemirrors | \
grep -B 2 '>rsync</a>' | grep http | awk -F '"' '{print $2}'`
rm res
echo "$urls" | while read url;do
rm T
wget -q --no-cache -O T "$url/ls-lR.gz" &
sleep 3
kill %%
echo "testing... $url"
echo -n "$url " >> res
ls -l T >>res
done
?
sort -k 6 -n res > fast_mirror
rm res T
最后你可以 tail fast_mirror 看到3秒內(nèi)下載的字節(jié)數(shù)最多的一個源。我這還真有一個源,能在3秒把7.4M大的ls-lR.gz給下載完的。
然后,你可以先用這個最快的源把大部分數(shù)據(jù)先更新下來,完了之后,為了保證數(shù)據(jù)最新,再向官方源更新一次,我用的是這個腳本:

#!/bin/bash
[[ $UID == 0 ]] || { echo "Must be root to run this script."; exit 0; }
LOCK="/data/sync_sh/lock"
LOG="/data/sync_sh/log"
?
while true; do
echo -e "\nstart sync @ `date`" | tee -a $LOG
?
if [ -f $LOCK ]; then
?echo "another sync is running, I exiting..." | tee -a $LOG
?exit 1
fi
touch $LOCK
?
st=`date +%s`
rsync --timeout=120 --exclude=".~tmp~" -avP --delete-excluded --progress rsync://archive.ubuntu.com/ubuntu/pool/ /data/mirrors/ubuntu/pool/
res=$?
if [ $res -eq 0 ]; then
?echo "rsync pool succ" | tee -a $LOG
?et=`date +%s`
?echo "pool sync use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
else
?echo "rsync pool failed" $res | tee -a $LOG
fi
?
st=`date +%s`
rsync --timeout=120 --exclude=".~tmp~" -avP --delete-excluded --progress rsync://archive.ubuntu.com/ubuntu/ /data/mirrors/ubuntu/
res=$?
if [ $res -eq 0 ]; then
??????? echo "rsync all succ" | tee -a $LOG
??????? et=`date +%s`
??????? echo "all sync use $(( $et-$st )) sec = $(( ($et-$st)/60 )):$(( ($et-$st)%60 ))" | tee -a $LOG
else
??????? echo "rsync all failed" $res | tee -a $LOG
fi
?
df | grep "/data" | tee -a $LOG
echo -e "end sync @ `date`" | tee -a $LOG
?
rm $LOCK
?
sleep 7200
done
這個腳本先更新pool目錄,再整個目錄更新一遍,這樣是為了減少出現(xiàn)軟件列表里已經(jīng)有某軟件,但是卻下載不到的情況。
腳本常駐運行,在上次更新完以后的2小時,啟動下一次更新,這樣應該算是國內(nèi)最新的源了吧?
PS: 感謝服務器達人lupa的walkerxk在我架設源時,給我的熱心幫助。

上文介紹的就是架設Ubuntu源的腳本,按照以上步驟應該不會出問題,有問題可以留言給我們愛站技術(shù)頻道哦。

標簽: Ubuntu 腳本

版權(quán)申明:本站文章部分自網(wǎng)絡,如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:如何查看Linux系統(tǒng)中DNS服務器的運行狀況

下一篇:關(guān)于Linux下開放與關(guān)閉端口