自動化伺服器安裝設定檔頂級鍵“late-commands”不能使用 wget 或 curl

自動化伺服器安裝設定檔頂級鍵“late-commands”不能使用 wget 或 curl

我遇到了有關自動伺服器安裝的問題。

這是我的環境: 伺服器:centos 7.6 x86_64(它是一個kvm系統) Node1:無系統 Node2:無系統

我想自動安裝Ubuntu-20.04.3 Server系統。

關於Server1我安裝了tftpd,dhcpd,httpd。像這樣的一些配置:

# tftpd
# cat /etc/xinetd.d/tftp
service tftp
{
    socket_type     = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = -s /var/lib/tftpboot
    disable         = yes
    per_source      = 11
    cps         = 100 2
    flags           = IPv4
}


# dhcpd
# cat  /etc/dhcp/dhcpd.conf
ddns-update-style none;
subnet 10.10.8.0 netmask 255.255.252.0 {
     option routers             10.10.11.254;
     option domain-name-servers 10.10.9.250;
     option subnet-mask         255.255.252.0;
     range dynamic-bootp        10.10.11.10 10.10.11.220;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.10.11.245;
     filename "pxelinux.0";
}

# httpd
# cat /etc/httpd/conf.d/tftp.conf
<Directory /var/lib/tftpboot>
        Options +FollowSymLinks +Indexes
        Require all granted
</Directory>
Alias /tftp /var/lib/tftpboot

文件位於/var/lib/tftpboot

# ll  /var/lib/tftpboot/
总用量 1328744
drwxrwxrwx 2 root root         22 12月  8 18:40 grub
-rwxrwxrwx 1 root root   86017541 11月 25 17:40 initrd
-rwxrwxrwx 1 root root         31 11月 25 17:45 meta-data
-rwxrwxrwx 1 root root        336 12月  8 20:03 network.sh
-rwxrwxrwx 1 root root    1435512 4月  16 2020 pxelinux.0
-rwxrwxrwx 1 root root 1261371392 8月  24 17:09 ubuntu-20.04.3-live-server-amd64.iso
-rwxrwxrwx 1 root root       1353 12月  8 20:03 ubuntu_init.sh
-rwxrwxrwx 1 root root       2856 12月  8 20:17 user-data
-rwxrwxrwx 1 root root   11772160 11月 25 17:40 vmlinuz

grub設定檔

# cat grub/grub.cfg
default=autoinstall
timeout=5
timeout_style=menu

set menu_color_normal=white/black
set menu_color_highlight=black/light-gray

menuentry "Focal Live Installer - automated" --id=autoinstall {
    echo "Loading Kernel...1111"
    linux /vmlinuz  root=/dev/ram0 ramdisk_size=1500000 root=/dev/ram0 ramdisk_size=1500000  ip=dhcp url=http://10.10.11.245/tftp/ubuntu-20.04.3-live-server-amd64.iso autoinstall ds=nocloud-net\;s=http://10.10.11.245/tftp/ ---
    echo "Loading Ram Disk...111"
    initrd /initrd
}
menuentry "Focal Live Installer" --id=install {
    echo "Loading Kernel...22"
    linux /vmlinuz   root=/dev/ram0 ramdisk_size=1500000 ramdisk_size=1500000 ip=dhcp url=http://10.10.11.245/tftp/ubuntu-20.04.3-live-server-amd64.iso
    echo "Loading Ram Disk...22"
    initrd /initrd
}

元數據

# cat meta-data
instance-id: focal-autoinstall

使用者資料

# cat user-data
#cloud-config
autoinstall:
  apt:
    geoip: true
    preserve_sources_list: false
    primary:
    - arches: [amd64, i386]
      uri: http://mirrors.aliyun.com/ubuntu
    - arches: [default]
      uri: http://ports.ubuntu.com/ubuntu-ports
  user-data:
    timezone: Asia/Shanghai
    disable_root: false
    chpasswd:
      list: |
        root:$6$YMYlEcE71$/bcl2qd2rSYePvOkmgAyQR/h/
  identity: {hostname: 111, password: $6$ereNXNuj9WVUt77B$.dbpuHaLernNl6qq6r14meIk1W5VAyaMV9.,
    realname: 11, username: 11}
  keyboard: {layout: us, toggle: null, variant: ''}
  locale: en_US.UTF-8
  network:
    ethernets:
      eno12399:
        critical: true
        dhcp-identifier: mac
        dhcp4: true
        nameservers:
          addresses: [10.10.9.250]
      eno12409: {dhcp4: true}
      eno12419: {dhcp4: true}
      eno12429: {dhcp4: true}
      eno8303: {dhcp4: true}
      eno8403: {dhcp4: true}
    version: 2
  proxy: http://mirrors.aliyun.com/ubuntu
  ssh:
    allow-pw: true
    authorized-keys: []
    install-server: true
  storage:
    grub:
      reorder_uefi: False
    config:
    - {ptable: gpt, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: false,
      type: disk, id: disk-sda}
    - {device: disk-sda, size: 536870912, wipe: superblock, flag: boot, number: 1,
      preserve: false, grub_device: true, type: partition, id: partition-2}
    - {fstype: fat32, volume: partition-2, preserve: false, type: format, id: format-2}
    - {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 2,
      preserve: false, grub_device: false, type: partition, id: partition-3}
    - {fstype: xfs, volume: partition-3, preserve: false, type: format, id: format-3}
    - {path: /, device: format-3, type: mount, id: mount-3}
    - {path: /boot/efi, device: format-2, type: mount, id: mount-2}
  updates: security
  packages:
  - linux-generic
  - net-tools
  late-commands:
  - curtin in-target --target=/target -- /usr/bin/wget -P /root/ http://10.10.11.245/tftp/ubuntu_init.sh
  - curtin in-target --target=/target -- /usr/bin/wget -P /root/ http://10.10.11.245/tftp/network.sh
  - curtin in-target --target=/target -- /usr/bin/bash /root/ubuntu_init.sh
  #- curtin in-target --target=/target -- sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && systemctl restart sshd
  #- curtin in-target --target=/target -- systemctl stop ufw.service && systemctl disable ufw.service
  #- curtin in-target --target=/target -- echo -e "NTP=ntp1.aliyun.com\nFallbackNTP=ntp.ubuntu.com" >> /etc/systemd/timesyncd.conf && systemctl restart systemd-timesyncd
  version: 1

