Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

LinuxEye 開源鏡像站的搭建與運營全記錄

技術這東西,本來就在於折騰。最近手頭剛好有閒置的國內伺服器資源,便忍不住動手折騰起來,為的是方便廣大開源愛好者下載各種 Linux 發行版,於是 Linux 運維筆記就自己搭了一個鏡像網站。

LinuxEye 開源鏡像站網址:https://mirrors.linuxeye.com/

原本打算像 mirrors.ustc.edu.cn 那樣鏡像整個倉庫,無奈伺服器磁碟容量有限,於是 LinuxEye 改採只收錄最新版本(mini)的策略——鏡像會定期更新,抓取各發行版的最新版本,並自動替換所在目錄,同時附上對應的 md5 值。

ps:如果大家有特別想要的發行版,歡迎回帖告訴我,可以考慮加進鏡像站,先在此謝過!

LinuxEye 開源鏡像站的搭建過程
1. 使用《lnmp 一鍵安裝包》安裝 lnmp,執行 vhost.sh 新增虛擬主機 mirrors.linuxeye.com。

2. 在 nginx 中加入 fancyindex 模組,實現漂亮的索引目錄。

 cd lnmp/src wget https://gitorious.org/ngx-fancyindex/ngx-fancyindex/archive-tarball/master tar xvzf master # /usr/local/nginx/sbin/nginx -V #查看nginx已經編譯參數 cd nginx-1.6.2 make clean #增加ngx-fancyindex模塊(--add-module=../ngx-fancyindex-ngx-fancyindex) ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module \ --with-http_spdy_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module \ --with-http_flv_module --with-ld-opt=-ljemalloc --add-module=../ngx-fancyindex-ngx-fancyindex make mv /usr/local/nginx/sbin/nginx{,_`date +%F`} cp objs/nginx /usr/local/nginx/sbin

3. 修改虛擬主機設定檔(/usr/local/nginx/conf/vhost/mirrors.linuxeye.com.conf)。

 server { listen 80; server_name mirrors.linuxeye.com; access_log off; index index.html index.htm index.php; root /home/wwwroot/mirrors.linuxeye.com; location / { fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; fancyindex_footer "/footer.html"; fancyindex_ignore "footer.html" "exclude_centos.list"; } }

參數說明:
fancyindex on:開啟 fancy 索引。
fancyindex_exact_size off:不使用精確大小,改以四捨五入呈現,例如 1.9M 會顯示為 2M;若開啟則單位為位元組。
fancyindex_localtime on:使用本地時間。
fancyindex_footer /footer.html:把網站根目錄下的 footer.html 內容作為頁尾,檔案不存在時頁尾會出現 404。
footer.html 內容如下:

 <!-- footer START --> <div id="footer"> <div id="copyright"> 版權所有 &copy; 2015 LinuxEye </div> </div> <!-- footer END -->

fancyindex_ignore:指定哪些檔案/目錄要被隱藏。

fancy 指令用法:
fancyindex
語法:*fancyindex* [*on* | *off*]
預設值:fancyindex off
設定區塊:http, server, location
說明:開啟/關閉目錄索引功能。

fancyindex_css_href
語法:*fancyindex_css_href uri*
預設值:fancyindex_css_href “”
設定區塊:http, server, location
說明:外部 css 路徑,可用它取代現有的 css 樣式。

fancyindex_exact_size
語法:*fancyindex_exact_size* [*on* | *off*]
預設值:fancyindex_exact_size on
設定區塊:http, server, location
說明:定義檔案大小的顯示方式,預設為 on(精確值,單位位元組);off 時單位為 KB、MB、GB,含小數會四捨五入,例如 1.9MB 會顯示為 2MB。

fancyindex_footer
語法:*fancyindex_footer path*
預設值:fancyindex_footer “”
設定區塊:http, server, location
說明:指定哪個檔案嵌入到索引頁面的底部。

fancyindex_header
語法:*fancyindex_header path*
預設值:fancyindex_header “”
設定區塊:http, server, location
說明:指定哪個檔案嵌入到索引頁面的頂部,用法與 fancyindex_footer 類似。

fancyindex_ignore
語法:*fancyindex_ignore string1 [string2 [… stringN]]*
預設值:無。
設定區塊:http, server, location
說明:指定哪些檔案/目錄要被隱藏,支援 nginx 正則。

fancyindex_localtime
語法:*fancyindex_localtime* [*on* | *off*]
預設值:fancyindex_localtime off
設定區塊:http, server, location
說明:以當地時間顯示檔案的建立時間,預設為 off(GMT 時間)。

4. 同步 ustc 的 centos 鏡像。

 mkdir -p /home/wwwroot/mirrors.linuxeye.com/centos tmux #後台同步 rsync -avrt rsync://mirrors.ustc.edu.cn/centos/ \ --exclude-from=/home/wwwroot/mirrors.linuxeye.com/exclude_centos.list \ /home/wwwroot/mirrors.linuxeye.com/centos/

原文:https://blog.linuxeye.com/409.html

Copyright © Linux教程網 All Rights Reserved