Install EVE-NG in ESXI

PS:如果可以,还是建议使用物理机安装EVE NG,另外PNET也是一个不错的选择,算是另一个纯免费的开源软件,跟EVE NG用的一样的核心文件,但不像EVE NG高级功能需要收费,PNET纯免费;

安装EVE NG

直接从官网选择OVF的Image下载,通过ESXI新建虚拟机时,拖拽OVF和VMDK两个文件进去;安装完后配置CPU/Memory/硬盘等,并且在CPU中打开嵌套虚拟化的设置;

配置EVE NG

安装完后,进去按照提示配置,完成配置启动后发现没有IP,怀疑是我的服务器不能访问外网的原因,因此手动配置IP以及调整SSH的端口:

root@eve-ng:~# lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.7 LTS
Release:        16.04
Codename:       xenial

root@eve-ng:~# dpkg -l eve-ng
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                    Version          Architecture     Description
+++-=======================-================-================-===================================================
ii  eve-ng                  2.0.3-112        amd64            A new generation software for networking labs.
root@eve-ng:~# more /etc/network/interfaces
......
# The primary network interface
iface eth0 inet manual
auto pnet0
iface pnet0 inet static
    bridge_ports eth0
    bridge_stp off
    address 172.16.211.154
    netmask 255.255.255.0
    gateway 172.16.211.1

更新SSH端口后重启进程

root@eve-ng:~# /etc/init.d/ssh restart

备份文件

我之所以重新安装,就是因为改了一些参数导致点击创建node没任何反应,感觉EVE 还是很脆弱的,所以重新安装后第一件事就是先备份文件;备份操作可以参考这里:How to backup content of EVE-NG

/opt/unetlab/addons/
/opt/unetlab/tmp/
/opt/unetlab/labs/
/opt/unetlab/evedb.gz
/opt/unetlab/html/templates/
/opt/unetlab/html/images/
/opt/unetlab/html/includes/config.yml
/opt/unetlab/html/includes/custom_templates.yml

添加定制Image-qcow2

建议参考“EVE-Comm-Book-1.11-2021.pdf”中的12.3,讲的很详细,可以去官网查阅:

https://www.eve-ng.net/index.php/documentation/community-cookbook/

添加定制Image-ISO

建议参考官网的文章,如下:

https://www.eve-ng.net/index.php/documentation/howtos/howto-create-own-windows-host-on-the-eve/

保存现有Image变动的配置

当对Linux Server做了很多变动后(如地址分配,软件安装,调试等),重启这个节点,变动不会消失;但如果想在其他拓扑中调用这个image,所有变动都被初始化了,那么是否有方法把变动的配置提交给原始镜像,下次再调用时就不用再次重复配置了呢?答案当然是“有的”;

其实很简单,默认EVE会把image放在一个特定目录下 /opt/unetlab/addons/qemu/xxxx/”,当lab启动后,会从这里拷贝image到临时目录,例如“/opt/unetlab/tmp/1/76a357d5-7484-41a2-856c-a0bcfe66fac0/29”,此时对image的操作,配置变更,都只会改变这个临时文件,即使设备重启,这些配置仍然会保留,除非wipe了设备,相当于格式化,重新拷贝一个新的image,所有配置就会没了,那么如何把改变的配置提交给原始的image?其实一条命令即可,注意执行commit需要先把设备关闭

root@eve-ng:/opt/unetlab/tmp/1/76a357d5-7484-41a2-856c-a0bcfe66fac0/29# qemu-img info hda.qcow2   
image: hda.qcow2
file format: qcow2
virtual size: 100G (107374182400 bytes)
disk size: 4.2G
cluster_size: 65536
backing file: /opt/unetlab/addons/qemu/linux-centos7/hda.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
root@eve-ng:/opt/unetlab/tmp/1/76a357d5-7484-41a2-856c-a0bcfe66fac0/29# qemu-img commit hda.qcow2 
Image committed.
root@eve-ng:/opt/unetlab/tmp/1/76a357d5-7484-41a2-856c-a0bcfe66fac0/29# qemu-img info hda.qcow2 
image: hda.qcow2
file format: qcow2
virtual size: 100G (107374182400 bytes)
disk size: 260K
cluster_size: 65536
backing file: /opt/unetlab/addons/qemu/linux-centos7/hda.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
root@eve-ng:/opt/unetlab/tmp/1/76a357d5-7484-41a2-856c-a0bcfe66fac0/29# ls -l
total 264
-rw-rw-r-- 1 root unl 262144 Aug 10 23:01 hda.qcow2
-rw-rw-r-- 1 root unl    122 Aug 10 22:59 wrapper.txt

2022-06-13更新:扩容原有qcow2的硬盘

对于LVM的扩容,之前总结过,可以参考这篇文章:How to resize LVM on Centos7/Ubuntu14.04 。由于公司版本的Linux默认没有使用LVM,直接使用物理介质,那么物理介质如何扩容呢?网上查了下,感觉比较麻烦,因为默认是没办法直接对正在使用的分区进行扩容或缩容的,需要通过宿主机挂在这个虚拟盘,然后通过分区工具融合,就如同你拿U盘安装了一个winpe,然后用这个U盘启动,然后通过U盘中的分区管理工具对原有磁盘进行操作,可以参考这篇文章:How to resize a qcow2 disk image on Linux

