自动服务器安装配置文件顶级键“late-commands”不能使用 wget 或 curl

自动服务器安装配置文件顶级键“late-commands”不能使用 wget 或 curl

我遇到了有关自动服务器安装的问题。

这是我的环境:服务器:centos 7.6 x86_64(它是一个 kvm 系统)节点 1:无系统节点 2:无系统

我想自动安装 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命令可以执行而没有错误,例如echo,,sed等等systemctl 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_proxyhttps_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

相关内容