VirtualBox 安装 Amazon linux2

  |   0 评论   |   0 浏览

  

VirtualBox 安装 Amazon linux2

环境准备

  1.下载镜像

  https://cdn.amazonlinux.com/os-images/2.0.20201111.0/virtualbox/

  2.下载引导文件

  https://cdn.amazonlinux.com/os-images/2.0.20201111.0/Seed.iso

  VirtualBox 版本 6.1,安装步骤不在本文范围

创建虚拟机

  image.png

  这边输入 linux2,VirtualBox 会帮你自动识别类型和版本,点击下一步,选择分配的内存,点击下一步,选择使用已有的虚拟硬盘文件,如下图所示:

  image.png

  选择在官网下载镜像 vdi 文件所在的位置,点击创建

使用 SSH 连接

  安装之后,发现不知道 root 密码,然后查阅相关资料,发现需要根据自身需求,生成一个 seed.iso 的引导镜像挂载到服务器上

 1 For on-prem images, we recommend using the NoCloud data source:
 2 
 3 https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
 4 
 5 On-prem images also support the AltCloud, ConfigDrive, and OVF
 6 cloud-init data sources. More information on datasources at:
 7 
 8 https://cloudinit.readthedocs.io/en/latest/topics/datasources.html#datasource-documentation
 9 
10 
11 The seed image for NoCloud can be generated by writing two YAML files,
12 meta-data and user-data, and making them part of an ISO image. This ISO
13 needs to be attached to the virtual machine on first boot. More information on
14 generating the seed ISO is at:
15 https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/amazon-linux-2-virtual-machine.html
16 
17 
18 -----BEGIN meta-data SAMPLE------
19 local-hostname: amazonlinux.onprem
20 
21 # eth0 is the default network interface enabled in the image. You can
22 # configure static network settings with an entry like below.
23 
24 network-interfaces: |
25   iface eth0 inet static
26   address 192.168.1.10
27   network 192.168.1.0
28   netmask 255.255.255.0
29   broadcast 192.168.1.255
30   gateway 192.168.1.254
31 -----END meta-data SAMPLE------
32 
33 -----BEGIN user-data SAMPLE------
34 #cloud-config
35 # vim:syntax=yaml
36 users:
37 # A user by the name ec2-user is created in the image by default.
38 - default
39 # The following entry creates user1 and assigns a plain text password.
40 # Please note Security best practises recommend not using plain text password.
41   - name: user1
42     gecos: test user1 with plain passwd configured and sudo nopasswd enabled
43     groups: sudo
44     sudo: ['ALL=(ALL) NOPASSWD:ALL']
45     plain_text_passwd: < plain text password here >
46     lock_passwd: false
47 # The following entry creates user2 and attaches a hashed password to the user.
48 # Hashed passwords can be generated with the following command on Amazon Linux 2:
49 # python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())'
50   - name: user2
51     gecos: test user2 with hashed passwd configured
52     passwd: < hashed password here >
53     lock_passwd: false
54 # The following entry creates user3, disables password-based login and enables an SSH public key.
55   - name: user3
56     gecos: test user3 with SSH key configured
57     ssh-authorized-keys:
58       - ssh-public-key-information
59     lock_passwd: true
60 chpasswd:
61   list: |
62     ec2-user:<plain text password here>
63 # In the above line, do not add any spaces after 'ec2-user:'.
64 
65 # NOTE: Cloud-init applies network settings on every boot by default. To retain network settings from first
66 boot, uncomment the following 鈥榳rite_files鈥� section:
67 #write_files:
68 #  - path: /etc/cloud/cloud.cfg.d/80_disable_network_after_firstboot.cfg
69 #    content: |
70 #       # Disable network configuration after first boot
71 #       network:
72            config: disabled
73 -----END user-data SAMPLE------
74 
75 
76 To build seed.iso from user-data and meta-data files:
77 
78 $ genisoimage  -output seed.iso -volid cidata -joliet -rock user-data meta-data

  为了尽快进入系统·本尊·,直接使用官方的 seed.iso,默认带 sudo 的用户是 user1,密码是 amazon

  重新启动系统,使用账号密码成功进入系统

  修改/etc/ssh/sshd_conf 文件,开放 SSH 账号密码登录

  基本命令和 CentOS 大同小异,没有多少出入。

  最后的效果图如下:

  image.png

---------------------------------------------------------------
>> 博客地址:https://blog.mufengs.com
>> 邮箱地址:[email protected]
>> 微信帐号:Do8080
>> Github : https://github.com/mufengcoding
---------------------------------------------------------------