【入门岛·第1关】linux 基础知识

三法师 / 2024-09-25 / 原文

目录
  • 闯关任务 完成SSH连接与端口映射并运行hello_world.py

闯关任务 完成SSH连接与端口映射并运行hello_world.py

1 在远程主机上建立hello_python.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()

image
可知程序运行的端口是7860
2 设置ssh远程连接

ssh -p 42412 root@ssh.intern-ai.org.cn -CNg -L {本地机器_PORT}:127.0.0.1:{开发机_PORT} -o StrictHostKeyChecking=no
42412是远程主机开放的ssh端口。当在个人PC上执行这个SSH命令后,SSH客户端会在本地机器的7860端口上监听。任何发送到本地7860端口的流量,都会被SSH隧道转发到远程服务器的127.0.0.1地址上的7860端口。
ssh -p 42412 root@ssh.intern-ai.org.cn -CNg -L 7860:127.0.0.1:7860 -o StrictHostKeyChecking=no

  1. 访问结果
    image

可选任务 1 将Linux基础命令在开发机上完成一遍
可选任务 2 使用 VSCODE 远程连接开发机并创建一个conda环境
可选任务 3 创建并运行test.sh文件