当前位置: 首页 > article >正文

腾讯云CloudStudio使用笔记(三)

0、感谢

感谢“Cloud Studio 核心体验官”群里面各位大佬的指点和讨论
感谢deepseek带来的福利,感谢腾讯云的资源和福利o( ̄▽ ̄)ブ

1、背景及目标

当前方案(xCloudStudio)用于解决以下2个问题
1、CloudStudio默认提供的环境为VSCODE,适合前端开发,对于后端开发来说目前并未提供idea
2、CloudStuido无桌面环境

2、可行性分析

1、CloudStudio是基于ubuntu 20.04的并且放开了一部分端口
2、OpenStack有基于浏览器访问虚拟机的方式
结论:可行

3、逻辑视图

如下图所示xCloudStudio以腾讯提供的CloudStudio作为底座,基于CloudStudio所在的Ubuntu 20.04操作系统上进行软件安装,而CloudStudio是基于Docker的,截止目前CloudStudio的GPU版本并未提供Docker in Docker的支持,所以对后续的部署过程会有约束。
在这里插入图片描述

3.1 screen

用于后台运行及切换回原理的控制台(Linux的Terminal)进行查看

3.2 xrdp

提供Linux的远程桌面是rdp协议在Linux环境的一个实现

3.3 xfce

Linux环境下的一个轻量级桌面环境

3.4 noVNC

https://github.com/novnc/noVNC
提供一个基于浏览器访问vnc的环境

3.5 TurboVNC

https://www.turbovnc.org/
https://github.com/TurboVNC/turbovnc.git
VNC的一个实现

4、软件安装

说明:以下命令操作均以root用户进行(CloudStudio默认已开启了root用户登录就是root用户)

4.1 screen

apt install screen

使用时screen -S xCloudStudio即可开启一个新的session,在这个新的seseion里面操作完直接关闭浏览器并不会导致当前的控制台中断
使用screen -ls可以查看运行中的screen的session
使用screen -R xCloudStudio可以恢复前面创建的session

4.2 桌面环境的安装

apt update
apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils
apt install xrdp

编辑启动文件vi /etc/xrdp/xrdp.ini在文件末尾输入exec start xfce4,对xrdp.ini保存(如果vi不会操作可以留言)后使用service xrdp restart重启xrdp服务

中文乱码解决:如果有中文乱码将windows系统c:/windows/fonts下的宋体或者任何字体(请不要复制有版权的字体)以root用户复制到linux系统的/usr/share/fonts目录然后重启linux系统即可

4.3 VNC安装

wget -q -O- https://packagecloud.io/dcommander/turbovnc/gpgkey |   gpg --dearmor >/etc/apt/trusted.gpg.d/TurboVNC.gpg
wget https://raw.githubusercontent.com/TurboVNC/repo/main/TurboVNC.list
mv TurboVNC.list /etc/apt/sources.list.d/
apt update && apt install turbovnc -y

安装完之后加一下软链

ln -s /opt/TurboVNC/bin/vncserver /usr/bin/vncserver
ln -s /opt/TurboVNC/bin/Xvnc /usr/bin/Xvnc
ln -s /opt/TurboVNC/bin/vncconnect /usr/bin/vncconnect
ln -s /opt/TurboVNC/bin/vncpasswd /usr/bin/vncpasswd
ln -s /opt/TurboVNC/bin/vncviewer /usr/bin/vncviewer
ln -s /opt/TurboVNC/bin/webserver /usr/bin/webserver
cp /opt/TurboVNC/bin/xstartup.turbovnc /usr/bin/

4.4 noVNC安装及运行
官方资料
在这里插入图片描述
具体操作

# 下载
wget https://codeload.github.com/novnc/noVNC/tar.gz/refs/tags/v1.5.0 -O noVNC-1.5.0.tar.gz
# 解压
tar -zxvf noVNC-1.5.0.tar.gz -C /root/
# 进入目录
cd /root/noVNC-1.5.0
# 生成密钥
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
# 运行(暂时不需要立刻运行,如果运行了直接ctrl+C即可)
./utils/novnc_proxy --vnc localhost:5901 --listen 0.0.0.0:10001 --cert self.pem --key self.pem --file-only

5、用户创建

创建xx用户(后续vnc登录时使用的用户,不建议使用root,会有安全风险以及浏览器访问异常错误)

adduser xx

创建java用户(仅仅用于安装java,如果不使用idea运行java环境可以不用创建)

adduser java

6、配置

6.1 文件1配置

# 进入目录
cd /usr/share/xsessions
# 备份
cp ubuntu.desktop /root/
# 替换
cp xfce.desktop ubuntu.desktop

6.2 文件2配置

cd /root/.vnc
vi xstartup

