2018-12-11 ova模板的制作

1.下载 VMware vSphere Command Line Interface 6.5

https://my.vmware.com/zh/web/vmware/details?productId=614&downloadGroup=VS-CLI-65

2. 安裝套件
# yum install epel-release
# yum update
# yum install openssl-devel cpan perl-Devel-StackTrace perl-Class-Data-Inheritable perl-Convert-ASN1 perl-Crypt-OpenSSL-RSA perl-Exception-Class perl-Archive-Zip perl-Try-Tiny perl-Crypt-SSLeay perl-XML-SAX perl-XML-NamespaceSupport perl-libxml-perl perl-XML-LibXML perl-Socket6 perl-IO-Socket-INET6 libuuid-devel perl-Crypt-OpenSSL-X509 perl-Path-Class perl-Class-MethodMaker perl-Data-UUID perl-Data-Dump perl-SOAP-Lite perl-Net-INET6Glue

# PERL_MM_USE_DEFAULT=1 cpan install BINGOS/ExtUtils-MakeMaker-6.96.tar.gz LEONT/Module-Build-0.4205.tar.gz GBARR/libnet-1.22.tar.gz GAAS/libwww-perl-5.837.tar.gz PERLER/UUID-Random-0.04.tar.gz

3. 解压缩
# tar xvzf VMware-vSphere-CLI-6.5.0-4566394.x86_64.tar.gz

4. 切換目录
# cd vmware-vsphere-cli-distrib

5. 进行安裝
# ./vmware-install.pl --prefix=/opt/vmwarecli EULA_AGREED=yes --default
Creating a new vSphere CLI installer database using the tar4 format.

Installing vSphere CLI 6.5.0 build-4566394 for Linux.

This vSphere CLI installer includes precompiled Perl modules for RHEL.
Answering yes will install the precompiled modules, and answering no will
install from CPAN.
Do you want to install precompiled Perl modules for RHEL?
[yes]

Please wait while copying vSphere CLI files...

The installation of vSphere CLI 6.5.0 build-4566394 for Linux completed
successfully. You can decide to remove this software from your system at any
time by invoking the following command:
"/opt/vmwarecli/bin/vmware-uninstall-vSphere-CLI.pl".

This installer has successfully installed both vSphere CLI and the vSphere SDK
for Perl.

The following Perl modules were found on the system but may be too old to work
with vSphere CLI:

Devel::StackTrace 1.31 or newer
MIME::Base64 3.14 or newer
Try::Tiny 0.22 or newer
LWP 6.15 or newer
Socket6  0.23 or newer
IO::Socket::INET6 2.71 or newer
Net::HTTP 6.09 or newer

Enjoy,

--the VMware team

6.查询所有虚拟机

[root@node03 ~] vmware-cmd -H vcenter_ip  -U 用户名 -P 密码 -l 


/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/centos7/centos7.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/volume-8eb77f9c-f3ee-4169-abe8-d55c4620539a/volume-8eb77f9c-f3ee-4169-abe8-d55c4620539a.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/gsq001/gsq001.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/docker-registry/docker-registry.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/新建虚拟机_1/新建虚拟机.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/新建虚拟机_2/新建虚拟机.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/新建虚拟机_3/新建虚拟机.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/KOlla-OVA/KOlla-OVA.vmx
/vmfs/volumes/5bbf8006-43a9107c-464d-e8611f1d738e/VMware vCenter Server Appliance/VMware vCenter Server Appliance.vmx
/vmfs/volumes/5bc064b9-6c5f7f41-e3d8-e8611f1d738e/VMware-NSX-Manager-6.4.3-9927516/VMware-NSX-Manager-6.4.3-9927516.vmx
 

 

二.ovftool安装使用

二、安装

已linux 版本为例:

  下载下来之后,直接sh 运行即可:

root@ubuntu:~# sh VMware-ovftool-4.1.0-2459827-lin.x86_64.bundle

三、OVA、OVF模板部署

  ovftool安装完即可用,其userguide文档里提供了很多可选参数,下面是我实际使用过程中用的一个语法,基本包含了可能会用到的几个参数::

root@ubuntu:~# ovftool --X:logLevel=verbose \ 
--X:logFile=/root/deploy_log-`date +%Y%m%d` \
 --noSSLVerify --acceptAllEulas \
 -dm=thin  -vf=Templates \
 -ds=POD01-VOL 
 /data/template/centos/MyTest-CentOS6.5-64bit-V1.ova \
 'vi://username:password@pod01-vcenter/POD01(TEST-POD)/host/POD01-CLU01/pod01-clu01-h001.cdscloud.local'

如果ova/ovf模板网卡里带portgroup,一块网卡用参数:-nw或者--network后跟目标网络;

多个网卡可以用--net指定源和目标portgroup,格式类似--net:source-portgroup=target-portgroup:

例如:

--net:vlan10-pod01-Test-Private=vlan11-pod01-Test-Private

多个网卡使用多个--net指定。

参数详解:

--X:logLevel:定义log的级别;

--X:logFile:定义log文件位置,以日期的格式命名;

--noSSLVerify:跳过vSphere连接的SSL认证;

--acceptAllEulas:接受所有用户的licenses;

-dm(--diskMode): 磁盘类型,一般选用thin置备,如果不加此参数,默认硬盘厚置备类型;

-vf(--vmFolder):模板部署的目标目录(即文件夹),我这里假设要部署到Templates目录下面;

-ds(--datastore):模板部署的目标存储位置

vi:// : 全称”VMware Infrastructure“,用来和数据中心通信的命令行选项,最早是ESX 3版本的一个术语。格式:”username:password@vcenter名称/数据中心名称/host/指定host“;也可以只指定到cluster。

其中:

/data/template/centos/MyTest-CentOS6.5-64bit-V1.ova是ova文件的位置;

pod01-vcenter是vcenter的名称;

POD01(TEST-POD)是数据中心的名称;

host后面接模板部署目标host位置,CLU01代表集群,pod1-clu01-h001.jx.local是集群下的一台宿主机;

需要注意的是,这里的dns要设置好,或者也可用ip地址代替,比如:

vi://username:password@192.168.1.1/?ip=192.168.100.1'

192.168.1.1是vcenter的地址,192.168.100.1是目标宿主机的ip地址;

这里跟vcenter的连接也可以用http的形式,具体详见官方文档。

四、模板导出

导出成ova/ovf模板的常用命令:

ovftool -o \
--powerOffSource \
 --acceptAllEulas \
 --machineOutput \
 --X:logLevel=verbose \
 --X:logFile=log.log  \
 --noSSLVerify  \
 "vi://username:password@pod01-vcenter/POD01(TEST-POD)/vm/MyTestVM" /root/MyTestVM.ova

参数介绍:

-o(--overwrite):如果导出的文件名已存在,强制重写;

--powerOffSource:确保VM在被导出之前处于关机的状态

--machineOutput:以机器可读的格式输出ovftool的信息;

另外需要注意的一点是ovftool导出的文件权限问题,默认是600,建议改成644。

五、自动部署

  如果有多个ova文件,自动部署的时候简单点的加个for循环用shell脚本即可,例如:

#!/bin/bash
filename=`find /data/template/ -name *.ova`
# find all ova template
for ova in $filename
do
/usr/bin/ovftool --X:logLevel=verbose --X:logFile=/root/ovflog-`date +%Y%m%d`  --noSSLVerify --acceptAllEulas -dm=thin -vf=Templates -ds=POD1-Template `echo $ova` 'vi://username:password*@MyVC/POD1(MyDC)/host/CLU01/pod1-clu01-h001.jx.local'
continue
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值