Vue中使用novnc来构建虚拟化桌面

安装novncyarn add @novnc/novncnpm i @novnc/novnc 具体用法可以参阅官方文档https://github.com/novnc/noVN... 在vue里面使用template<template> <div id="screen"> //虚拟化桌面将已canvas的形式被渲染到这里 </div></template>scriptimport RFB from '@novnc/novnc/core/rfb';export default { name: 'novnc', data () { rfb:null, url: undefined, //链接的url IsClean: false, //是否已断开并不可重新连接 connectNum:0 //重连次数 }, methods: { // vnc连接断开的回调函数 disconnectedFromServer (msg) { if(msg.detail.clean){ // 根据 断开信息的msg.detail.clean 来判断是否可以重新连接 this.contentVnc() } else { //这里做不可重新连接的一些操作 } }, // 连接成功的回调函数 connectedToServer() { console.log('success') }, //连接vnc的函数 connectVnc () { const PASSWORD = ''; let rfb = new RFB(document.getElementById('screen'), this.url, { // 向vnc 传递的一些参数,比如说虚拟机的开机密码等 credentials: {password: password} }); rfb.addEventListener('connect', this.connectedToServer); rfb.addEventListener('disconnect', this.disconnectedFromServer); rfb.scaleViewport = true; //scaleViewport指示是否应在本地扩展远程会话以使其适合其容器。禁用时,如果远程会话小于其容器,则它将居中,或者根据clipViewport它是否更大来处理。默认情况下禁用。 rfb.resizeSession = true; //是一个boolean指示是否每当容器改变尺寸应被发送到调整远程会话的请求。默认情况下禁用 this.rfb = rfb; } }, 在mounted周期里面连接vnc mounted () { //这时已经可以获取到dom元素 this.connectVnc() } }

October 15, 2019 · 1 min · jiezi

CentOS-7安装GUI界面及远程连接

转载请注明文章出处:https://tlanyan.me/install-gu... 用基于浏览器(webdriver)的selenium技术爬取数据,所以程序需运行在GUI环境下。本文分三个部分简要介绍安装GUI界面及远程连接的步骤。 安装GUI界面大多数云服务器厂商提供的镜像都无GUI界面,所以要先安装图形环境。本文使用GNOME桌面环境: yum -y groups install "GNOME Desktop" 这条命令将安装GNOME桌面的必要软件包,执行完后配置X系统使用GNOME: echo "exec gnome-session" >> ~/.xinitrc 安装KDE或者MATE桌面环境的两个命令稍微不一样: <pre class="sh"># kdeyum -y groups install "KDE Plasma Workspaces"echo "exec startkde" >> ~/.xinitrc mateyum --enablerepo=epel -y groups install "MATE Desktop"echo "exec /usr/bin/mate-session" >> ~/.xinitrc</pre> 以上便安装好了GUI桌面环境。 启动桌面环境有两种方式: 一次性的:在终端里输入startx;系统启动时默认进入桌面环境: systemctl set-default graphical.target,然后重启;安装vnc-server有了桌面环境,一般可以通过云服务器厂商提供的web终端远程连接进入桌面。用web终端每次都需要打开浏览器,然后登陆云管理后台再连接,比较麻烦。我们采取直接从桌面客户端远程连接的方式,省去打开浏览器和登录云管理后台的操作。 远程桌面技术有多种,例如VNC, TeamViewer, RDP等,本文使用免费且广泛使用的VNC。 在服务器上先安装服务端(tigervnc是tightvnc的分支): yum install -y tigervnc-server 接着复制一份VNC配置: cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service 注意上述命令参数重的“@:1”,可以将数字1换成30000内的任意数字,“5900+数字”即为程序的显示(监听)端口,如"@:1"表示监听5901端口。 编辑该配置文件,将文件内的<USER>替换成远程连接时的登录用户名(如果是root,注意将第二个<USER>所在行的"/home"移除掉)。以root身份的配置示例: # The vncserver service unit file## Quick HowTo:# 1. Copy this file to /etc/systemd/system/vncserver@.service# 2. Replace <USER> with the actual user name and edit vncserver# parameters appropriately# (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"# PIDFile=/home/<USER>/.vnc/%H%i.pid)# 3. Run `systemctl daemon-reload`# 4. Run `systemctl enable vncserver@:<display>.service`## DO NOT RUN THIS SERVICE if your local area network is# untrusted! For a secure way of using VNC, you should# limit connections to the local host and then tunnel from# the machine you want to view VNC on (host A) to the machine# whose VNC output you want to view (host B)## [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB## this will open a connection on port 590N of your hostA to hostB's port 590M# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).# See the ssh man page for details on port forwarding)## You can then point a VNC client on hostA at vncdisplay N of localhost and with# the help of ssh, you end up seeing what hostB makes available on port 590M## Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.## Use "-localhost" to prevent remote VNC clients connecting except when# doing so through a secure tunnel. See the "-via" option in the# `man vncviewer' manual page.[Unit]Description=Remote desktop service (VNC)After=syslog.target network.target[Service]Type=forking# Clean any existing files in /tmp/.X11-unix environmentExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"PIDFile=/root/.vnc/%H%i.pidExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'[Install]WantedBy=multi-user.target接下来设置vnc连接密码: ...

June 23, 2019 · 2 min · jiezi