首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动安装程序和云init的几个问题

自动安装程序和云init的几个问题
EN

Ask Ubuntu用户
提问于 2021-01-11 14:05:56
回答 1查看 2.4K关注 0票数 3

我来自debian,现在正在尝试为Ubuntu20.04通用安装新服务器和VM建立一个环境,并且看到debian-installer (d-i)已被废弃,不再受支持,我已经开始处理自动安装和云-init,但仍然有一些斗争。

在安装服务器并从/var/log/installer复制安装文件并对其进行少量调整之后,我可以设置一个非常原始的系统,但这仍然缺少以下内容,可以轻松地处理d。

因此,到目前为止,我所做的是:使用Apache2设置tftp,这样我就可以提供PXE映像和云init用户数据。

代码语言:javascript
复制
cat /srv/tftp/pxelinux.cfg/default
代码语言:javascript
复制
DEFAULT vesamenu.c32
TIMEOUT 100
ONTIMEOUT local
PROMPT 0

NOESCAPE 1

LABEL local
        MENU DEFAULT
        MENU LABEL boot-from-local-disk
        LOCALBOOT 0

LABEL focal-live-install
        MENU label Install focal
        KERNEL vmlinuz
        INITRD initrd
        APPEND root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url=http://172.16.16.41/tftp/ubuntu-20.04.1-live-server-amd64.iso

LABEL focal-live-install-autoinstall
        MENU label Install focal - autoinstall
        KERNEL vmlinuz
        INITRD initrd
        APPEND root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url=http://172.16.16.41/tftp/ubuntu-20.04.1-live-server-amd64.iso autoinstall ds=nocloud-net;s=http://172.16.16.41/tftp/cloud-init/
代码语言:javascript
复制
cat /etc/apache2/conf-enabled/tftp.conf
代码语言:javascript
复制
<Directory /srv/tftp>
        Options +FollowSymLinks +Indexes
        Require all granted
</Directory>
Alias /tftp /srv/tftp
代码语言:javascript
复制
cat /srv/tftp/cloud-init/user-data
代码语言:javascript
复制
#cloud-config
autoinstall:
  apt:
    geoip: true
    preserve_sources_list: false
    primary:
    - arches: [amd64, i386]
      uri: http://de.archive.ubuntu.com/ubuntu
    - arches: [default]
      uri: http://ports.ubuntu.com/ubuntu-ports
  identity: {hostname: localhost, password: <>,
    realname: ka_de_ae, username: ka_de_ae}
  keyboard: {layout: de, toggle: null, variant: ''}
  locale: en_GB
  network:
    ethernets:
      enp3s0: {dhcp4: true}
    version: 2
  ssh:
    allow-pw: true
    authorized-keys: []
    install-server: true
  user-data:
    disable_root: false
    chpasswd:
      root:<>
  storage:
    config:
    - {ptable: gpt, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: true, type: disk, id: disk-sda}
    - {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false,
      grub_device: false, type: partition, id: partition-sda1}
    - {device: disk-sda, size: 2147483648, wipe: superblock, flag: linux, number: 2,
      preserve: false, grub_device: false, type: partition, id: partition-sda2}
    - {fstype: ext4, volume: partition-sda2, preserve: false, type: format, id: format-0}
    - {device: disk-sda, size: -1, wipe: superblock, flag: linux, number: 3,
      preserve: false, grub_device: false, type: partition, id: partition-sda3}
    - name: vg0
      devices: [partition-sda3]
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - {name: root, volgroup: lvm_volgroup-0, size: 5368709120B, preserve: false, type: lvm_partition,
      id: lvm_partition-0}
    - {fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-1}
    - {device: format-1, path: /, type: mount, id: mount-1}
    - {name: swap, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false, type: lvm_partition,
      id: lvm_partition-1}
    - {fstype: swap, volume: lvm_partition-1, preserve: false, type: format, id: format-2}
    - {device: format-2, path: '', type: mount, id: mount-2}
    - {name: tmp, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false, type: lvm_partition,
      id: lvm_partition-2}
    - {fstype: ext4, volume: lvm_partition-2, preserve: false, type: format, id: format-3}
    - {device: format-3, path: /tmp, type: mount, id: mount-3}
    - {name: usr, volgroup: lvm_volgroup-0, size: 16106127360B, preserve: false, type: lvm_partition,
      id: lvm_partition-3}
    - {fstype: ext4, volume: lvm_partition-3, preserve: false, type: format, id: format-4}
    - {device: format-4, path: /usr, type: mount, id: mount-4}
    - {name: var, volgroup: lvm_volgroup-0, size: 10737418240B, preserve: false, type: lvm_partition,
      id: lvm_partition-4}
    - {fstype: ext4, volume: lvm_partition-4, preserve: false, type: format, id: format-5}
    - {device: format-5, path: /var, type: mount, id: mount-5}
    - {name: varlog, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false,
      type: lvm_partition, id: lvm_partition-5}
    - {fstype: ext4, volume: lvm_partition-5, preserve: false, type: format, id: format-6}
    - {device: format-6, path: /var/log, type: mount, id: mount-6}
    - {device: format-0, path: /boot, type: mount, id: mount-0}
    swap: {swap: 0}
  version: 1
  users:
    - name: ka_de_ae
      shell: /bin/bash
      ssh-authorized-keys:
        - ssh-rsa <key + comment>
        - ssh-rsa <key + comment>
        - ssh-rsa <key + comment>
        - ssh-rsa <key + comment>
  runcmd:
    - sed -i -e '/^#PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
    - restart ssh

