标签为 XenCenter 的文章

通过非XenCenter方式连接到XenServer各个VM的VNC本地界面

下面,就是我们在线上所使用的脚本,只需要你本地安装有一个VNC客户端就可以了。

获取本地VM列表
# ./getvnc

 
Usage: ./getvnc vm_name
VMs found:
idc2-server1                     
idc2-server2

获取指定VM的VNC端口号
# ./getvnc idc2-server2

 
run this on laptop and connect via vnc to localhost:5903 
--> ssh -L 5903:localhost:5903 root@10.100.1.30

接下来,直接在本地运行"ssh -L 5903:localhost:5903 root@10.100.1.30";
再通过VNC客户端连接"localhost:5903"就可以了。

脚本代码:

 
#!/bin/bash

vm=$1
if [ -z ${vm} ]; then
  echo "Usage: $0 vm_name"
  echo "VMs found:"
  xl list-vm | awk '{print $3}' | grep -vw name
  exit 1
fi

xe vm-list params=name-label name-label=${vm} | grep ${vm} > /dev/null
if [ $? -gt 0 ]; then
  echo "Error: invalid VM name"
  exit 1
fi

host=$(xe vm-list params=resident-on name-label=${vm} | grep resident-on | awk '{print $NF}')
dom=$(xe vm-list params=dom-id name-label=${vm} | grep dom-id | awk '{print $NF}')
port=$(xenstore-read /local/domain/${dom}/console/vnc-port)
ip=$(xe pif-list management=true params=IP host-uuid=${host} | awk '{print $NF}')

echo "run this on laptop and connect via vnc to localhost:${port}"
echo "--> ssh -L ${port}:localhost:${port} root@${ip}"

, ,

No Comments