3. 如何Mirror FreeBSD 站台

好,現在你知道硬體需求和如何提供服務,但不知道如何做。:-) 這節將解釋如何實際 mirror FreeBSD 的不同部分,使用哪些工具以及從哪裡 mirror。

3.1. 鏡像 FTP 站

FTP 部份有最大量的資料需要被 mirror。它包括網路安裝所需的發布集,實際上是原始碼樹快照的分支,可燒錄光碟供安裝系統的ISO映像檔 ,一個可 live 開機的檔案系統,以及一個 port tree 的快照。當然,全都有各種 FreeBSD 版本和各種CPU架構。

The best way to mirror the FTP area is rsync. You can install the port net/rsync and then use rsync to sync with your upstream host. rsync is already mentioned in 節 2.4.2, “Rsync (給FTP檔案集選用)”. Since rsync access is not required, your preferred upstream site may not allow it. You may need to hunt around a little bit to find a site that allows rsync access.

注意:

由於 rsync 客戶端的數量將對伺服器主機產生重大影響,因此大多數管理員會對伺服器負荷加以限制。對於 mirror 站台,您應該詢問您要 mirror 站台的管理人員他們的管理政策,也許需要對您的主機開放例外(因為您是一個 mirror 站)。

一個需要mirror FreeBSD官網的指令如下:

% rsync -vaHz --delete rsync://ftp4.de.FreeBSD.org/FreeBSD/ /pub/FreeBSD/

Consult the documentation for rsync, which is also available at http://rsync.samba.org/, about the various options to be used with rsync. If you sync the whole module (unlike subdirectories), be aware that the module-directory (here "FreeBSD") will not be created, so you cannot omit the target directory. Also you might want to set up a script framework that calls such a command via cron(8).

3.2. Mirroring 網頁

FreeBSD 網站應只能透過rsync指令來mirror.

一個 mirror FreeBSD 網站的指令應該看起像這樣:

% rsync -vaHz --delete rsync://bit0.us-west.freebsd.org/FreeBSD-www-data/ /usr/local/www/

3.3. Mirroring 套件

由於對頻寬,儲存空間和管理的要求非常高,FreeBSD 計畫決定不允許公眾 mirror 套件. 對於擁有大量伺服主機的網站,建議為 pkg(8) 使用 HTTP proxy 快取可能會有所幫助。或者,您可以使用以下指令獲得套件與相依套件:

% pkg fetch -d -o /usr/local/mirror vim

一旦這些套件包被下載,就必須執行以下命令來產生套件庫數據:

% pkg repo /usr/local/mirror

一旦套件被下載並且已經生成了套件庫的數據,就可以透過 HTTP 協定將套件提供給客戶端機器。有關更多訊息,請參閱 pkg(8) 的 man pages,特別是pkg-repo(8) 頁面。

3.4. 我多久應該mirror?

Every mirror should be updated at a minimum of once per day. Certainly a script with locking to prevent multiple runs happening at the same time will be needed to run from cron(8). Since nearly every admin does this in their own way, specific instructions cannot be provided. It could work something like this:

  1. Put the command to run your mirroring application in a script. Use of a plain /bin/sh script is recommended.

  2. Add some output redirections so diagnostic messages are logged to a file.

  3. Test if your script works. Check the logs.

  4. Use crontab(1) to add the script to the appropriate user's crontab(5). This should be a different user than what your FTP daemon runs as so that if file permissions inside your FTP area are not world-readable those files can not be accessed by anonymous FTP. This is used to stage releases — making sure all of the official mirror sites have all of the necessary release files on release day.

Here are some recommended schedules:

  • FTP fileset: daily

  • WWW pages: daily

本文及其他文件,可由此下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/

若有 FreeBSD 方面疑問,請先閱讀 FreeBSD 相關文件,如不能解決的話,再洽詢 <questions@FreeBSD.org>。

關於本文件的問題,請洽詢 <doc@FreeBSD.org>。