这已经比最初的简单安装提前了一些步骤,但是有很多东西不起作用。

  • 主机名:我不想把固定的主机名放在那里,我想用DNS来填这个,就像我做的那样。但是如果我保留这个空白,安装程序就会停止,我必须手动完成,这不是我想要做的。使用" localhost“,就像一些人在互联网上建议的那样,只是将其设置为localhost,而不是使用来自DNS服务器的DNS名称。如何做到这一点?
  • 获取authorized_keyfile的ssh公钥不起作用。我尝试过几种方法,但仍然没有任何用户附加任何公钥。
  • 让根用户在安装后直接使用authorized_keys。当然可以,但是只要我们有一个拥有根目录权限的用户,我们就可以继续使用Ansible。但如果根能起作用,那就更好了。
  • 有其他用户在初始安装后,而不是在“身份”中的用户仍然对我不起作用。
  • 网络接口:我正在测试的服务器上有4台设备,其中一台目前只有一个链接(enp3s0),但这并不总是接口名称,我仍然缺乏一种方法,只说服务器“带链接的第一个服务器,在它上尝试DHCP,工作时,使用它,暂时忽略所有其他接口”。有点失踪的eth0这里..。
  • 也许最好把它放到一个自己的线程中,但万一它很容易回答:我们还想为服务器提供一个自己的镜像,所以我们只能将所有东西下载一次到一个中央镜像,而不是每个服务器都自己下载。但是使用镜像(只是简单的apt镜像)并不适用于云init,因为似乎缺少一些文件夹,这是必要的。

我想,从我所读到的,大部分这些事情应该是相当可行的,但我肯定错过了一些事情做的对,所以任何帮助都是值得感谢的。

EN

回答 1

Ask Ubuntu用户

发布于 2021-01-14 10:18:22

同时,对于一些要点,我找到了正确的语法。

  • 主机名:仍然不起作用。为此,我需要一些建议
  • ssh公钥:至少对于安装的一个用户来说,我现在已经开始使用ssh公钥了。我不知道为什么以前尝试的语法现在有效,也许这是第一次与正确的混合(ssh ->授权-键没有用户部分)组合。请进一步查看配置
  • root:我们放弃了使用root用户,并决定拥有一个具有管理权限的用户就足够了,从这里开始使用Ansible就足够了。
  • 其他用户:没有再次尝试该部分,因为有一个用户就足够了。
  • 网络接口:只是没有在配置中添加任何内容,而是使用了“第一个工作”部分。
  • 自己的镜子:还没做完,不知道我们在这里错过了什么。要清楚的是,如何在云-init中配置这一点是众所周知的,但如何使用自己的镜像,而不是。

