美文网首页
pve模板制作cloud-init

pve模板制作cloud-init

作者: 小黑佬 | 来源:发表于2021-06-08 12:15 被阅读0次

    ubuntu

       33  wget http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img
       37  qm create 9000 --memory 1024 --net0 virtio,bridge=vmbr0
       38  qm importdisk 9000 ubuntu-20.04-server-cloudimg-amd64.img local-lvm
       39  qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
       40  qm set 9000 --ide0 local-lvm:cloudinit
       41  qm set 9000 --boot c --bootdisk scsi0
       42  qm set 9000 --serial0 socket --vga serial0
       43  qm template 9000
    
    

    centos

    
    root@pve:/var/lib/vz/template/iso# wget https://cloud.centos.org/centos/7/images/CentOS-7-x86_             64-GenericCloud.qcow2
    --2021-06-08 11:42:39--  https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud             .qcow2
    Resolving cloud.centos.org (cloud.centos.org)... 18.188.140.33
    Connecting to cloud.centos.org (cloud.centos.org)|18.188.140.33|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 858783744 (819M) [application/octet-stream]
    Saving to: 'CentOS-7-x86_64-GenericCloud.qcow2'
    
    CentOS-7-x86_64-Generic 100%[=============================>] 819.00M  11.1MB/s    in 76s
    
    2021-06-08 11:43:56 (10.8 MB/s) - 'CentOS-7-x86_64-GenericCloud.qcow2' saved [858783744/858783             744]
    
    root@pve:/var/lib/vz/template/iso# qm create 8000 --memory 1024 --net0 virtio,bridge=vmbr0
    root@pve:/var/lib/vz/template/iso# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master vmbr0 state UP group defau             lt qlen 1000
        link/ether 2c:ea:7f:ed:49:20 brd ff:ff:ff:ff:ff:ff
    3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 2c:ea:7f:ed:49:21 brd ff:ff:ff:ff:ff:ff
    4: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 2c:ea:7f:ed:49:22 brd ff:ff:ff:ff:ff:ff
    5: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 2c:ea:7f:ed:49:23 brd ff:ff:ff:ff:ff:ff
    6: vmbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen              1000
        link/ether 2c:ea:7f:ed:49:20 brd ff:ff:ff:ff:ff:ff
        inet 192.168.5.253/24 brd 192.168.5.255 scope global vmbr0
           valid_lft forever preferred_lft forever
        inet6 fe80::2eea:7fff:feed:4920/64 scope link
           valid_lft forever preferred_lft forever
    20: tap100i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master fwbr1             00i0 state UNKNOWN group default qlen 1000
        link/ether c6:ae:83:b8:4a:71 brd ff:ff:ff:ff:ff:ff
    21: fwbr100i0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default              qlen 1000
        link/ether 72:f9:d0:a6:89:d4 brd ff:ff:ff:ff:ff:ff
    22: fwpr100p0@fwln100i0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master vmbr0              state UP group default qlen 1000
        link/ether 86:82:a6:6a:ee:ed brd ff:ff:ff:ff:ff:ff
    23: fwln100i0@fwpr100p0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master fwbr1             00i0 state UP group default qlen 1000
        link/ether 72:f9:d0:a6:89:d4 brd ff:ff:ff:ff:ff:ff
    33: tap101i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether 56:3f:ee:ac:ee:71 brd ff:ff:ff:ff:ff:ff
    34: tap104i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether a6:3e:30:4d:cc:cb brd ff:ff:ff:ff:ff:ff
    37: tap103i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether 46:f1:61:b5:4d:cc brd ff:ff:ff:ff:ff:ff
    38: tap105i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether 36:e0:c9:26:67:75 brd ff:ff:ff:ff:ff:ff
    39: tap106i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether 22:2d:fe:ff:51:3d brd ff:ff:ff:ff:ff:ff
    40: tap107i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether 52:0f:c1:04:e7:33 brd ff:ff:ff:ff:ff:ff
    41: tap108i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether a2:db:dd:26:2a:b6 brd ff:ff:ff:ff:ff:ff
    42: tap102i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vmbr0              state UNKNOWN group default qlen 1000
        link/ether ba:16:0f:b5:3b:b9 brd ff:ff:ff:ff:ff:ff
    55: tap109i0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master fwbr1             09i0 state UNKNOWN group default qlen 1000
        link/ether 62:6a:21:c3:ba:79 brd ff:ff:ff:ff:ff:ff
    56: fwbr109i0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default              qlen 1000
        link/ether 2a:cb:44:a1:3a:56 brd ff:ff:ff:ff:ff:ff
    57: fwpr109p0@fwln109i0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master vmbr0              state UP group default qlen 1000
        link/ether ae:46:b2:25:00:5d brd ff:ff:ff:ff:ff:ff
    58: fwln109i0@fwpr109p0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master fwbr1             09i0 state UP group default qlen 1000
        link/ether 2a:cb:44:a1:3a:56 brd ff:ff:ff:ff:ff:ff
    root@pve:/var/lib/vz/template/iso# ls
    CentOS-7-x86_64-GenericCloud.qcow2                   ubuntu-20.04-server-cloudimg-amd64.img
    CentOS-8.3.2011-x86_64-minimal.iso                   ubuntu-20.04-server-cloudimg-amd64.vmdk
    cn_windows_10_multiple_editions_x64_dvd_6848463.iso  ubuntu-20.04.2-live-server-amd64.iso
    root@pve:/var/lib/vz/template/iso# qm importdisk 8000 CentOS-7-x86_64-GenericCloud.qcow2 local             -lvm
    importing disk 'CentOS-7-x86_64-GenericCloud.qcow2' to VM 8000 ...
      Logical volume "vm-8000-disk-0" created.
    transferred 0.0 B of 8.0 GiB (0.00%)
    transferred 100.8 MiB of 8.0 GiB (1.23%)
    transferred 193.3 MiB of 8.0 GiB (2.36%)
    transferred 293.3 MiB of 8.0 GiB (3.58%)
    transferred 393.2 MiB of 8.0 GiB (4.80%)
    transferred 494.0 MiB of 8.0 GiB (6.03%)
    transferred 593.9 MiB of 8.0 GiB (7.25%)
    transferred 693.9 MiB of 8.0 GiB (8.47%)
    transferred 793.8 MiB of 8.0 GiB (9.69%)
    transferred 893.7 MiB of 8.0 GiB (10.91%)
    transferred 993.7 MiB of 8.0 GiB (12.13%)
    transferred 1.1 GiB of 8.0 GiB (13.36%)
    transferred 1.2 GiB of 8.0 GiB (14.58%)
    transferred 1.3 GiB of 8.0 GiB (15.80%)
    transferred 1.4 GiB of 8.0 GiB (17.02%)
    transferred 1.5 GiB of 8.0 GiB (18.24%)
    transferred 1.5 GiB of 8.0 GiB (19.36%)
    transferred 1.6 GiB of 8.0 GiB (20.44%)
    transferred 1.7 GiB of 8.0 GiB (21.63%)
    transferred 1.8 GiB of 8.0 GiB (22.85%)
    transferred 1.9 GiB of 8.0 GiB (24.02%)
    transferred 2.0 GiB of 8.0 GiB (25.25%)
    transferred 2.1 GiB of 8.0 GiB (26.47%)
    transferred 2.2 GiB of 8.0 GiB (27.69%)
    transferred 2.3 GiB of 8.0 GiB (28.91%)
    transferred 2.4 GiB of 8.0 GiB (30.13%)
    transferred 2.5 GiB of 8.0 GiB (31.36%)
    transferred 2.6 GiB of 8.0 GiB (32.39%)
    transferred 2.7 GiB of 8.0 GiB (33.45%)
    transferred 2.8 GiB of 8.0 GiB (34.54%)
    transferred 2.9 GiB of 8.0 GiB (35.69%)
    transferred 3.0 GiB of 8.0 GiB (36.91%)
    transferred 3.0 GiB of 8.0 GiB (37.92%)
    transferred 3.1 GiB of 8.0 GiB (39.14%)
    transferred 3.2 GiB of 8.0 GiB (40.36%)
    transferred 3.3 GiB of 8.0 GiB (41.58%)
    transferred 3.4 GiB of 8.0 GiB (42.60%)
    transferred 3.5 GiB of 8.0 GiB (43.63%)
    transferred 3.6 GiB of 8.0 GiB (44.86%)
    transferred 3.7 GiB of 8.0 GiB (46.08%)
    transferred 3.8 GiB of 8.0 GiB (47.30%)
    transferred 3.9 GiB of 8.0 GiB (48.52%)
    transferred 4.0 GiB of 8.0 GiB (49.74%)
    transferred 4.1 GiB of 8.0 GiB (50.97%)
    transferred 4.2 GiB of 8.0 GiB (52.19%)
    transferred 4.3 GiB of 8.0 GiB (53.41%)
    transferred 4.4 GiB of 8.0 GiB (54.56%)
    transferred 4.5 GiB of 8.0 GiB (55.78%)
    transferred 4.6 GiB of 8.0 GiB (57.01%)
    transferred 4.6 GiB of 8.0 GiB (58.02%)
    transferred 4.7 GiB of 8.0 GiB (59.21%)
    transferred 4.8 GiB of 8.0 GiB (60.44%)
    transferred 4.9 GiB of 8.0 GiB (61.66%)
    transferred 5.0 GiB of 8.0 GiB (62.88%)
    transferred 5.1 GiB of 8.0 GiB (63.94%)
    transferred 5.2 GiB of 8.0 GiB (64.96%)
    transferred 5.3 GiB of 8.0 GiB (66.19%)
    transferred 5.4 GiB of 8.0 GiB (67.37%)
    transferred 5.5 GiB of 8.0 GiB (68.37%)
    transferred 5.6 GiB of 8.0 GiB (69.59%)
    transferred 5.7 GiB of 8.0 GiB (70.81%)
    transferred 5.7 GiB of 8.0 GiB (71.85%)
    transferred 5.8 GiB of 8.0 GiB (73.07%)
    transferred 5.9 GiB of 8.0 GiB (74.30%)
    transferred 6.0 GiB of 8.0 GiB (75.52%)
    transferred 6.1 GiB of 8.0 GiB (76.74%)
    transferred 6.2 GiB of 8.0 GiB (77.96%)
    transferred 6.3 GiB of 8.0 GiB (78.97%)
    transferred 6.4 GiB of 8.0 GiB (80.19%)
    transferred 6.5 GiB of 8.0 GiB (81.41%)
    transferred 6.6 GiB of 8.0 GiB (82.52%)
    transferred 6.7 GiB of 8.0 GiB (83.74%)
    transferred 6.8 GiB of 8.0 GiB (84.75%)
    transferred 6.9 GiB of 8.0 GiB (85.90%)
    transferred 7.0 GiB of 8.0 GiB (87.12%)
    transferred 7.1 GiB of 8.0 GiB (88.35%)
    transferred 7.2 GiB of 8.0 GiB (89.48%)
    transferred 7.3 GiB of 8.0 GiB (90.70%)
    transferred 7.4 GiB of 8.0 GiB (91.92%)
    transferred 7.5 GiB of 8.0 GiB (93.14%)
    transferred 7.5 GiB of 8.0 GiB (94.36%)
    transferred 7.6 GiB of 8.0 GiB (95.59%)
    transferred 7.7 GiB of 8.0 GiB (96.81%)
    transferred 7.8 GiB of 8.0 GiB (98.00%)
    transferred 7.9 GiB of 8.0 GiB (99.22%)
    transferred 8.0 GiB of 8.0 GiB (100.00%)
    transferred 8.0 GiB of 8.0 GiB (100.00%)
    Successfully imported disk as 'unused0:local-lvm:vm-8000-disk-0'
    
    Successfully imported disk as 'unused0:local-lvm:vm-8000-disk-0'
    root@pve:/var/lib/vz/template/iso# qm set 8000 --scsi
    --scsi0   --scsi12  --scsi16  --scsi2   --scsi23  --scsi27  --scsi30  --scsi7
    --scsi1   --scsi13  --scsi17  --scsi20  --scsi24  --scsi28  --scsi4   --scsi8
    --scsi10  --scsi14  --scsi18  --scsi21  --scsi25  --scsi29  --scsi5   --scsi9
    --scsi11  --scsi15  --scsi19  --scsi22  --scsi26  --scsi3   --scsi6   --scsihw
    root@pve:/var/lib/vz/template/iso# qm set 8000 --scsihw virtio-scsi-pci --scsi
    --scsi0   --scsi12  --scsi16  --scsi2   --scsi23  --scsi27  --scsi30  --scsi7
    --scsi1   --scsi13  --scsi17  --scsi20  --scsi24  --scsi28  --scsi4   --scsi8
    --scsi10  --scsi14  --scsi18  --scsi21  --scsi25  --scsi29  --scsi5   --scsi9
    --scsi11  --scsi15  --scsi19  --scsi22  --scsi26  --scsi3   --scsi6   --scsihw
    root@pve:/var/lib/vz/template/iso# qm set 8000 --scsihw virtio-scsi-pci --scsi
    --scsi0   --scsi12  --scsi16  --scsi2   --scsi23  --scsi27  --scsi30  --scsi7
    --scsi1   --scsi13  --scsi17  --scsi20  --scsi24  --scsi28  --scsi4   --scsi8
    --scsi10  --scsi14  --scsi18  --scsi21  --scsi25  --scsi29  --scsi5   --scsi9
    --scsi11  --scsi15  --scsi19  --scsi22  --scsi26  --scsi3   --scsi6   --scsihw
    root@pve:/var/lib/vz/template/iso# qm set 8000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-8000-disk-0
    update VM 8000: -scsi0 local-lvm:vm-8000-disk-0 -scsihw virtio-scsi-pci
    root@pve:/var/lib/vz/template/iso# qm set 8000 --scsihw virtio-scsi-pci --ide0 local-lvm:cloudinit
    update VM 8000: -ide0 local-lvm:cloudinit -scsihw virtio-scsi-pci
      Logical volume "vm-8000-cloudinit" created.
    root@pve:/var/lib/vz/template/iso# qm set 8000 --boot
    --boot      --bootdisk
    root@pve:/var/lib/vz/template/iso# qm set 8000 --boot
    CentOS-7-x86_64-GenericCloud.qcow2                   ubuntu-20.04-server-cloudimg-amd64.img
    CentOS-8.3.2011-x86_64-minimal.iso                   ubuntu-20.04-server-cloudimg-amd64.vmdk
    cn_windows_10_multiple_editions_x64_dvd_6848463.iso  ubuntu-20.04.2-live-server-amd64.iso
    root@pve:/var/lib/vz/template/iso# qm set 8000 --boot c --boot
    --boot      --bootdisk
    root@pve:/var/lib/vz/template/iso# qm set 8000 --boot c --boot
    --boot      --bootdisk
    root@pve:/var/lib/vz/template/iso# qm set 8000 --boot c --bootdisk  scsi0
    update VM 8000: -boot c -bootdisk scsi0
    root@pve:/var/lib/vz/template/iso# qm set 8000 --serial0 socket --vga serial0
    update VM 8000: -serial0 socket -vga serial0
    root@pve:/var/lib/vz/template/iso# qm template 8000
      Renamed "vm-8000-disk-0" to "base-8000-disk-0" in volume group "pve"
      Logical volume pve/base-8000-disk-0 changed.
      WARNING: Combining activation change with other commands is not advised.
    
    

    优化版centos 修改时区

     导入镜像
    创建vm
    qm create 8000 --memory 2048 --name CentOS-7-template --net0 virtio,bridge=vmbr0
    
    导入下载的镜像到local-lvm 存储空间
    qm importdisk 8000 CentOS-7-x86_64-GenericCloud.qcow2 local-lvm
    
    将导入的磁盘以 scsi 方式挂载到虚拟机上面
    qm set 8000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-8000-disk-0
    
    添加 Cloud-Init CDROM 驱动(必须添加这个vm才能启动cloud-init)
    qm set 8000 --ide2 local-lvm:cloudinit
    
    qm set 8000 --serial0 socket --vga serial0
    
    设置启动
    qm set 8000 --boot c --bootdisk scsi0
    
    启动后
    修改时区
    timedatectl set-timezone Asia/Shanghai
    

    提示命令行设置完毕后,可以登录web界面查看模板的配置信息是否正确。可以参考ubuntu的步骤,centos只是我记录的一个过程,用于对照参考。

    相关文章

      网友评论

          本文标题:pve模板制作cloud-init

          本文链接:https://www.haomeiwen.com/subject/fmwdeltx.html