本地制作虚拟机模板上传到Azure China(1)
本地服务器虚拟化,现在已经非常普遍,那么企业中也必然有许多虚拟机模板文件,希望可以利用这些文件上传到Microsoft Azure,转化为映像文件并基于此部署企业需要的环境。在微软的Microsoft Azure平台中,允许用户在本地制作装有操作系统的VHD,然后将该VHD文件上传到到云端存储中。
不过需要注意的是,Azure仅支持采用VHD文件格式且磁盘大小固定的第1代虚拟机。VHD允许的最大大小为1023GB,操作系统磁盘最大127GB。可将第1代虚拟机从VHDX转换成VHD文件格式,并从动态扩展转换成固定大小磁盘。但无法更改虚拟机的代次。该VHD文件不能被压缩或者其他第三方工具处理过,操作系统必须是Azure平台所支持的系统,例如Windows Server 2012 R2,CentOS6.8等。
将虚拟磁盘转换为 VHD 和固定大小磁盘
首选在Hyper-V平台中创建虚拟机所需的虚拟磁盘(VHD)
选择磁盘格式页面,选择”VHD”
如果您已经有一个基于VHDX格式的虚拟机,需要使用下面方式对其进行转化
或者使用PwerShell
Convert-VHD -Path c:\test\MY-VM.vhdx -DestinationPath c:\test\MY-NEW-VM.vhd -VHDType Fixed
在”新建虚拟硬盘向导-选择磁盘类型” 页面,选择VHD磁盘类型,由于微软Microsoft Azure平台的限制,目前只能选择”固定大小”
制定名称和位置页面,键入一个形象化的名称
配置磁盘页面,设置虚拟机磁盘大小,设置OS盘为127GB
因为是实验环境,我这里选择30G
基于以上创建的VHD文件,新建虚拟机,虚拟机代数选择一代
关于一代和二代虚拟机的区别,可以参考我之前写的
http://ericxuting.blog.51cto.com/8995534/1586431
到了这里,基本的虚拟机环境准备好了,下面所要操作的是Azure平台针对映像文件的一些编辑。
设置 Azure 的 Windows 配置
使用”netsh winhttp reset proxy “删除删除WinHTTP代理
使用以下命令将磁盘SAN策略设置为 Onlineall。
diskpart
san policy=onlineall
exit
将Windows设置为协调世界时(UTC)时间,并将Windows时间 (w32time)服务的启动类型设置为”自动”
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation /v RealTimeIsUniversal /t REG_DWORD /d 1
sc config w32time start= auto
设置Windows服务
确保下面的每个Windows服务均设置为Windows默认值。若要重置启动设置,请运行以下命令
sc config bfe start= auto
sc config dcomlaunch start= auto
sc config dhcp start= auto
sc config dnscache start= auto
sc config IKEEXT start= auto
sc config iphlpsvc start= auto
sc config PolicyAgent start= demand
sc config LSM start= auto
sc config netlogon start= demand
sc config netman start= demand
sc config NcaSvc start= demand
sc config netprofm start= demand
sc config NlaSvc start= auto
sc config nsi start= auto
sc config RpcSs start= auto
sc config RpcEptMapper start= auto
sc config termService start= demand
sc config MpsSvc start= auto
sc config WinHttpAutoProxySvc start= demand
sc config LanmanWorkstation start= auto
sc config RemoteRegistry start= auto
更新远程桌面注册表设置
启用远程桌面协议(RDP)
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server’ -name “fDenyTSConnections” -Value 0 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services’ -name “fDenyTSConnections” -Value 0 -Type DWord
设置RDP端口号
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp’ -name “PortNumber” 3389 -Type DWord
配置用于 RDP 连接的”网络级别身份验证”模式
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp’ -name “UserAuthentication” 1 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp’ -name “SecurityLayer” 1 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp’ -name “fAllowSecProtocolNegotiation” 1 -Type DWord
设置 keep-alive 值
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services’ -name “KeepAliveEnable” 1 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services’ -name “KeepAliveInterval” 1 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp’ -name “KeepAliveTimeout” 1 -Type DWord
配置 Windows 防火墙规则
#在三个配置文件(”域”、”标准”和”公共”)上启用 Windows 防火墙
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\services\SharedAccess\Parameters\FirewallPolicy\DomainProfile’ -name “EnableFirewall” -Value 1 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\services\SharedAccess\Parameters\FirewallPolicy\PublicProfile’ -name “EnableFirewall” -Value 1 -Type DWord
Set-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\services\SharedAccess\Parameters\FirewallPolicy\Standardprofile’ -name “EnableFirewall” -Value 1 -Type DWord
#在 PowerShell 中运行以下命令,允许 WinRM 通过三个防火墙配置文件(”域”、”专用”和”公共”)并启用 PowerShell 远程服务
Enable-PSRemoting -force
netsh advfirewall firewall set rule dir=in name=”Windows Remote Management (HTTP-In)” new enable=yes
netsh advfirewall firewall set rule dir=in name=”Windows Remote Management (HTTP-In)” new enable=yes
#启用以下防火墙规则,允许 RDP 流量
netsh advfirewall firewall set rule group=”Remote Desktop” new enable=yes
#启用”文件和打印机共享”规则,使 VM 能够在虚拟网络中响应 ping 命令
netsh advfirewall firewall set rule dir=in name=”File and Printer Sharing (Echo Request – ICMPv4-In)” new enable=yes
系统补丁更新
开启系统补丁自动更新设置
以上,我们已经做好基本前期准备工作,接下来将要开始
- 安装Microsoft Azure VM Agent
- 封装VHD文件
- 准备Azure环境、上传VHD以及基于此VHD新建VM
文中所涉及的脚本:
本文固定链接: http://365vcloud.net/2017/12/05/local-vhd-file-uploaded-to-azure-china/ | 365vCloud的云计算之旅