NCNU-OpenSource
      • 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

      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
    • 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 Help
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
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

    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: 1091, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book Week 03(2020/10/8) === ## 上次作業 ``` 某天 MOLi 科技的攻城師阿偉收到一封客訴信,客戶小公主表示用他們家的網站系統很慢,要求改善,不然就要請律師姐姐對公司提告。 阿偉查了 Apache 網頁伺服器的紀錄檔沒發現問題,又調整了 MySQL 資料庫的設定,但改善程度有限,不知如何是好,便藉機請教隔壁部門的天菜妹。不消一炷香時間,就發現 CPU 和記憶體使用量正常,問題其實是公司太窮,硬碟太老舊,所以撐不住資料庫的大量的讀寫,加上網頁空間也快要滿了。 向來豪邁的練董正好經過聽到,說時遲那時快,直接從口袋裡掏出兩顆 4T 傳統硬碟、一顆 500G SSD 給他們。 請問: 1. 阿偉要到哪個目錄看 Apache 紀錄檔? 2. 阿偉要到哪個目錄調整 MySQL 設定? 3. 天菜妹要用什麼指令查看 CPU 和記憶體使用狀況? 4. 用這三顆硬碟裝新系統時,該怎麼規劃呢? ``` ### Apache 紀錄檔 1. `/var/log/apache2/` (最精確) - `access.log`: 紀錄連線資訊 ex: ip,時間 2. `/var/log/httpd` - 合理懷疑不在 Debain 系統,在 Linux 這種 Debian 系統中,若用 sudo apt install 安裝的會去區分 httpd 服務(nginx, lighttpd 等) ### MySQL 調整設定 1. `/etc/mysql/my.cnf` :::info 跟設定有關,都會在`/etc`底下 ::: - /root : 是超級使用者儲存家目錄的地方 (非本題答案) ### 要用什麼指令查看 CPU 和記憶體使用狀況 1. `top` - 一次看完需要的東西,也可以列出每個核心的使用量 - 按下 `M` 鍵,直接依記憶體使用量排序 3. cat/proc/cpuinfo - `proc` 虛擬目錄,跟 process 有關 - 多少顆 CPU 或型號,無法表示出 CPU 使用量 4. cat/proc/meminfo - 詳細列出 cpu 使用量 5. ps - 每一個 process 目前的狀態,但看不到總記憶體 6. htop - top 加強版 ### 硬碟規劃 - 傳統硬碟 - 便宜,同價位下,能買到較大的空間 - 速度比較慢、效能較差 - SSD 固態硬碟 - 快、效能佳 - 昂貴 :::info - 本題服務 : **網頁伺服器、資料庫** - 資料庫讀寫頻繁,可以考慮放在 SSD 裡 - 網頁伺服器需要的是空間大,放的是中小型瑣碎檔案 - 程式放在 SSD 與 HDD 的差別只有在啟動速度。當程式在運行時,他是在記憶體運行,因此跟放在哪種硬碟無關 - 對於伺服器來說,不需一直開關機,反而是資料存取較重要 - 4T HDD1 - web server 伺服器放的地方 - 4T HDD2 - (也給 web server ) - 500G SSD - 資料庫 - /boot 100MB,啟動較快(錯誤答案) - 更新可能就爆了,要就給多一點 - /boot 切 SSD 使用效率不好 ::: :::success - 為什麼要做磁碟分割(詳情請看上周共筆) - 限制使用的空間大小 - 資料損毀時,不會互相影響 - 資料保護-當其他磁區壞掉時,不會影響到重要磁區 ::: ### BT 補充 > 劈哩啪啦 西哩花啦 [name= BlueT] :::danger - **盡量一個分割區就在一個硬碟裡(也有例外)** - 如果一定要把多顆硬碟都作分割使用,建議一開始就做成磁碟陣列 ::: - / : 一定要有根目錄 - /usr : 放軟體 - /tmp : 可能會做獨立分割 - /opt : 放垃圾(程式) - /boot : 非必要,視電腦及環境架構決定要不要切;若要切割,不要太小(一個kernel小的大概20-30MB,大的大概70-80MB) - /home : 所有使用者的家目錄 - 這是一台網頁伺服器,通常不會開系統帳號給外人 - 不會在裡面放太多東西 - /swap : 當記憶體滿了,放到此的軟體運作會極慢 - 如果放 SSD 很傷: swap需要經常讀寫,而 SSD 寫入壽命較低(雖然讀取不影響壽命) - `ls -al /tmp`(指令) : 查看 `/tmp` 目錄內的檔案 ## 常用指令 - 終端機 - `ctrl + shift + n`: 在新視窗開啟終端機(限定在你現在的視窗是終端機 - `ctrl + shift + T`: 在同一個視窗開啟終端機 - `ctrl + alt + T`: 開啟新的終端機(跟第一個差不多啦,差在這個不論是哪個視窗都可以叫出終端機) ### 操作檔案 - `ls -al`: 可以看到詳細資料 - `l` : link - `d` : 目錄 - `-` : 檔案 - `rwx`(權限) : 讀(read),寫(write),執行(execute) - `r` : 4, `w` : 2, `x` : 1 - `rwx/rwx/rwx`: 分別是`owner所有者/group群組/other其他人`的權限等級 ![](https://i.imgur.com/4LFwutd.jpg) - sticky bit (最後一個是t,rwxrwxrw**t**) - 除了 root 都不能亂動 - rws - 執行此指令時 權限會被提高 - eg.更改密碼時 - 檔名顏色 - **<font color="red">壓縮檔</font>** red newFile?? - ==**<font color="white">一般檔案</font>**== white - **<font color="blue">資料夾</font>** pale blue - **<font color="lightblue">軟連結 (symbolic link)</font>** sky blue --- ##### 補充 - 在 Linux 中的檔案有三種時間戳記: - access time:檔案最後被讀取的時間。 - modify time:檔案最後被修改的時間。 - change time:檔案屬性(例如權限、擁有者等)最後被修改的時間 --- - `touch <filename>` : 建立一個空白檔案或者更新檔案修改時間 - 更改檔案(或目錄)的時間戳計 - `touch newFile.txt`: 建立一個為 newFile 的 txt 檔 - 若只要更新 access time,可以加上 -a 參數 - `touch -a filename` - `ls -i 檔名` : 查看指定檔案的 inode - `ls -l 檔名` : 以長格式(long listing format)表示,包含檔案屬性 - `ls -il 資料夾名稱` - `ln <oldfilename> <newfilename>`:建立 hard link,前面是舊檔案名,後面是新檔案名 - **<font color="red">不能跨 file system </font>**,像是建立另一個門 是同一個檔案,不能改資料型態 - 把`ln`換成`ln -s`就變成 Symbolic Link 了 - `clear`: 將terminal清空 - `chmod`: 更改檔案權限 - 新增檔案時,權限預設為644(Owner 可讀可寫,其餘唯讀) - `chmod 777 檔名` : 把此檔改成所有人可讀可寫可執行 - `chmod a+x 檔名`: 直接替所有人(all)新增可執行(x)權限 - `r(read)`、`w(write)`、`x(excute)` - `chmod g+w 檔名`: 替 群組(g) 加上可寫(w) - `u(user)`、`g(group)`、`o(other)` - `chown`: 更改檔案的擁有者 - - eg. 把檔案擁有者設為 root : `sudo chown root <filename>` 升級權限 > hāi ya [name=天菜妹] ### 檔案建置 - `touch`:如果沒檔案,就建立一個。如果有,將他的檔案時間標記更新到現在 - `echo` : 產生一個訊息 - `>` : 把前面的訊息寫進去 會覆寫掉原本的東西 - `>>`: 把前面的訊息寫進去 皆在原本東西的後面,不會覆寫 - `cat` : 偷看一下內容 - `mkdir + 名稱` : 建立資料夾 ### BT補充 > 我們現在來簡單介紹一下 inode 是什麼洨,喔不是[name=BlueT] - inode - 數字標記該往哪裡找檔案 - soft link 會產生不同 inode - 因為跟原本的檔案無關,是不同的檔案 - hard link 是同一個 inode - 因為是指到同一個檔案 - link 大不同 ![](https://i.imgur.com/aiylrOH.png) - symbolic link(soft link) (Windows 的捷徑) - `ln -s <目標檔案> <softlink連結>` - **一個獨立的檔案,存的是記憶體位址**,這個檔案會指向另一個路徑(可能不存在) - 不管你指向的東西是否存在 - ls 可以看到指向哪個位置(可以是資料夾) - 建立一個新的 link 的檔案 - 可以跨 file system > 除非你知道你在幹麼,不然都給我用soft link[name=BT] - [hard link](https://en.wikipedia.org/wiki/Hard_link) - `ln <hardlink_name> <file_name>` - 同一個東西有不同名字 - 只想保留一個檔案真實存在,但在別的地方也想用 - ls 的時候看不出來是一個 link - 刪掉 hard link 時 counter - 1,然後檢查 counter ,當 counter = 0 檔案才會真的被刪掉 - 在硬碟中只佔一個檔案的空間 - 不能跨 file system - 備份檔案(將相同的內容用hardlink指過去) > 以遊戲術語來講,soft link 就像影分身,本體掛了就沒了。 > hard link就像史萊姆,可以不斷分裂,你要把全部都消滅才算消滅。[name=陳柏瑋] > ![](https://i.imgur.com/rHkMtlc.png) > > ![](https://i.imgur.com/2w2tCwi.png) > 喔哇~,我有sock檔[name=大家的姐姐 - 歐芷欣] > 之前有同學說不要延遲下課時間,所以我現在來加速標一下車[name=BlueT] - 使用者權限在/etc底下,紀錄有甚麼使用者 - /etc/shadow : 存使用者的密碼 一般使用者看不到 用sudo > sudo vim /etc/shadow - /etc/groups : 甚麼使用者在甚麼群組底下 - /etc/passwd : 存放UID GID ## 文字編輯器 - `nano` - `vi`/`vim` - ~~echo "xxx" > yyy~~ ## Question? 就等你們開口口口口口渴:) >[color=red]Q:r,w,x 為啥分別代表4,2,1呢 >>[color=blue]A:2進位啊(2^2^,2^1^,2^0^) ## 火車 1. 開啟 terminal 2. 輸入`sudo apt install sl` 3. 確定安裝 4. `sl` 5. 如果你的是 ubuntu 是 18.X.X 的話,可以輸入`sl -h`

    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