Miyago
    • 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
    --- title: Linux與服務部署 tags: mcu, osc, tutorial # type: slide slideOptions: transition: fade --- # Linux與服務部署 --- ## Linux基本介紹 雖然現今的作業系統 都已經有完備的圖形介面可供便利操作 比較少人使用指令 但熟悉指令後 許多操作會變得相對簡潔有力 因此我們以Linux為主軸介紹指令的使用 --- ## Linux是什麼 ---- ### 作業系統簡介 **Operating System (作業系統)** 作業系統是電腦裡的系統程式 負責調度與分配硬體資源給需要的應用程式使用 ---- 而最常見的作業系統有 - Windows - MacOS - Linux ---- ### Windows 大家再熟悉不過的作業系統 大部分台灣人使用文書和遊玩遊戲都是用這套系統 由微軟開發 以完全的圖形操作介面聞名 ---- ### MacOS 第二多人使用的作業系統 由蘋果開發 介面優雅簡潔 通常用於文書和工作處理 比較少用於遊玩遊戲 ---- ### Linux 今天的主角 是由社群合力開發的作業系統 雖然一般使用者較少 但卻是伺服器系統的首選 > ![](https://i.imgur.com/gpz5ibj.png =125x) > Linux的吉祥物企鵝 ---- ### Linux Kernal Linux的本質是一個作業系統核心 意即只包含了最基本的功能 而 Linux 的核心當初由 *Linus Torvalds* 開發出來 並且將所有原始碼開放 讓所有人皆能自由修改使用 這也造成了後來 Linux 有各種變化版本。 ---- ### Linux Distribution Linux 發行版就是將核心加上搭配其他程式打包起來 變成使用者能夠自行安裝進電腦的形式 而各發行版的差別 最明顯的就是圖形介面 :::info 熱知識: Android就是為行動裝置開發的Linux發行版 ::: ---- ### 為什麼選用Linux 1. 免費 開源 2. 多個用戶 多個線程 多個任務 3. 高穩定性和高效性 4. 類Unix系統 ---- ### 要選擇哪一種Linux系統 Linux的系統有非常非常多種 有centOS、debian、Kali、Arch之類的很多很多 以系統完善和穩定度而言 許多公司行號會選擇Debian或同系的Ubuntu 筆者的電腦則是ArchLinux 以輕量化著名 --- ## 學習詠唱咒語: 跟Terminal互動 玩Linux指令的第一步 ~~是要先有這個系統~~ 是要先學會如何打指令跟系統溝通 ---- ### 終端機 終端機是一個純文字介面的程式 會提供Shell跟系統進行互動 而Shell能夠下指令 判斷你的指令意圖並告訴系統 ---- 在三大系統中 分別可以這樣開啟Terminal - Linux - Ctrl+Shift+T - 系統功能表->系統工具->終端機 - MacOS - 在啟動器裡面尋找「Terminal.app」 - Windows - 使用Windows Terminal開啟Powershell > 注意 CMD和Linux指令並不兼容 ---- ### 沒有Linux系統怎麼辦 - 魔改自己的電腦系統 - 使用虛擬機 - 使用虛擬雲 - 使用wsl - ~~買一台幫你裝好的新電腦~~ ---- ### Alwaysdata 本文會以這個平台進行示範 免付費註冊能夠給予100mb玩到爽的服務 並且提供網域可以監控服務 --- ## Linux常用指令 有了終端機之後就能打指令和系統互動了 ---- ### ssh 首先優先介紹這個 - 一種能和遠端伺服器互動的加密協定 ```shell= ssh user@domain ``` > [穿牆術補充](https://hackmd.io/@fanlan1210/S16xysoZ5#/) > @fanlan1210 ---- ### pwd - print working directory - 顯示目前你所在的位置 在終端機裡面通常會想做的第一件事 就是查詢目前所待的目錄位置 這行指令可以辦到這件事 ![](https://i.imgur.com/rxtx1Vd.png =480x) ---- ### ls - list - 列出資料夾裡的內容 - 預設列出你目前所在的資料夾 ```shell= ls ls <資料夾名稱> ls -a #列出隱藏內容 ls -l #列出詳細資料 ``` ![](https://i.imgur.com/IEDEM44.png =480x) ---- ### cd - change directory - 切換資料夾 ```shell= cd <資料夾位置> ``` ![](https://i.imgur.com/1Ey6OIj.png =480x) ---- ### 補充: 位置表示法 在表示位置中有兩種表示法 - 相對位置 - 絕對位置 ---- #### 絕對位置 - 台灣桃園市龜山區明路5號S棟5樓之13 絕對位置是從最初的起點一路表示到所在位置 像是我們現在的位置就可以表示成上面那樣 ---- #### 相對位置 - 銘傳大學AA棟隔壁那個S棟 相對位置可以是用目前所在位置作為參考 進一步去延伸想要表示的位置 就像是以一個現成的建築物去對照資訊大樓的位置 ---- 而在 Linux 裡面,這種比照方式就不是以 / 開頭,而會是`.`和`..`: - `.` 開頭: 目前所在的位置 - `..` 開頭: 目前所在的位置的上一層 ---- ### mkdir - make directory - 建立資料夾 ```shell= mkdir <新資料夾名稱> ``` ![](https://i.imgur.com/mdnnMXv.png =480x) ---- ### cp - copy - 複製檔案、資料夾 ```shell= cp <檔案名稱> <新檔案名稱> cp -R <資料夾名稱> <新資料夾名稱> ``` ---- ### nano/vim - 兩種文字編輯器 - vim用法 - `:w`: 儲存檔案 - `:q`: 離開檔案 ```shell= vim <文件名稱> ``` ---- ### cat - ~~貓~~ concatenate - 檢視檔案內容 ```shell= cat <檔案名稱1> <檔案名稱2> ...... ``` ![](https://i.imgur.com/VjT29Wk.png =480x) --- ## 注意 接下來要介紹的指令有一定操作風險 請小心使用 一不小心就會 bang ---- ### mv - move - 移動檔案或資料夾 - 更改名稱 - **覆蓋檔案** 如果移動的位置不變 就會有更改檔案名稱的作用 ```shell= mv <檔案名稱> <資料夾名稱> mv <原名稱> <新名稱> ``` :::danger 只是要注意如果新名稱已經存在 系統將不會警告 直接強制覆蓋掉 ::: ---- ### rm - remove - 刪除檔案或資料夾 - **不可逆** 不經過垃圾桶而直接將檔案或目錄移除 ```shell= rm <檔案名稱> rm -R <資料夾名稱> ``` ---- ### sudo - superuser do - 以管理員權限執行後者指令 ```shell= sudo <指令> ``` --- ## 服務部署 ---- 既然我們會基礎的linux操作了 是時候試試在linux環境下架設一個屬於我們自己的服務吧 --- ### npm - node package manager node.js自帶的套件管理器 > windows系統底下可以[在這邊](https://nodejs.org/en/)下載 ```shell= npm install <package> #安裝套件 npm install #安裝package.json中寫好的套件 ``` ---- ### node_module - 裡面存放著nodejs專案所需的各種library - 超級肥 ![](https://i.imgur.com/XSqE10D.png =480x) ---- ### run nodejs的服務可以透過`node`指令執行檔案 或者各個npm套件有各自可以run的腳本 ```shell= node app.js npm run server ```

    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