Ubuntu_init.sh

#!/bin/bash
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

systemctl restart sshd

systemctl stop ufw.service
systemctl disable ufw.service
# 
echo -e "NTP=ntp1.aliyun.com\nFallbackNTP=ntp.ubuntu.com" >> /etc/systemd/timesyncd.conf
systemctl restart systemd-timesyncd
# 
cat >> /etc/security/limits.conf << EOF
*       soft        nofile  655350
*       hard        nofile  655350
*       soft        nproc   655350
*       hard        nproc   655350
root        soft        nofile  655350
root        hard        nofile  655350
root        soft        nproc   655350
root        hard        nproc   655350
EOF
########################################
cp /etc/sysctl.conf /etc/sysctl.conf.bak
cat > /etc/sysctl.conf << EOF
vm.swappiness = 0
kernel.sysrq = 1

net.ipv4.neigh.default.gc_stale_time = 120

net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_slow_start_after_idle = 0
EOF

/sbin/sysctl -p

我的問題

當我在 Dell R750 或其他開放 UEFI 服務伺服器電腦上執行 pxe 自動安裝。 tftp、dhcpd、httpd 都可以。但是當伺服器執行“late-commands”之類的wgetcurl然後報告錯誤時。其他 bash 指令可以執行,也不會出現錯誤,例如echosedsystemctl start service等等。

當自動安裝錯誤時,會報告錯誤並破壞此系統安裝。我使用wget可以從我的 httpd 伺服器下載 bash 檔案並執行。

這個的圖片: 錯誤圖片

如果你打開錯誤圖片很慢,這裡是錯誤文字描述:

start: subiquity/Late/run/command_0: curtin in-target --target=/target -- /usr/bin/wget -P /root/ http://10.10.11.245/tftp/ubuntu_init.sh
start: subiquity/Meta/status_GET
finish: subiquity/Late/run/command_0: Command '['system-cat', '--level-prefix=false', '--identifier=subiquity_log.3140', 'sh', 'c', 'curtin in-target --target=/target --/usr/bin/wget -P /root/ http://10.10.11.245/tftp/ubuntu_init.sh']' returned non-zero exit status 8.ip a 

httpd日誌

10.10.11.94 - - [13/Dec/2021:15:58:40 +0800] "GET /tftp/ubuntu-20.04.3-live-server-amd64.iso HTTP/1.1" 200 1261371392 "-" "Wget"
10.10.11.94 - - [13/Dec/2021:15:59:01 +0800] "GET /tftp/ubuntu-20.04.3-live-server-amd64.iso HTTP/1.1" 200 1261371392 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:13 +0800] "GET /tftp/ubuntu-20.04.3-live-server-amd64.iso HTTP/1.1" 200 1261371392 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:25 +0800] "GET /tftp/meta-data HTTP/1.1" 200 31 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:25 +0800] "GET /tftp/user-data HTTP/1.1" 200 2772 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:25 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:26 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:27 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:28 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:29 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:30 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:31 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:32 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:33 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:34 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"
10.10.11.94 - - [13/Dec/2021:15:59:35 +0800] "GET /tftp/vendor-data HTTP/1.1" 404 214 "-" "Cloud-Init/21.2-3-g899bfaa9-0ubuntu2~20.04.1"

我手動執行沒有錯誤。


如果有人知道如何解決這個問題或與我的問題相同,請給我留言,謝謝。

如果我沒表達清楚,你可以指出。

答案1

您的問題很可能是由proxy配置引起的

  proxy: http://mirrors.aliyun.com/ubuntu

我發現如果您指定代理,那麼所有網路流量都將使用該代理。嘗試wget下載腳本是透過代理程式發送的,但失敗。

使用方法之一proxy是環境變數http_proxy和將在安裝程式環境中https_proxy設定為您的值。proxy發出 Web 請求時,wget使用這些環境變數來確定代理程式。以下是一些簡單的命令列,您可以在安裝程式環境 shell(或實際上任何 Linux 系統)中嘗試進行驗證。

這應該可以工作,因為沒有設定代理。

http_proxy= wget http://10.10.11.245/tftp/ubuntu_init.sh

這應該會出錯並退出,返回代碼8與您的日誌顯示的一樣。

http_proxy=http://mirrors.aliyun.com/ubuntu wget http://10.10.11.245/tftp/ubuntu_init.sh
echo $?

選項

有一些可用的方法可以解決這個問題

  • 不要配置proxy.
  • early_commands似乎不受 的影響proxy,因此可以下載腳本。
  early-commands:
    - /usr/bin/wget -P /run/ http://10.10.11.245/tftp/ubuntu_init.sh
  • 取消設定中的相關環境變數late-commands。必須對每個命令執行此操作。
  late-commands:
    - http_proxy= curtin in-target --target /target -- /usr/bin/wget -P /root/ http://10.10.11.245/tftp/ubuntu_init.sh

筆記

我使用 Ubuntu20.04.3安裝程式進行了測試 ( subiquity 21.08.2)

相關內容