环境:centos 7
宿主机地址:10.6.31.60
虚拟机端口 :5900、5901
-
下载novnc
yum istall -y git
git clone https://github.com/novnc/noVNC.git
-
启动novnc(首次使用会选择Websokify)
cd noVNC
$ ./utils/launch.sh --vnc localhost:5900
浏览器访问http://localhost:6080/vnc.html 或者http://localhost:6080/vnc_lite.html (IP根据实际情况作更改),二者区别如下
- vnc.html 完整界面,有操作按钮
- vnc_lite.html 精简界面,只有虚拟机内容
这样我们便可以在浏览器中直接操作5900的虚拟机,如果需要操作多台虚拟机,我们可以用token 进行配置。
-
单独下载websockify
git clone https://github.com/novnc/websockify.git
-
配置token
token文件格式(注意空格位置)
token1: host1:port1
token 文件可以为一个文件,也可以为多个,这里为一个token文件情况。(token文件只要在指定目录即可,也可以没有后缀名,都能够正常识别)
cd websockify
mkdir token
vi ./token/token01.conf
输入内容如下
vm01: 10.6.31.60:5900
vm02: 10.6.31.60:5901
-
启动websockify
启动前先重启之前的novnc(指定端口8888)
./launch.sh --listen 8888
然后启动websockify
./run --token-plugin TokenFile --token-source ./token/ 6080
在浏览器输入http://localhost:8888/vnc_lite.html?host=10.6.31.60&port=6080&path=websockify/?token=vm01就可以访问虚拟机了
其中host 为websockify所在的服务器ip,port为其端口,path为访问路径,token 为我们刚才配置的token