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
    Week 14 (2024/12/12) Monitor --- - Book mode https://hackmd.io/@ncnu-opensource/book [toc] ## linux server常用監控工具 - process - top: 查看系統當前的 process,包含 pid 和資源使用量 - htop - 介面互動比top完整 - 欄位 1.系統 CPU usage 2.系統 Mem usage 3.系統負載 ![image](https://hackmd.io/_uploads/Skf--7_41g.png) - [btop](https://github.com/aristocratos/btop) - 介面比 htop 又更豐富 ![image](https://hackmd.io/_uploads/S1PvM7_E1g.png) ## disk - lsblk - df -h - iotop - free - vmstat ## SNMP - 架構圖 ![OIP](https://hackmd.io/_uploads/BygU4lkVke.png) ## The Simple Network Management Protocol (SNMP) Simple Network Management Protocol (SNMP) 是一種用於網路管理的協議。它被設計用來管理和監控網路設備(如Router, Switch, Servers等)上的數據。SNMP 提供了一個標準化的框架,通過它可以從網絡上的設備收集數據,監控和管理這些設備的運行狀況,並在發生異常時發出警報。 ![image](https://hackmd.io/_uploads/BkkZVPh7R.png) 1. **Manager**:在 Network Operations Center(NOC),有一台名為 Manager 的電腦。Manager 管理著大量的設備,例如 Router, Switch, Servers 等。 2. **Agent**:Manager 並不直接與被管理的設備對話。每個被管理的設備都有一個 Agent,Agents 可以是硬體、軟體或兩者兼有。Manager 與 Agent 對話,Agent 則與被管理的設備對話。 3. **Management Information Base (MIB)**:NOC 會使用 SNMP 不斷從被管理設備收集資料,並將這些資料放在 MIB ```mermaid flowchart TB Root-Node --> CCITT:0 Root-Node --> ISO:1 Root-Node --> JOINT:2 ISO:1 --> org:3 org:3 --> dod:6 dod:6 --> internet:1 internet:1 --> directory:1 internet:1 --> mgmt:2 internet:1 --> experimental:3 internet:1 --> private:4 mgmt:2 --> mib:1 mib:1 --> system:1 mib:1 --> interface:2 mib:1 --> addr-tran:3 mib:1 --> ip:4 mib:1 --> icmp:5 mib:1 --> tcp:6 mib:1 --> udp:7 mib:1 --> ... ``` :::info 這張圖的看法 OID: .1.3.6.1.2.1.4 = iso.org.dod.internet.mgmt.mib.ip ::: 4. **Command**:SNMP 的常用指令 - **GET**:用來從 Agent 獲取資料,**常用在已經知道某個OID的值** - **SET**:用來設置 Agent 中的變數值 - **TRAPS**:Agent 主動發送給 Manager 的異常或狀態改變通知,當agent知道今天自己有些問題時(e.g.開機沒通過身分驗證),會發通知給manager - **GET NEXT**:取得 MIB tree 下一個 OID 值,**常用來遍歷未知的MIB結構** - **GET BULK**:從 MIB 中取得特定某個 OID 其底下的Subtree - **INFORM**:SNMP 管理系統接收指令後回傳確認 - **RESPONSE**:回傳 SNMP 網路管理系統執行的值或訊號 - **snmpwalk [options] [IP address] [OID]**:指定設備的某個 OID 起點開始,自動遍歷其子節點以取得管理資訊 :::info 1. OID: **.1.3.6.1.4.1.2021.4.5.0** - 該台Server的MEM總大小 - private subtree(.1.3.6.1.4) - 由廠商自定義的管理物件,讓廠商可以提供適用他們設備的資料 - 例如: Cisco Router(.1.3.6.1.4.1.9),Net-SNMP(.1.3.6.1.4.1.2021) ::: 查通用 MIB 結構的網站: [OID assignments from the top node](https://www.alvestrand.no/objectid/top.html) ### 為何需要 master agent / subagent ![image](https://hackmd.io/_uploads/HJZHVVuVJe.png) 如果沒有 Master Agent: - Manager需要單獨與每個subagent溝通、且需要知道subagent的具體位置 - 遇到的問題 1. Manager 要查很多 agent 要查很久 2. agent 可能會位於內網中 - 解決 1. 由 master agent 暫存其他 subagent 回應,等 manager 來問一次回 2. 這樣只需要 master agent 有暴露給 manager ### 傳輸方式 - master -> agent: Send packet to agent on udp port 161 - agent -> master: udp port 162 on master - agent 主動傳給 master 時,像是 TRAP, INFORM ### SNMP 組成 1.訊息標頭(Message Header) - 包含兩個欄位 - 版本(Version)t->指定 SNMP 協議版本(例如 SNMPv1、SNMPv2c) - 共同體(Community String)->**就是密碼**,用來做身分認證,看是public or private,那也可以做不同權限的設定,像是Read-Only(只讀)、Read-Write(讀寫)。 ### 版本 - 最常用: SNMPv2c - 這版本才有 GET BULK - SNMPv3 - 有用 HMAC 雜湊來驗證身分 - 可以用對稱式加密來加密內容 - 推薦使用: v2c, v3 ### 安全等級 1. noAuthNoPriv - `snmpget -v2c -c public 198.19.249.116 1.3.6.1.2.1.1.1.0` - 沒有 authentication - 沒有加密(privacy) - 僅用 community string 驗證身分 - 中間人攻擊抓封包看得到 community string 2. authNoPriv - `snmpget -v3 -u lsa_authnopriv -l authNopriv -A testtest 198.19.249.116 1.3.6.1.2.1.1.1.0` - 有authentication - 沒有加密 - 抓封包??? 3. authPriv - 有 authentication - 有加密(privacy) - 雖然安全但有延遲,但內網應該是用不太到 ### DEMO - NetSNMP 定義的 - 常用OID,可以回傳 Network Interface 的名稱 (注意<font color=#f00>.1.3.6.1.2</font>) ![image](https://hackmd.io/_uploads/Hy_-GEO4kg.png) 查看CPU的使用量 ![image](https://hackmd.io/_uploads/rJ8yQVdE1x.png) ### LAB - 安裝 snmp manager - `sudo apt install snmp-mibs-downloader` - 安裝 snmp agent - `sudo apt install snmpd` - 常用指令 - `snmpget` - `snmpgetnext` - `snmpwalk` - `snmpset` - `snmptrap` #### 設定 - Manager:`sudo vim /etc/snmp/snmp.conf` - 把`#mibs`的註解拿掉 - Agent:`sudo vim /etc/snmp/snmpd.conf` - 讓 Agent 可以接收非本地來的 request :::info 把 `agentaddress 127.0.0.1,[::1]:161` 改成 `agentaddress udp:161,udp6:[::1]:161` ::: - 建立 SNMP User,讓 Manager 可以有權限送 request 給 Agent(加在檔案的最下面) ``` createUser tommy SHA myAuthPassword AES myPrivPassword rwuser tommy priv ``` myAuthPassword 跟 myPrivPassword 可以自己設定 tommy 也是 - 套用設定檔:`sudo systemctl restart snmpd` - 開啟防火牆: `sudo ufw allow 161` - 嘗試打:`snmpwalk -u <剛剛打的username> -l authPriv -a SHA-512 -x AES -A <你的AuthPassword> -X <你的myPrivPassword> <agent-ip> 1.3.6.1.2.1.2.2.1.2` 測試用(無密碼) - test 名稱可以自己取 - 新增`createUser test` - 設定密碼`rwuser test noauth` - 套用設定檔:`sudo systemctl restart snmpd` - 開啟防火牆: `sudo ufw allow 161` - snmpwalk -u test 127.0.0.1 1.3.6.1.2.1.2.2.1.2 謝謝薛閔容跟 Andy Su ## Cacti ## Nagios ## Prometheus ## Grafana

    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