经过与同事讨论,发现一种很容易的方法:改写分区表,然后根据分区表再更新磁盘空间,这种操作同样可以做到无损扩容,下面是操作部署:

qcow2现有虚拟磁盘大小

root@eve-ng:/opt/unetlab/tmp/3/f547b082-a364-4737-bbd9-898793f6f066/5# qemu-img info hda.qcow2 
image: hda.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 47M
cluster_size: 65536
backing file: /opt/unetlab/addons/qemu/linux-pke-bm-4-19-95-17-20210630/hda.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

虚拟机现有分区信息

[root@server3] ~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.7G     0  7.7G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           7.8G  584K  7.8G   1% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda2        15G  7.7G  7.4G  52% /
tmpfs           1.6G     0  1.6G   0% /run/user/0

增加qcow2的虚拟硬盘大小

root@eve-ng:/opt/unetlab/tmp/3/f547b082-a364-4737-bbd9-898793f6f066/5# qemu-img resize hda.qcow2 +300G
Image resized.
root@eve-ng:/opt/unetlab/tmp/3/f547b082-a364-4737-bbd9-898793f6f066/5# qemu-img info hda.qcow2 
image: hda.qcow2
file format: qcow2
virtual size: 320G (343597383680 bytes)
disk size: 47M
cluster_size: 65536
backing file: /opt/unetlab/addons/qemu/linux-pke-bm-4-19-95-17-20210630/hda.qcow2
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

查看扩容后的分区信息

看上去应该是因为sda1采用的是GPT(对硬盘大小无限制),导致fdisk(只支持2TB以下的硬盘分区)查看不聊sda2,通过parted 修复下,fdisk就可以查阅这部分分区了:

[root@server3] ~$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
fd0      2:0    1    4K  0 disk 
sda      8:0    0  220G  0 disk 
├─sda2   8:2    0   15G  0 part /
└─sda1   8:1    0    2M  0 part 
[root@server3] ~$ fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 236.2 GB, 236223201280 bytes, 461373440 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1    41943039    20971519+  ee  GPT
[root@server3] ~$ parted -l /dev/sad
Error: The backup GPT table is not at the end of the disk, as it should be.
This might mean that another operating system believes the disk is smaller.
Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? Fix                                                    
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 419430400 blocks) or continue with the current setting?                                                               
Fix/Ignore? Fix                                                           
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sda: 236GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name    Flags
 1      1049kB  3146kB  2097kB                       bios_grub
 2      3146kB  16.1GB  16.1GB  xfs          "root"
[root@server3] ~$ fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 236.2 GB, 236223201280 bytes, 461373440 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: D5B2A65C-111A-4BC0-ABFD-DAEFFA154434


#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot       
 2         6144     31457280     15G  Linux filesyste "root"

删除现有分区表

分区表只会记录着硬盘的寻址地址和格式,跟真实内容分开,所以我们可以用“sgdisk”删除分区表,再增加一个新的分区表,让这个分区表的Start和End包含了扩容的那部分空间即可,重启生效:

[root@server3] ~$ /usr/sbin/sgdisk --set-alignment=1 --delete=2 --new=2:6144:0 --change-name=2:\"root\" --typecode=2:8300 /dev/sda
Setting name!
partNum is 1
REALLY setting name!
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[root@server3] ~$ fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 236.2 GB, 236223201280 bytes, 461373440 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: D5B2A65C-111A-4BC0-ABFD-DAEFFA154434


#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot       
 2         6144    461373406    220G  Linux filesyste "root"
[root@server3] ~$ reboot

扩容硬盘空间

通过“lsblk”可以看到硬盘已经扩容了,但“df -H”看不出来,使用“xfs_growfs”进行扩容;

PS:使用“xfs_growfs”命令增加 XFS 文件系统的大小,必须挂载 XFS 文件系统,并且底层设备上必须有可用空间,另外只能扩,不能缩;

[root@server3] ~$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
fd0      2:0    1    4K  0 disk 
sda      8:0    0  220G  0 disk 
├─sda2   8:2    0  220G  0 part /
└─sda1   8:1    0    2M  0 part 
[root@server3] ~$ df -H
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.1G     0  4.1G   0% /dev
tmpfs           4.1G     0  4.1G   0% /dev/shm
tmpfs           4.1G  635k  4.1G   1% /run
tmpfs           4.1G     0  4.1G   0% /sys/fs/cgroup
/dev/sda2        17G   15G  1.5G  91% /
tmpfs           810M     0  810M   0% /run/user/0
[root@server3] ~$ xfs_growfs /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=15, agsize=262144 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3931392, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3931392 to 57670907
[root@server3] ~$ 
[root@server3] ~$ df -H
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.1G     0  4.1G   0% /dev
tmpfs           4.1G     0  4.1G   0% /dev/shm
tmpfs           4.1G  635k  4.1G   1% /run
tmpfs           4.1G     0  4.1G   0% /sys/fs/cgroup
/dev/sda2       237G   15G  222G   7% /
tmpfs           810M     0  810M   0% /run/user/0
本文出自 Frank's Blog

版权声明:


本文链接:Install EVE-NG in ESXI
版权声明:本文为原创文章,仅代表个人观点,版权归 Frank Zhao 所有,转载时请注明本文出处及文章链接
你可以留言,或者trackback 从你的网站

留言哦

blonde teen swallows load.xxx videos