my blog my blog

Monthly 12月 2019
Nginx配置noVNC的web页面教程

先说下noVNC的一键启动

./utils/launch.sh --listen localhost:6002--vnc localhost:6001

listen是监听本地端口,如果开放就不要用localhost而用0.0.0.0就好了 。vnc后面是vnc server的端口。

这个noVNC的启动项目没法直接用Nginx反代,因为涉及到websocket。官方的教程是这样做的

在nginx.conf的http字段中添加
upstream vnc_proxy {
    server 127.0.0.1:6080;
}
在nginx.conf的server字段中添加
location /websockify {
          proxy_http_version 1.1;
          proxy_pass http://vnc_proxy/;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";

          # VNC connection timeout
          proxy_read_timeout 61s;

          # Disable cache
          proxy_buffering off;
    }
location /vnc {
            index vnc.html;
            alias /home/nenew/noVNC/;
            try_files $uri $uri/ /vnc.html;
    }

其实很好理解,就是通过建立nginx和upstream的连接,然后把vnc的传输通过websocket完成。

这里nginx配置就算完成了,我们还需要一个websocket

./utils/websockify/run source_port target_addr:target_port

其中的源端口和目标地址:端口就正常填写即可,这里需要说的是目标端口和一键启动的端口没有关系,就是vnc的服务端口,websockify和launch俩程序没啥关系。

然后直接通过网站http://www.nenew.net/vnc访问即可。

Ubuntu Server安装KVM NAT虚拟机

安装kvm和libvert套装

apt install qemu qemu-kvm libvirt-bin  bridge-utils  virt-manager

下载好安装镜像并查看NAT网络

virsh net-list
查看会有一个default网络
ifconfig
会有一个私网的bridge网桥

开启IPV4转发

vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl –p

安装KVM虚拟机

virt-install --name kvm --memory 4096 --vcpus=2 --boot hd,cdrom,menu=on --cdrom /home/nenew/ubuntu-18.04.3-desktop-amd64.iso --cdrom /home/nenew/virtio-win.iso --disk path=/home/nenew/kvm.img,format=qcow2,bus=virtio --network network=default --graphics vnc,listen=0.0.0.0,port=6001

这样配置一个可以在6001端口监听的VNC server,用VNC连接server并进行安装。

启动虚拟机

virsh list --all
查看所有虚拟机
virsh start kvm
启动虚拟机(安装完成后虚拟机可能关机)

奶牛现在码字感觉很费力,懒得多写了。