顯示具有 mirror 標籤的文章。 顯示所有文章
顯示具有 mirror 標籤的文章。 顯示所有文章

2014年5月29日 星期四

將實體機的 Debian 鏡像站分享給 pxeserver

2019/10/14 修改

PXE Server 雖然有 deb_mirror.img 來作為網路安裝下載之檔案儲存空間,但畢竟不是一個完整的 Debian 鏡像站,為了解決這個問題,讓 PXE Server 能成為虛擬教室真正的 Debian 鏡像站,我們要將實體機的 /home/ftp/debian 及 /home/ftp/emdebian 目錄以 NFS 方式分享給 PXE Server,而 PXE Server 可以掛載此兩個目錄,並成為虛擬教室中真正的鏡像站主機。


作法:

1. 本機(實體機器)端開啟 NFS 服務

首先請以 root 權限安裝 nfs-kernel-server 套件,接著修改

/etc/exports 檔案,加上二行:

/home/ftp/debian           192.168.10.254(ro,sync,no_subtree_check)
/home/ftp/emdebian      192.168.10.254(ro,sync,no_subtree_check)

作完後執行

/etc/init.d/nfs-kernel-server restart

然後執行 showmount -e localhost 來觀看輸出,如底下所示:

root@aspire:~# showmount -e localhost
Export list for localhost:
/home/ftp/emdebian 192.168.10.254
/home/ftp/debian   192.168.10.254


2. PXE Server 掛載 NFS 目錄

2.1 確認有看到實體機分享出來的鏡像站目錄

showmount -e 192.168.10.1
             ^^^^^^^^^^^^ -> 此 IP 為 PXE Server 所看到實體主機之 IP

看到輸出如下所示:

Export list for 192.168.10.1:
/home/ftp/emdebian 192.168.10.254
/home/ftp/debian   192.168.10.254

2.2 建置 ftp 伺服器


2.3 在 pxe 伺服器底下輸入:

# showmount -e  192.168.10.1
Export list for 192.168.10.1:
/srv/ftp 192.168.10.0/24

接著手動掛載試試看:
# mkdir -p /home/ftp/debian
# mount -t nfs 192.168.10.1:/home/ftp/debian  /home/ftp/debian

看看能不能把遠端的 ftp 站掛在 pxe 伺服器的 /home/ftp 目錄。確定可以的話我們把設定寫入
/etc/fstab

接著請修改 /etc/passwd 檔案,將
ftp:x:107:65534::/srv/ftp:/usr/sbin/nologin
改成
ftp:x:107:65534::/home/ftp:/usr/sbin/nologin

然後用瀏覽器開 ftp://192.168.10.254,看看能不能看到 debian 目錄。


# vi /etc/fstab
新增一行:

192.168.10.1:/home/ftp/debian   /home/ftp/debian   nfs   defaults   0  0

然後可以執行:

# mount -a

來確認掛載沒有問題。


3. 測試虛擬機之鏡像站設定

請在實體機上修改 /etc/apt/sources.list 檔,將其中的鏡像站設定改為:

deb ftp://192.168.10.254/debian/ stretch main contrib non-free

然後再執行

# apt-get update

看看能不能自 ftp://192.168.10.254 下載資料。



請參考網頁

2014年5月22日 星期四

自建 Debian 鏡像站

2019/10/14 修改

目的:自建 Debian 鏡像站 (MIRROR)

在安裝 Debian Linux 的過程中,常常需要使用網路進行遠端連線來下載套件 (packages), 如果網路連線有問題的話,我們經常無法進行套件下載或更新的操作。這對執行專案是項極大的困擾,為了不讓網路干擾我們進行下載,因此必須自行建立 Debian 鏡像站。

Debian 支援相當多硬體架構,因此官方鏡像站需要相當多的容量才可以儲存所有套件,我們的計畫僅需要底下架構:

X86_64 (amd64)
i386 (i386)
EABI ARM (armel)
Hard Float ABI ARM (armhf)
ARM64 (arm64)

其它架構的檔案無需下載,以節省硬碟空間。要自建 Debian 鏡像站的流程如下:

1. 建立 ftp 伺服器

2. 下載 Debian 套件

3. 啟動服務

4. 設定 /etc/apt/sources.list

------------------------------

如果我們希望所下載的 Debian 鏡像站可以提供給 pxeserver 使用的話,還必須

