XSGGT
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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 New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy 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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: WSL2 + docker-desktop tags: Windows --- # WSL2 + docker-desktop > [name=陳信安] > [time=TUE, OCT 06, 2020 10:03 AM] --- # Agenda * 何謂WSL * 安裝WSL + 升級WSL2 * Windows Terminal OR Hyper * zsh + oh my zsh + powerlevel10k * 常用插件 + 優化 * docker-desktop + kubectl + kubectx + linuxbrew + htop + gcloud sdk --- ## 何謂WSL --- WSL全名Windows Subsystem for Linux,意思是Windows的linux子系統 主要是讓開發人員無需安裝虛擬機就可以在Windows上運行Linux環境 --- ## 安裝WSL + 升級WSL2 --- 首先開啟Powershell(系統管理員)並執行以下命令: ##### 備註:Windows作業系統版本必須至少大於或等於Windows 10 2004 安裝WSL功能 ``` dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart ``` ![](https://i.imgur.com/5goG75D.png) --- ### 安裝WSL2功能 ``` dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart ``` ![](https://i.imgur.com/D7RvVIC.png) --- 執行 Win + R 輸入appwiz.cpl,點擊"開啟或關閉Windows功能" ![](https://i.imgur.com/dYOLKQ1.png) --- 勾選 Windows子系統Linux版 與 虛擬機器平台後重新開機 ![](https://i.imgur.com/sPaOyiG.png) --- ### 安裝Linux內核 目前為止我們只是開啟了WSL2的功能,接下來安裝Linux系統內核。 [Linux kernel載點](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi) 執行此命令 ``` wsl --set-default-version 2 ``` 之後安裝的Linux版本都會安裝在WSL2中 --- ### 安裝Linux 18.04 or 20.04 ##### 備註:Linux建議安裝 20.04版本(較穩定) 點擊開始 -> 輸入Microsoft store -> 開啟 ![](https://i.imgur.com/vwtHZ7X.png) --- 右上角搜尋Ubuntu ![](https://i.imgur.com/BkPVvNT.png) --- 選擇安裝Ubuntu 20.04 LTS ![](https://i.imgur.com/jptcs11.png) --- 安裝之後第一次打開Linux會初始化,待初始化完畢後進行設定帳號與密碼 設定完畢後執行重開機 --- 接下來執行```wsl -l -v```看到Version已經是2。到這裡WSL算是完成安裝 ![](https://i.imgur.com/zhAZui3.png) --- ## Windows Terminal Or Hyper(擇一) --- Windows Terminal是Microsoft推出一款全新的Windows終端機,可以把目前Windows上的CMD、Powershell與WSL 統一使用一套終端機,透過不同的分頁去使用不同的終端機 --- Hyper是Electron推出,主要特色是擁有大量的插件、主題等等擴展性強大。 --- ### Hyper[載點](https://hyper.is/#installation) ![](https://i.imgur.com/3aXTVN9.png) --- ### 主題切換 ![](https://i.imgur.com/UGYW0JH.png) --- ### 安裝Windows terminal 點擊開始 -> 輸入Microsoft store -> 開啟 ![](https://i.imgur.com/vwtHZ7X.png) --- 右上角搜尋Windows terminal ![](https://i.imgur.com/lwIFbWe.png) --- 選擇Windows terminal ![](https://i.imgur.com/dFYzkON.png) --- 完成畫面 ![](https://i.imgur.com/OdGHjye.png) --- ## zsh + oh my zsh + powerlevel10k --- Linux世界裡最常接觸到的就是指令,大多數的Linux版本預設帶的都是bash,但bash缺少了好看的介面與功能。如果您也是追求好看的介面那就不能錯過zsh並使用oh my zsh框架套上powerlevel10k主題 --- ### 安裝zsh 進入 Ubuntu 20.04後先進行系統更新再執行下列指令 ```= sudo apt-get install zsh -y ``` 將zsh設成預設的Shell ```= chsh -s /usr/bin/zsh ``` 重新載人 ```= source ~/.zshrc ``` --- ### 安裝oh my zsh 使用curl或wget下載 Oh My Zsh 並執行 * curl ```= sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ``` * wget ```= sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ``` --- ### 安裝 powerlevel10k 在安裝powerlevel10k前首先下載待會用到的字型,字型下載後安裝到Windows系統裡(C:\Windows\fonts) - [MesloLGS NF Regular.ttf](https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Regular.ttf) - [MesloLGS NF Bold.ttf](https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Bold.ttf) - [MesloLGS NF Italic.ttf](https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Italic.ttf) - [MesloLGS NF Bold Italic.ttf](https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Bold%20Italic.ttf) --- ![](https://i.imgur.com/VPMtXPT.png) --- powerlevel10k ```= git clone https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ``` 編輯~/.zshrc檔案  ```= vi ~/.zshrc ``` --- 修改成ZSH_THEME="powerlevel10k/powerlevel10k" 與新增POWERLEVEL9K_MODE="awesome-patched" ![](https://i.imgur.com/cipL1of.png) --- 預設使用WSL,將guid複製至defaultProfile ![](https://i.imgur.com/Cx1XiTf.png) --- 使用WSL開啟Ubuntu Windows terminal點選右上角的設定 ![](https://i.imgur.com/zHTMCLe.png) --- 增加下面2段參數至設定檔 ``` "commandline": "wsl.exe -d Ubuntu-20.04", "fontFace": "MesloLGS NF", ``` ![](https://i.imgur.com/LG3idMy.png) --- 重啓Windows terminal後開始設定風格 --- ###### 備註:如需重新設定可以執行`p10k configure` ![](https://i.imgur.com/tBjm9cA.png) --- ### 快捷鍵 `Ctrl + Shift + T` 打開新標籤頁 `Ctrl + Shift + 1` 進入配置文件中定義的第一個環境(Ctrl + Shift + 2進入第二個,以此類推) `Ctrl + Shift + W` 關閉分屏 `Alt + Shift + -` 橫向分屏 `Alt + Shift + +` 縱向分屏 `Ctrl + +` 放大 `Ctrl + -` 縮小 `Ctrl + 0` 恢復默認縮放比例 --- ## 常用插件 + 優化 --- ### 常用插件 zsh-syntax-highlighting(語法高亮) ```= git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting ``` zsh-autosuggestions(自動建議) ```= git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions ``` ###### 備註:如要提高高反差於.zshrc加入 ```= ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline" ``` --- zsh-completions(自動補全) ```= git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-completions ``` --- zsh-completions插件還需把`autoload -U compinit && compinit`增加到.zshrc。輸入以下指令 ```= [ -z "`grep "autoload -U compinit && compinit" ~/.zshrc`" ] && echo "autoload -U compinit && compinit" >> ~/.zshrc ``` --- 到這就剩最後一步了!將要啓用的插件增加到.zshrc。 ```= vi ~/.zshrc 新增 plugins=(git zsh-syntax-highlighting zsh-autosuggestions zsh-completions docker) or sed -i '/^plugins=/c\plugins=(git zsh-syntax-highlighting zsh-autosuggestions zsh-completions docker)' ~/.zshrc ``` --- ## 優化 ### 限制Windows terminal最大内存 在C:\Users\(使用者名稱)底下 新增.wslconfig 檔案 輸入以下 --- [wsl2] memory=4GB swap=8GB localhostForwarding=true ![](https://i.imgur.com/yIZx5iW.png) --- ## docker + kubectl + kubectx + linuxbrew --- ### 安裝docker 首先到docker官網下載[docker-desktop](https://www.docker.com/get-started) ##### 備註:因目前docker-desktop最新版(2.4.0.0)與K8S版本(1.18)有相容性問題,建議先退版安裝[2.3.0.5版本](https://docs.docker.com/docker-for-windows/release-notes/) ![](https://i.imgur.com/JOgzLnp.png) --- 安裝完成後,進入Settings的General把 Use the WSL2 based engine選項打勾 ![](https://i.imgur.com/F3yLlXo.png) --- 再進入Resources的WSL INTEGRATION把Enable integration with my default WSL distro打勾與點選Enable integration with additional distros ![](https://i.imgur.com/KYsNuR2.png) --- 輸入docker ps -a查看是否安裝成功 ![](https://i.imgur.com/tbyBk48.png) ###### 備註:如要安裝K8S請將Kubernetes中Enable Kubernetes打勾 ![](https://i.imgur.com/T8oOlAz.png) --- ### linuxbrew linuxbrew相當於Linux下的apt-get是一個安裝包工具,可以安裝各種軟體 [linuxbrew官網](https://docs.brew.sh/Homebrew-on-Linux) ```= /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" ``` --- 安裝後會出現以下步驟及提示,按照提示操作即可 ```= ==> Next steps: - Run `brew help` to get started - Further documentation: https://docs.brew.sh - Install the Homebrew dependencies if you have sudo access: sudo apt-get install build-essential See https://docs.brew.sh/linux for more information - Add Homebrew to your PATH in /home/zoechao/.zprofile: echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> /home/zoechao/.zprofile eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) - We recommend that you install GCC: brew install gcc ``` --- ```= sudo apt-get install build-essential ``` ![](https://i.imgur.com/iRUTWrx.png) --- ##### 備註:留意使用者名稱 ```= echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> /home/(使用者名稱)/.zshrc eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) ``` ![](https://i.imgur.com/xy9MtSW.png) --- ```= brew install gcc ``` ![](https://i.imgur.com/DkdgcLl.png) --- ### kubectl 主要是用來針對kubernetes集群運行命令 ```= brew install kubectl ``` --- ### kubectx 簡易切換kubernetes集群 ```= brew install kubectx ``` --- 安裝後輸入kubectx會帶出使用環境 ![](https://i.imgur.com/S6NT5kM.png) --- 執行後會列出所有的kubernetes集群 ![](https://i.imgur.com/4hv7QIw.png) --- 切換kubernetes集群 ```= kubectx <集群name> ``` ![](https://i.imgur.com/lFXZ4G1.png) --- ### kustomize kustomize 是 SIG-CLI 的一個子項目,其目的是為 K8s 提供一種可以重複使用配置檔的管理工具。 如果成功安裝linuxbrew,可直接執行brew的指令去安裝 ```= brew install kustomize ``` --- ### htop 查看linux系統效能最常用的指令是top。但功能比較陽春與顯示資訊不足,這時侯就可以安裝htop來取代內建的top ```= brew install htop ``` --- ![](https://i.imgur.com/ke8ggbW.png) --- 說明: PID:程序編號 USER:開啟程序的使用者名稱 PRI:Linux kernal排程優先順序,數值從0(最高優先權)到139(最低優先權) NI:Niceness,數值從-20(最高優先權)到19(最低優先權) VIRT:虛擬記憶體用量 RES:常駐記憶體用量 SHR:共享記憶體用量 --- S:程序狀態 - S:可中斷的睡眠 - D:不可中斷的睡眠狀態(例如IO) - R:執行中或可執行 - T:工作停止 - t:除錯中斷 - Z:Zombie Process(殭屍程序) --- CPU%:CPU使用率 MEM%:記憶體使用率 TIME+:程序執行時間 Comamnd:執行程序的命令 --- ### figlet 使用指令創造出文字標題 ```= brew install figlet ``` 輸入figlet docker(自定義文字) ![](https://i.imgur.com/bQeCzH8.png) --- ### gcloud sdk gcp console ```= curl https://sdk.cloud.google.com | bash ``` --- 點擊ENTER ![](https://i.imgur.com/4a7I6Xa.png) --- 輸入Y進行更新 ![](https://i.imgur.com/lm1HdPH.png) --- 點擊ENTER ![](https://i.imgur.com/n9FtIcN.png) --- 將下列命令加入~./zshrc ```= # google cloud sdk path if [ -d $HOME/.google-cloud-sdk ]; then export PATH="$HOME/.google-cloud-sdk/bin:$PATH"; fi ``` ![](https://i.imgur.com/yUmLZZj.png)

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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