Jimmy Chu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: substrate-中文 --- # 如何国外开服并远端编译 Rust 项目 请对照相关视频一起看: - [bilibili hosting](https://www.bilibili.com/video/BV1MT4y1K7b4/) - [screencast-o-matic hosting](https://screencast-o-matic.com/watch/crVl1LPEN0) --- 会用到以下服务: - [Digital Ocean](https://www.digitalocean.com/)(DO) 来开服 - [安装 Rust](https://www.rust-lang.org/tools/install) 页 - [Cargo remote](https://github.com/sgeisler/cargo-remote) 项目 - [sccache](https://github.com/mozilla/sccache)(rust 编译包缓存) 项目 ## DO 开服: - 前题,小伙伴们有信用卡可让云服公司扣费。 - 建议开在新加坡,离中国大陆最近。也不需 fq。如果在国内开服,那请把 js npm 及 rust crate 镜像源设回国内,以后下载依赖包会快很多。參考: - [npm 镜源设回国内](https://zhuanlan.zhihu.com/p/35856841) - [rust 镜源设回国内](https://rustcc.com/article?id=6baecc6f-29ed-40d2-870b-343606aa2e93) - 用 Ubuntu v20.04 LTS 或 Ubuntu v18.04 LTS 的 (除非你个人对 Redhat 系操作系统情有独钟)。 - 长期使用的话,因为是用作编译用,对 CPU 需求大,建议開個最少 4 vCPUs 的 (一般跟 8GB 内存)。 - 小伙伴们第一次用 DO 开服,可能没得在云服设 ssh key, 所以选用密码登入 (password), 接着看以下步骤。 ## 云服安装 Rust ```bash # 安裝 Rust 指令 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ... # 把 $HOME/.cargo/env 的环境带进来现在的指令行环境 source $HOME/.cargo/env # 撿查 rust 安裝好 rustup --version # 应该显示以下内容 > rustup 1.23.1 ... rustc --version # 应该显示以下内容 > rustc 1.49.0 ... cargo --version # 应该显示以下内容 > cargo 1.49.0 ... # 安装 ubuntu 常用的开发包 apt-get update apt-get install build-essential libssl-dev apt-get dist-upgrade # 重启服务器 reboot now ``` ## 本機安裝 Rust - 如果是苹果电脑,那安装过程和上面大同小异,但不需要跑 `apt-get` 及以下的指令。 - 如果你是 windows 电脑,看我第二个视频如何在本机安装 ubuntu 虚拟机。 ## 本機安裝 Cargo Remote - 1/2 - 到 https://github.com/sgeisler/cargo-remote ```bash # 安裝 cargo remote git clone https://github.com/sgeisler/cargo-remote # 下面指令可能跑长达 5 分钟 cargo install --path cargo-remote/ ``` ## 本机设置 ssh key 来连接到云服 ```bash # 生成你的 ssh key ssh-keygen -t rsa # 接着用它默認的設置,你在以下目錄會多了兩個檔案 # 1. `~/.ssh/id_rsa` - 这是你的私钥,别传给其他人。 # 2. `~/.ssh/id_rsa.pub` - 这是你的公钥,放到服务器上 # 进到个人目录 cd ~/ # 在个人目录下创建 .ssh 目录 mkdir .ssh cd .ssh # 创建并修改档案 nano ~/.ssh/config ``` 在 `~/.ssh/config` 裡加以下一塊 ``` Host cargo-remote-demo HostName <云服 IP> User root (主用户名,也可能是 `ubuntu`) LocalForward 9944 localhost:9944 IdentityFile ~/.ssh/id_rsa ``` 跟着在远端设置 ssh root 登录公钥,跑如下指令: ```bash ssh root@<云服 IP> # 现在已连到远端,在个人目录下创建 .ssh 目录 mkdir .ssh cd .ssh # 创建并修改档案 nano authorized_keys # 现在把本机生成的 `id_rsa.pub` 里的内容贴到这里来 # 可在本机用 `cat id_rsa.pub` 来查看档案内容 ``` ## 本機安裝 Cargo Remote - 2/2 在本机设 `cargo remote` 的设置档 ```bash cd ~/.config/cargo-remote nano cargo-remote.toml ``` 放入: ``` remote = "root@cargo-remote-demo" ``` 之後,你就可以用 cargo remote. ```bash # 以前用本机编译 cargo build --release # 現在用远端编译 cargo remote -- build --release # 以前在本机编译 cargo run --release # 現在用远端编译 cargo remote -- run --release ``` 基本就是 `cargo remote --` 然后再加平常你在本机用的参数。 ## 总结 你现在能作以下开发流程: - 本机编辑 Substrate / rust 项目 - 用 cargo remote 云服编译 - 要用 polkadot-js app 连的话,就先 `ssh cargo-remote-demo-pf` 用上 ssh port forwarding 功能。 - polkadot-js app 设连到 `http://localhost:9944` - 在云服跑起 Substrate 的 binary, 那 polkadot-js app 也能成功透过本机 9944 端口,连过去云服的 9944 端口。 ## 待续 1. 其实还有 sccache 我中间展示安装不成功,剪掉。但可以的话最好装上 sccache。 2. 下次弄个视频在 windows 机会安装 vagrant/virtual box 在本机跑 ubuntu 虚拟机。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully