[书生实战营] 入门岛1: Linux基础
一、闯关任务
完成SSH连接与端口映射并运行hello_world.py
1.创建开发机器
进入InternStudio的首页,并创建开发机
可以在这个界面设置开发机名称、镜像类型以及资源配置
选择进入开发机并进行配置
能够进入该界面后,说明配置成功
2.配置SSH远程连接
选择SSH连接后,可以获得登录命令和密码
在本地终端中输入登录命令和密码即可登录,其中密码不会显示
3.配置免密SSH登录
在本地终端中,使用RSA算法生成密钥:
ssh-keygen -t rsa
输入命令后直接回车,密钥会生成在 C:\Users\{your_username}\.ssh\id_rsa.pub
文件中
回到InternStudio的首页 ,并选择配置SSH
将之前生成的id_rsa.pub
的内容复制到公钥部分
完成后就可以不输入密码直接登录了
4.配置vscode远程连接
安装remote ssh插件
安装完成后使用之前的ssh命令进行连接
ssh -p 38218 root@ssh.intern-ai.org.cn -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
之后可以进入本地的vscode界面,之后可以使用本地的vscode进行代码开发
5.执行hello_word.py
在目录下创建hello_word.py
文件
import socket
import re
import gradio as gr
# 获取主机名
def get_hostname():
hostname = socket.gethostname()
match = re.search(r'-(\d+)$', hostname)
name = match.group(1)
return name
# 创建 Gradio 界面
with gr.Blocks(gr.themes.Soft()) as demo:
html_code = f"""
<p align="center">
<a href="https://intern-ai.org.cn/home">
<img src="https://intern-ai.org.cn/assets/headerLogo-4ea34f23.svg" alt="Logo" width="20%" style="border-radius: 5px;">
</a>
</p>
<h1 style="text-align: center;">☁️ Welcome {get_hostname()} user, welcome to the ShuSheng LLM Practical Camp Course!</h1>
<h2 style="text-align: center;">😀 Let’s go on a journey through ShuSheng Island together.</h2>
<p align="center">
<a href="https://github.com/InternLM/Tutorial/blob/camp3">
<img src="https://oss.lingkongstudy.com.cn/blog/202406301604074.jpg" alt="Logo" width="20%" style="border-radius: 5px;">
</a>
</p>
"""
gr.Markdown(html_code)
demo.launch()
在运行代码之前,需要先使用pip install gradio==4.29.0
在终端中执行python3 hello_world.py
后可以开启服务
6.端口转发
运行上述vscode中会自动启动端口转发
在浏览器输入127.0.0.1:7860
,结果如下