对于HDD的LVM配置,我建议您从零开始手动安装一台服务器,并根据您的意愿配置磁盘,然后使用安装日志来正确处理磁盘部件。在我这么做之前,经过了几天的尝试和错误,我只是想知道,你不能像你想要的那样命名分区,更好地使用这些数字,系统会给它们命名,而不是任何其他的。执行此操作时,请将所有保留部分切换为false,并将最后一个分区的大小切换为-1以使用整个磁盘空间。

当前正在工作的用户-数据:

代码语言:javascript
复制
#cloud-config
autoinstall:
  package_upgrade: true
  packages:
    - zsh
    - tmux
    - nmap
    - curl
    - wget
    - git
    - htop
    - iperf
    - fail2ban
    - vim
    - net-tools
  apt:
    geoip: true
    preserve_sources_list: false
    primary:
    - arches: [amd64, i386]
      uri: http://de.archive.ubuntu.com/ubuntu
    - arches: [default]
      uri: http://ports.ubuntu.com/ubuntu-ports
  identity: {hostname: localhost, password: <password>,
    username: ansible, realname: ansible}
  keyboard: {layout: de, toggle: null, variant: ''}
  locale: en_GB
  ssh:
    allow-pw: true
    install-server: true
    authorized-keys:
      - ssh-rsa ...
      - ssh-rsa ...
  user-data:
    disable_root: true
  storage:
    config:
    - {ptable: gpt, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: true, type: disk, id: disk-sda}
    - {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false,
      grub_device: false, type: partition, id: partition-sda1}
    - {device: disk-sda, size: 2147483648, wipe: superblock, flag: linux, number: 2,
      preserve: false, grub_device: false, type: partition, id: partition-sda2}
    - {fstype: ext4, volume: partition-sda2, preserve: false, type: format, id: format-0}
    - {device: disk-sda, size: -1, wipe: superblock, flag: linux, number: 3,
      preserve: false, grub_device: false, type: partition, id: partition-sda3}
    - name: vg0
      devices: [partition-sda3]
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - {name: root, volgroup: lvm_volgroup-0, size: 5368709120B, preserve: false, type: lvm_partition,
      id: lvm_partition-0}
    - {fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-1}
    - {device: format-1, path: /, type: mount, id: mount-1}
    - {name: swap, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false, type: lvm_partition,
      id: lvm_partition-1}
    - {fstype: swap, volume: lvm_partition-1, preserve: false, type: format, id: format-2}
    - {device: format-2, path: '', type: mount, id: mount-2}
    - {name: tmp, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false, type: lvm_partition,
      id: lvm_partition-2}
    - {fstype: ext4, volume: lvm_partition-2, preserve: false, type: format, id: format-3}
    - {device: format-3, path: /tmp, type: mount, id: mount-3}
    - {name: usr, volgroup: lvm_volgroup-0, size: 16106127360B, preserve: false, type: lvm_partition,
      id: lvm_partition-3}
    - {fstype: ext4, volume: lvm_partition-3, preserve: false, type: format, id: format-4}
    - {device: format-4, path: /usr, type: mount, id: mount-4}
    - {name: var, volgroup: lvm_volgroup-0, size: 10737418240B, preserve: false, type: lvm_partition,
      id: lvm_partition-4}
    - {fstype: ext4, volume: lvm_partition-4, preserve: false, type: format, id: format-5}
    - {device: format-5, path: /var, type: mount, id: mount-5}
    - {name: varlog, volgroup: lvm_volgroup-0, size: 4294967296B, preserve: false,
      type: lvm_partition, id: lvm_partition-5}
    - {fstype: ext4, volume: lvm_partition-5, preserve: false, type: format, id: format-6}
    - {device: format-6, path: /var/log, type: mount, id: mount-6}
    - {device: format-0, path: /boot, type: mount, id: mount-0}
    swap: {swap: 0}
  version: 1
  late-commands:
    - echo 'ansible ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ansible
票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1307054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档