当前位置:   article > 正文

go+react实现远程vCenter虚拟机管理终端

go+react实现远程vCenter虚拟机管理终端

React-Vcenter

基于go & react实现远程vSphere vcenter虚拟机终端console页面,提供与vcenter管理中的Launch Web Console相同的功能。

项目地址:react-vcenter

Demo

URL: http://localhost:3000

请添加图片描述
请添加图片描述

请添加图片描述

Quick Start

  1. 配置前端访问后端的代理

frontend/package.json

  "proxy": "http://localhost:8888" // The backend addr
  • 1

frontend/src/setupProxy.ts

export const { createProxyMiddleware } = require('http-proxy-middleware')

module.exports= function (app:any) {
    app.use(
        createProxyMiddleware(
            "/api",
            {
                target: "http://localhost:8888", // The backend addr
                changeOrigin: true,
                ws: true,
                pathRewrite:{
                    "^/api":"",
                },
            }
        )
    )
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  1. 配置websocket地址

frontend/src/components/Console/index.tsx, domain_name requires a value for nginx server_name

const consoleUrl = 'wss://<domain_name>/ticket/' + ticket + '?ip=' + host
  • 1
  1. 配置vCenter宿主机的nginx代理,所有访问虚拟机console页面的请求均由nginx来代理转发到指定的vCenter宿主机上
server {
    listen 80;
    server_name vc.rsq.cn;
    return 301 https://$http_host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name          vc.rsq.cn;
    ssl_certificate      nginx_conf/certs/rsq.cn.pem;
    ssl_certificate_key  nginx_conf/certs/rsq.cn.key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers off;
    ssl_protocols TLSv1.1 TLSv1.2;

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' '*';
    add_header 'Access-Control-Allow-Headers' '*';

    access_log  /var/log/openresty/vc.access.log main;
    error_log   /var/log/openresty/vc.error.log warn;

    location / {
        proxy_pass https://$arg_ip;
        proxy_http_version                 1.1;
        proxy_cache_bypass                 $http_upgrade;

        # Proxy headers
        proxy_set_header Upgrade           $http_upgrade;
        proxy_set_header Connection        $connection_upgrade;
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header Forwarded         $proxy_add_forwarded;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;

        # Proxy timeouts
        proxy_connect_timeout              60s;
        proxy_send_timeout                 120s;
        proxy_read_timeout                 120s;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  1. 配置vCenter sdk的账号密码和URL地址信息

backend/pkg/client.go

vcenterURL   = flag.String("vcurl", "https://<user>:<pass>@vcenter.rsq.cn/sdk", "URL of vCenter Server instance")
  • 1
  1. 开启前后端服务
# start frontend
cd frontend
npm i
npm run start

# start backend
cd backend
go mod tidy
go run main.go
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/486117
推荐阅读
相关标签
  

闽ICP备14008679号