确保xstartup文件和下图一致
在这里插入图片描述

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
xfdesktop &
xfce4-panel &
xfce4-menu-plugin &
xfsettingsd &
xfconfd &
xfwm4 &

6.3 文件3配置

使用vi /etc/hosts编辑/etc/hosts文件
在这里插入图片描述
将上图复制的对下图照着修改
在这里插入图片描述
使用cp /etc/hosts /workspace/备份到/workspace目录供下次使用,因为目前的CloudStudio每次启动后这个文件会被恢复

7、启动vnc

第7章节需要用xx用户执行,xx用户的创建在第5章节有可以回去看看
在这里插入图片描述

export  export USER=xx
# 注意如果第一次运行会让输入2个密码,需要保存,后面第8.2章节会用到
vncserver -geometry 1920x1080
# 确保启动成功
vncserver -list
netstat -ano |grep 5901

如下图所示如果netstat -ano |grep 5901执行完毕后有则说明是启动成功了,如果没有则使用vncserver -list查看是否启动了多个,如果启动了多个,使用vncserver -kill :1将第一个进程kill掉即可,如果有多个可以都kill掉
在这里插入图片描述

8、noVNC启动及访问

8.1 命令执行

# 第二次导出环境变量(后续可能不需要,为了稳妥起见先执行下)
export  export USER=xx
screen -S xCloudStudio
# 第三次导出环境变量(后续可能不需要,为了稳妥起见先执行下)
export  export USER=xx
cd /root/noVNC-1.5.0/
./utils/novnc_proxy --vnc localhost:5901 --listen 0.0.0.0:10001 --cert self.pem --key self.pem --file-only

8.2 浏览器访问

参考下面的链接进行访问
https://xxxx–10001.ap-guangzhou.cloudstudio.work/vnc.html?host=xxxx–10001.ap-guangzhou.cloudstudio.work
在这里插入图片描述
点击链接,输入第7章节设置的密码即可进入
最终界面

9、重新开机后到浏览器的访问流程

# 1
cp /workspace/hosts /etc/
export  export USER=xx
# 2
su - xx
export  export USER=xx
vncserver -kill :1
vncserver -geometry 1920x1080
exit
# 3
export  export USER=xx
screen -S xCloudStudio
export  export USER=xx
cd /root/noVNC-1.5.0/
./utils/novnc_proxy --vnc localhost:5901 --listen 0.0.0.0:10001 --cert self.pem --key self.pem --file-only

然后在浏览器访问即可

10、扩展增强特性

10.1 自定义域名

已验证可以支持,具体参考https://blog.csdn.net/hanmingjun/article/details/145791011即可
假定你的域名是ide.xxx.com则浏览器输入的是http://ide.xxx.com/vnc.html?host=ide.xxx.com

10.2 xfce看着模糊的解决

解决参考这个https://www.zhihu.com/question/384367815
点击左上角图标,打开Settings -> Settings manager -> Appearance -> Fonts
启用DPI -> Custom DPI setting,并调节到一个合适的值,如下所示
在这里插入图片描述

10.3 idea的安装

到官网下载linux版本,然后运行即可

11、常见问题

列表定期更新,有问题可以留言,祝开心

11.1 启动vncserver时报错xauth: (argv):1: bad display name “VM-0-80-ubuntu:1” in “add” command

请确保/etc/hosts文件使用的是修改过的,特别是重启CloudStudio后

11.2 在浏览器输入地址后访问可以出现界面点击连接输入密码后是黑屏

请确保6.2章节和6.1章节正确,如果正确按照第9章节再走一边(可以先重启下CloudStudio)


http://www.kler.cn/a/588615.html

相关文章:

  • 如何减少跨团队交付摩擦?——基于 DevOps 与敏捷的最佳实践
  • 如何用AI制作PPT,轻松生成高效演示文稿
  • 软件架构设计、详细设计和开发编码的过程中提高性能的技巧和方法
  • REDIS生产环境配置
  • Git使用和原理(3)
  • Git的基本指令
  • C# WPF 基础知识学习(三)
  • Leetcode-1278.Palindrome Partitioning III [C++][Java]
  • 使用 Flask 进行简单服务器改造的详细步骤和代码
  • 在 React 中使用 Web Components 的实践操作
  • Blender-MCP服务源码1-项目解读
  • Linux find 命令完全指南
  • 接口测试中常见的bug有哪些?
  • 使用elementplus的table表格遇到的问题
  • ubuntu ollama+dify实践
  • 关于修改 Ollama 及其模型默认路径、迁移已安装的 Ollama 程序和模型以及重启 Ollama 的操作指南
  • 计算机视觉——深入理解卷积神经网络与使用卷积神经网络创建图像分类算法
  • 在线 SQL 转 Flask-SQLAlchemy
  • 高版本node(17+)环境下VUE2项目启动报错
  • Android 7 及以上夜神模拟器,Fiddler 抓 https 包