下面,就是我们在线上所使用的脚本,只需要你本地安装有一个VNC客户端就可以了。
获取本地VM列表
./getvnc
1
Usage: ./getvnc vm_name
2
VMs found:
3
idc2-server1
4
idc2-server2
获取指定VM的VNC端口号
./getvnc idc2-server2
1
run this on laptop and connect via vnc to localhost:5903
2
–> ssh -L 5903:localhost:5903 root@10.100.1.30
接下来,直接在本地运行”ssh -L 5903:localhost:5903 root@10.100.1.30”;
再通过VNC客户端连接”localhost:5903”就可以了。
脚本代码:
view sourceprint?
01
!/bin/bash
02
03
vm=
104if[−z
{vm} ]; then
05
echo “Usage: 0 vm_name”
06
echo “VMs found:”
07
xl list-vm | awk ‘{print3}’ | grep -vw name
08
exit 1
09
fi
10
11
xe vm-list params=name-label name-label=
vm|grep
{vm} > /dev/null
12
if [ $? -gt 0 ]; then
13
echo “Error: invalid VM name”
14
exit 1
15
fi
16
17
host=
(xevm−listparams=resident−onname−label=
{vm} | grep resident-on | awk ‘{print NF}’)
18
dom=(xe vm-list params=dom-id name-label=
vm|grepdom−id|awk‘print$NF′)19port=
(xenstore-read /local/domain/
dom/console/vnc−port)20ip=
(xe pif-list management=true params=IP host-uuid={host} | awk ‘{printNF}’)
21
22
echo “run this on laptop and connect via vnc to localhost:
port”23echo“–>ssh−L
{port}:localhost:
portroot@
{ip}”