18.1 簡介 #
HTTP 開機結合了 DHCP、DNS 和 HTTP,可讓您透過網路開機和部署系統。HTTP 開機可做為 PXE 的高效能替代功能。HTTP 開機允許透過 HTTP 從 URI 將伺服器開機,從而可從本地網路外部的伺服器快速傳輸大型檔案,例如 Linux 核心和根檔案系統。
18.1.1 設定用戶端機器 #
依據您的特定硬體,在實體用戶端機器上啟用 HTTP 開機。如需關於如何在特定機器上啟用 HTTP 開機的更多資訊,請參閱相關文件。
18.1.2 準備 #
例如,此處所述的設定使用 192.168.111.0/24 (IPv4) 和 2001:db8:f00f:cafe::/64 (IPv6) IP 子網路,伺服器 IP 位址為 192.168.111.1(IPv4) 和 2001:db8:f00f:cafe::1/64 (IPv6)。請依據您的特定設定調整這些值。
在您打算做為 HTTP 開機伺服器的機器上安裝以下套件:dhcp-server、apache2 (或 lighttpd) 和 dnsmasq。
18.2 設定伺服器 #
18.2.1 DNS 伺服器 #
雖然設定 DNS 伺服器是選擇性步驟,但這可讓您為 HTTP 開機伺服器指定一個使用者易記的名稱。若要設定 DNS 伺服器,請新增以下內容至 /etc/dnsmasq.conf
檔案:
interface=eth0 addn-hosts=/etc/dnsmasq.d/hosts.conf
為 /etc/dnsmasq.d/hosts.conf
檔案中的 IP 位址指定網域名稱:
192.168.111.1 www.httpboot.local 2001:db8:f00f:cafe::1 www.httpboot.local
啟動 DNS 伺服器。
systemctl start dnsmasq
由於 UEFI 2.7 中的某個變更,我們建議使用 SLE 15 或更新版本中的 shim 開機載入程式,以避免該附加 DNS 節點可能導致的錯誤。
18.2.1.1 設定 DHCPv4 伺服器 #
設定 DHCP 伺服器之前,需在 /etc/sysconfig/dhcpd
中指定伺服器的網路介面:
DHCPD_INTERFACE="eth0" DHCPD6_INTERFACE="eth0"
這樣一來,DHCP 伺服器就只會在 eth0
介面上提供服務。
若要設定同時用於 PXE 開機和 HTTP 開機的 DHCPv4 伺服器,請將以下組態新增至 /etc/dhcpd.conf
檔案:
option domain-name-servers 192.168.111.1; option routers 192.168.111.1; default-lease-time 14400; ddns-update-style none; subnet 192.168.111.0 netmask 255.255.255.0 { range dynamic-bootp 192.168.111.100 192.168.111.120; default-lease-time 14400; max-lease-time 172800; class "pxeclients"{ match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; next-server 192.168.111.1; filename "/bootx64.efi"; } class "httpclients" { match if substring (option vendor-class-identifier, 0, 10) = "HTTPClient"; option vendor-class-identifier "HTTPClient"; filename "http://www.httpboot.local/sle/EFI/BOOT/bootx64.efi"; } }
請注意,DHCPv4 伺服器必須使用 HTTPClient
參數來表示廠商類別 ID,因為用戶端使用該參數來識別 HTTP 開機服務。
啟動 DHCP 精靈:
systemctl start dhcpd
18.2.1.2 設定 DHCPv6 伺服器 #
若要設定 DHCPv6 伺服器,請新增以下組態至 /etc/dhcpd6.conf
:
option dhcp6.bootfile-url code 59 = string; option dhcp6.vendor-class code 16 = {integer 32, integer 16, string}; subnet6 2001:db8:f00f:cafe::/64 { range6 2001:db8:f00f:cafe::42:10 2001:db8:f00f:cafe::42:99; option dhcp6.bootfile-url "http://www.httpboot.local/sle/EFI/BOOT/bootx64.efi"; option dhcp6.name-servers 2001:db8:f00f:cafe::1; option dhcp6.vendor-class 0 10 "HTTPClient"; }
此組態定義開機 URL 的類型、廠商類別和其他必需的選項。與 DHCPv4 設定類似,需要提供開機 URL,該 URL 必須包含 IPv6 位址。還需要指定廠商類別選項。在 DHCPv6 中,它由企業編號和廠商類別資料 (長度和內容) 組成。由於 HTTP 開機驅動程式會忽略企業編號,因此可將其設為 0
。廠商類別資料的內容必須是 HTTPClient
;否則,用戶端將會忽略該服務。
較舊的 HTTP 開機實作不遵循 RFC 3315,需要使用不同的組態:
option dhcp6.bootfile-url code 59 = string; option dhcp6.vendor-class code 16 = string; subnet6 2001:db8:f00f:cafe::/64 { range6 2001:db8:f00f:cafe::42:10 2001:db8:f00f:cafe::42:99; option dhcp6.bootfile-url "http://www.httpboot.local/sle/EFI/BOOT/bootx64.efi; option dhcp6.name-servers 2001:db8:f00f:cafe::1; option dhcp6.vendor-class "HTTPClient"; }
啟動 dhcpv6
精靈。
systemctl start dhcpd6
18.2.1.2.1 設定同時用於 PXE 開機和 HTTP 開機的 DHCPv6 伺服器 #
使用以下組態可以設定同時用於 PXE 開機和 HTTP 開機的 DHCPv6 伺服器:
option dhcp6.bootfile-url code 59 = string; option dhcp6.vendor-class code 16 = {integer 32, integer 16, string}; subnet6 2001:db8:f00f:cafe::/64 { range6 2001:db8:f00f:cafe::42:10 2001:db8:f00f:cafe::42:99; class "PXEClient" { match substring (option dhcp6.vendor-class, 6, 9); } subclass "PXEClient" "PXEClient" { option dhcp6.bootfile-url "tftp://[2001:db8:f00f:cafe::1]/bootloader.efi"; } class "HTTPClient"; { match substring (option dhcp6.vendor-class, 6, 10); } subclass "HTTPClient" "HTTPClient" { option dhcp6.bootfile-url "http://www.httpboot.local/sle/EFI/BOOT/bootx64.efi"; option dhcp6.name-servers 2001:db8:f00f:cafe::1; option dhcp6.vendor-class 0 10 "HTTPClient"; } }
您也可以依如下所示將廠商類別與特定架構進行比對:
class "HTTPClient" { match substring (option dhcp6.vendor-class, 6, 21); } subclass "HTTPClient" "HTTPClient":Arch:00016 { option dhcp6.bootfile-url "http://www.httpboot.local/sle/EFI/BOOT/bootx64.efi"; option dhcp6.name-servers 2001:db8:f00f:cafe::1; option dhcp6.vendor-class 0 10 "HTTPClient"; }
在此範例中,HTTPClient:Arch:00016
表示 AMD64/Intel 64 HTTP 開機用戶端。此組態允許伺服器同時為不同的架構提供服務。
18.2.1.2.2 設定防火牆 #
如果防火牆中的 RP 過濾器丟棄了 DHCPv6 封包,請檢查其記錄。如果記錄中包含 rpfilter_DROP
項目,請在 /etc/firewalld/firewalld.conf
中使用以下組態停用該過濾器:
IPv6_rpfilter=no
18.2.1.3 部署 TFTP 伺服器 (選擇性) #
若要同時為 PXE 開機和 HTTP 開機提供支援,請部署 TFTP 伺服器。安裝 tftp 並啟動服務:
systemctl start tftp.socket systemctl start tftp.service
還需要安裝用於 PXE 開機的特定 tftpboot-installation 套件:執行 zypper se tftpboot
指令以列出可用的 tftp-installation 套件,然後安裝所需系統版本和架構的套件,例如 tftpboot-installation-SLE-15-SP3-x86_64 例如,tftpboot-installation-SLE-VERSION-x86_64(以實際版本取代 VERSION)。將 SLE-VERSION-x86_64
目錄的內容複製到 TFTP 伺服器的根目錄中:
如需詳細資訊,請參閱 /usr/share/tftpboot-installation/SLE-VERSION-x86_64/README
18.2.1.4 設定 HTTP 伺服器 #
將第一個系統 ISO 影像的所有內容複製到 /srv/www/htdocs/sle/
目錄中。然後編輯 /srv/www/htdocs/sle/grub.cfg
檔案。使用下面的範例做為參考:
timeout=60 default=1 menuentry 'Installation IPv4' --class opensuse --class gnu-linux --class gnu --class os { set gfxpayload=keep echo 'Loading kernel ...' linuxefi /sle/boot/x86_64/loader/linux install=http://www.httpboot.local/sle echo 'Loading initial ramdisk ...' initrdefi /sle/boot/x86_64/loader/initrd } menuentry 'Installation IPv6' --class opensuse --class gnu-linux --class gnu --class os { set gfxpayload=keep echo 'Loading kernel ...' linuxefi /sle/boot/x86_64/loader/linux install=install=http://www.httpboot.local/sle ipv6only=1 ifcfg=*=dhcp6,DHCLIENT6_MODE=managed echo 'Loading initial ramdisk ...' initrdefi /sle/boot/x86_64/loader/initrd }
18.2.1.4.1 設定 lighttpd #
若要在 lighttpd 中同時啟用 IPv4 和 IPv6 支援,請依以下所示修改 /etc/lighttpd/lighttpd.conf
:
## ## Use IPv6? ## #server.use-ipv6 = "enable" $SERVER["socket"] == "[::]:80" { }
啟動 lighttpd
精靈:
systemctl start lighttpd
18.2.1.4.2 設定 apache2 #
Apache 不需要額外的組態。啟動 apache2
精靈:
systemctl start apache2
18.2.1.5 為 HTTP 伺服器啟用 SSL 支援 (選擇性) #
若要使用 HTTPS 開機,您需要將現有伺服器證書轉換為 DER
格式,並將其註冊到用戶端韌體中。
假設您的伺服器上已安裝證書,請使用以下指令將其轉換為 DER
格式,以用於用戶端:
openssl x509 -in CERTIFICATE.crt -outform der -out CERTIFICATE.der
18.2.1.5.1 將伺服器證書註冊到用戶端韌體中 #
註冊已轉換證書的確切程序取決於用戶端韌體的具體實作。對於某些硬體,您需要使用包含證書的外部儲存裝置,透過韌體 UI 以手動方式註冊證書。支援 Redfish 的機器可以從遠端註冊證書。如需註冊證書的詳細資訊,請參閱特定硬體的相應文件。
18.2.1.5.2 在 lighttpd 中啟用 SSL 支援 #
由於 lighttpd 需要私密金鑰和證書儲存在同一個檔案中,請使用以下指令整合這些資料:
cat CERTIFICATE.crt server.key > CERTIFICATE.pem
將 CERTIFICATE.pem
複製到 /etc/ssl/private/
目錄中。
cp server-almighty.pem /etc/ssl/private/ chown -R root:lighttpd /etc/ssl/private/server-almighty.pem chmod 640 /etc/ssl/private/server-almighty.pem
確定 mod_openssl
列在 /etc/lighttpd/modules.conf
檔案的 server.modules
部分,例如:
server.modules = ( "mod_access", "mod_openssl", )
將下面幾行新增至 /etc/lighttpd/lighttpd.conf
中的 SSL Support
部分:
# IPv4 $SERVER["socket"] == ":443" { ssl.engine = "enable" ssl.pemfile = "/etc/ssl/private/server-almighty.pem" } # IPv6 $SERVER["socket"] == "[::]:443" { ssl.engine = "enable" ssl.pemfile = "/etc/ssl/private/server-almighty.pem" }
重新啟動 lighttpd 以啟用 SSL 支援:
systemctl restart lighttpd
18.2.1.5.3 在 Apache 中啟用 SSL 支援 #
開啟 /etc/sysconfig/apache2
檔案,並依如下所示新增 SSL 旗標:
APACHE_SERVER_FLAGS="SSL"
請確定 ssl
模組列在 APACHE_MODULES
中,例如:
接下來,將私密金鑰和證書複製到 /etc/apache2/
目錄中。
cp server.key /etc/apache2/ssl.key/ chown wwwrun /etc/apache2/ssl.key/server.key chmod 600 /etc/apache2/ssl.key/server.key cp server.crt /etc/apache2/ssl.crt/
建立 ssl vhost 組態。
cd /etc/apache2/vhosts.d cp vhost-ssl.template vhost-ssl.conf
編輯 /etc/apache2/vhosts.d/vhost-ssl.conf
以變更私密金鑰和證書:
SSLCertificateFile /etc/apache2/ssl.crt/server.crt SSLCertificateKeyFile /etc/apache2/ssl.key/server.key
重新啟動 apache 以啟用 SSL 支援:
systemctl restart apache2
18.2.1.5.4 修改 DHCP 組態 #
在 dhcpd.conf/dhcpd6.conf
中,以 https://
取代 http://
字首,然後重新啟動 DHCP 伺服器。
systemctl restart dhcpd systemctl restart dhcpd6
18.3 透過 HTTP 開機將用戶端開機 #
如果韌體已支援 HTTP 開機,請插入電纜並選擇正確的開機選項。