利用 NFS 的方式將 Debian 鏡像站的目錄分享給 pxeserver。

=========================================

1. 建立 ftp 伺服器

請以 root 權限執行:

# apt-get install proftpd-basic

安裝完畢後,請修改 /etc/proftpd/proftpd.conf 這個檔案,將底下部份移除行首之 #
(註解),移除完之結果如底下所述:

---------
 <Anonymous ~ftp>
   User                         ftp
   Group                                nogroup
   # We want clients to be able to login with "anonymous" as well as "ftp"
   UserAlias                    anonymous ftp
   # Cosmetic changes, all files belongs to ftp user
   DirFakeUser  on ftp
   DirFakeGroup on ftp

   RequireValidShell            off

   # Limit the maximum number of anonymous logins
  MaxClients                    70

   # We want 'welcome.msg' displayed at login, and '.message' displayed
   # in each newly chdired directory.
   DisplayLogin                 welcome.msg
   DisplayChdir         .message

   # Limit WRITE everywhere in the anonymous chroot
   <Directory *>
     <Limit WRITE>
       DenyAll
     </Limit>
   </Directory>

   # Uncomment this if you're brave.
   # <Directory incoming>
   #   # Umask 022 is a good standard umask to prevent new files and dirs
   #   # (second parm) from being group and world writable.
   #   Umask                            022  022
   #            <Limit READ WRITE>
   #            DenyAll
   #            </Limit>
   #            <Limit STOR>
   #            AllowAll
   #            </Limit>
   # </Directory>

 </Anonymous>
--------

接著請修改 /etc/passwd 將 ftp 的家目錄由 /srv/ftp 改至 /home/ftp

修改完成後,請執行 proftpd-basic 服務,指令如下:


# /etc/init.d/proftpd restart
[ ok ] Stopping ftp server: proftpd.
[ ok ] Starting ftp server: proftpd.

啟動完畢後,我們可以使用 iceweasel 或是 gftp 來驗證自己的 ftp 站是否已完成架設。

=========================================

2. 下載 Debian 套件

由於 Debian 套件所佔之容量極為龐大,要下載 Debian 套件前請先確定自己的 /home/ftp 目錄是否有至少 150 GB 的容量,以免硬碟容量不足。


接下來請安裝 debmirror 套件,以便下載 Debian 鏡像站,接著請撰寫底下 script:

#HOST=ftp.tw.debian.org
HOST=debian.nctu.edu.tw
#HOST=opensource.nchc.org.tw
#HOST=ftp.twaren.net

debmirror \
        --arch=i386,amd64,armel,armhf \
        --dist=buster,buster-updates,buster-backports \
        --di-arch=i386,amd64,armel \
        --di-dist=stable \
        --host=$HOST \
        --root=":debian" \
        --diff=none -p \
        --nosource \
        --method=rsync \
        --section main,contrib,non-free \
        --i18n \
        --ignore-release-gpg /home/ftp/debian/ ;


此 script 請放在 /home/ftp 目錄下,執行:

# sh getdeb.sh

接著此 script 就會自動進行 Debian 套件下載的工作,我們也可以使用 crontab

讓此工作定期 (每日凌晨 2 點) 執行。




4. 設定 /etc/apt/sources.list

請修改 /etc/apt/sources.list

加上以下兩行:


deb file:/home/ftp/debian/ buster main contrib non-free

deb ftp://127.0.0.1/debian buster main contrib non-free
deb ftp://localhost/debian buster main contrib non-free


其中第一行是指在本機端下載套件時,可以不經由 ftp 傳輸協定,直接使用檔案複製的方式來進行套件下載。

第二行則是透過 ftp 傳輸協定,自 127.0.0.1 下載套件,請注意 lo 介面要打開,否則沒有 ftp://localhost 或 ftp://127.0.0.1。因此我們新的 /etc/apt/sources.list 可以只保留底下這幾行:

deb file:/home/ftp/debian/ buster main contrib non-free

deb ftp://127.0.0.1/debian buster main contrib non-free
#deb ftp://localhost/debian buster main contrib non-free

deb http://security.debian.org/ stable/updates main contrib

修改完畢後,可以在本機端使用

apt-get update
apt-get upgrade

apt-get install 套件

來進行安裝測試,以確認自己所架設之 Debian 鏡像站可以正常運轉。