验证使用VMware HTML Console SDK--Nginx集成Vcenter 6.X HTML Console系列之 2--(共4)

官方下载VMware HTML Console SDKVMware HTML Console SDK Programming Guide 2.10,当然大家也可以使用从这里下载OpenH5Console

打开里面的示例代码console.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  <title>Console</title> 
 </head> 
 <body> 
  <link rel="stylesheet" type="text/css" href="wmks-all.css" /> 
  <script type="text/javascript" src="jquery.js"></script> 
  <script type="text/javascript" src="jquery-ui.min.js"></script> 
  <script type="text/javascript" src="wmks.min.js"></script> 
  <div id="wmksContainer" style="position:absolute;width:100%;height:100%"></div> 
  <script> var wmks = WMKS.createWMKS("wmksContainer",{}) .register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE, function(event,data){ if(data.state == WMKS.CONST.ConnectionState.CONNECTED) { console.log("connection state change : connected"); } });wmks.connect("wss://10.200.108.91:443/ticket/368c0616102e1c58"); 
</script>  
 </body>
</html>

1、连接VM时使用的是vmks.connect(url)方法

该url的格式为:

<ws|wss>://<host:port>/<path>/<?authentication info>

ws是websocket的简称,WSS是 Web Socket Secure 的简称, 它是 WebSocket 的加密版本,SSL 是基础, 在 SSL 上运行 WebSocket 协议就是 WSS; 在 SSL 上运行 HTTP 协议就是 HTTPS,具体参考WSS、SSL 和 https 之间的关系

2、获取Ticket

很多人在这里卡住了,不是因为没有获取到ticket,而是因为获取的ticket类型不对。目前知道vcenter有三种类型的ticket(6.X),包括mksTicket、webmks Ticket、CloneSession Ticket。t经过验证,只能使用webmks Ticket,获取方法有很多种,我说两种

2.1 通过vcenter网页获取:

依次是:
浏览 vSphere 管理的对象--content--rootFolder--childEntity--datastore--vm

2.2 通过VMware PowerCLI获取:

需要下载安装VMware PowerCLI,然后依次执行如下命令

$VCenter = "vc的FQDN"
Connect-VIServer $VCenter -User [email protected] -Password  vc密码
$Vm = Get-VM VM名字
$Ticket = $Vm.ExtensionData.AcquireTicket("webmks")
$ESXHost = $Ticket.host
$TicketNumber = $Ticket.ticket

执行完成之后,再次输入$TicketNumber,就是需要的认证信息了。

将以上获取的ticket信息,放入console.html,然后双击就能打开控制台了。

3、有几个问题需要注意:

3.1 如果使用的wss的话,因为证书未安装,网页可能会没有反应。

这是因为需要信任证书,可以直接在浏览器输入https://<host:port>,然后添加信任例外就能解决。或者先安装对应的证书,再重新生成ticket进行连接

3.2 修改ESXi配置,使其支持ws方式,这样就没有证书验证的问题了

默认ESXi支持ws方式,但80端口给重定向到443端口了,所以需要把重定向去掉,具体步骤是:

1 Log in to the ESXi Shell as a user with administrator privileges.
2 Change to the /etc/vmware/rhttpproxy/endpoints/conf directory.
3 Use a text editor to open the endpoints.conf file.
4 Change the security settings as required

allow - Allow HTTP access.
redirect – If the Endpoint address is a local port, then the client is redirected to 443. If the Endpoint address is a remote host, then the client is redirected to that host.
reject - No HTTP access
只需要修改type为ticket的即可,改为allow,具体参考vsphere-esxi-vcenter-server-55-security-guide

然后重启rhttpproxy服务:

/etc/init.d/rhttpproxy restart

3.3 其实解决证书问题还可以通过Nginx

将https数据,输出为http的,

将https数据,输出为https的,然后为Nginx颁发信任证书,或添加信任

这个待第3篇里说。

参考:

Showing Web Console of a VM via vSphere HTML Console SDK - Samples

WebMKS SDK 2.0 non-minified wmks.js

vcenter 6.x 生成预验证的 html5 vm console链接

猜你喜欢

转载自www.cnblogs.com/lizhaoxian/p/10425869.html