跳至主要内容

附錄:維運工具軟體

本文件說明建議安裝的維運工具軟體,可提升系統管理效率。

終端管理工具

GNU Screen

Screen 是終端螢幕管理器,可在單一終端視窗中運行多個虛擬終端,即使中斷 SSH 連線,程式仍會在背景繼續執行。

安裝

sudo apt install screen -y

配置

編輯 /etc/screenrc,在檔案末尾加入:

# 啟用滑鼠滾動
termcapinfo xterm* ti@:te@

基本操作

# 建立新 session
screen -S myapp

# 列出所有 session
screen -ls

# 重新連接 session
screen -r myapp

# 分離目前 session(不中斷程式)
# 按 Ctrl+A 然後按 D

常用快捷鍵

按鍵功能
Ctrl+A D分離 session
Ctrl+A C建立新視窗
Ctrl+A N切換到下一個視窗
Ctrl+A P切換到上一個視窗
Ctrl+A "列出所有視窗

tmux

tmux 是更現代化的終端復用器,功能類似 Screen,但操作更直覺。

安裝

sudo apt install tmux -y

配置

建立 /etc/tmux.conf

# 使用 Alt+方向鍵切換 pane
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# 使用 Shift+方向鍵切換視窗
bind -n S-Left previous-window
bind -n S-Right next-window

# 啟用滑鼠模式
set -g mouse on

# 更簡單的分割快捷鍵
bind-key v split-window -h
bind-key h split-window -v

# 快速重新載入配置
bind-key r source-file ~/.tmux.conf \; display-message "Config reloaded"

# 防止登入腳本執行
set-option -g default-command "/bin/bash --noprofile"

# 256 色支援
set -g default-terminal "tmux-256color"

基本操作

# 建立新 session
tmux new -s myapp

# 列出所有 session
tmux ls

# 連接 session
tmux attach -t myapp

# 分離 session
# 按 Ctrl+B 然後按 D

常用快捷鍵

按鍵功能
Ctrl+B D分離 session
Ctrl+B C建立新視窗
Ctrl+B N下一個視窗
Ctrl+B P上一個視窗
Ctrl+B %垂直分割
Ctrl+B "水平分割
Ctrl+B 方向鍵切換 pane

系統監控工具

Glances

Glances 是跨平台的系統監控工具,提供 CPU、記憶體、網路、磁碟等即時資訊,支援 Web 介面。

安裝

sudo apt install glances -y

配置

編輯 /etc/glances/glances.conf

[network]
# 隱藏迴路介面
hide=lo

[diskio]
# 隱藏迴路裝置
hide=loop.*

# Docker 模組配置
# 在非 Docker 環境或不需要監控 Docker 時建議停用,可加快啟動速度並減少錯誤日誌
[docker]
disable=True

使用

# 啟動(終端模式)
glances

# 啟動 Web 模式(預設 Port 61208)
glances -w

# 指定 Port
glances -w -p 8888

常用快捷鍵

按鍵功能
Q離開
1顯示各 CPU 核心使用率
2顯示 CPU 左側欄
3開關 CPU 圖表
D開關磁碟 I/O
N開關網路
H顯示說明

htop

htop 是互動式的程序檢視器,比傳統 top 更易使用。

安裝

sudo apt install htop -y

使用

htop

常用快捷鍵

按鍵功能
F1說明
F5樹狀顯示
F6排序
F9終止程序
F10離開
/搜尋

系統資訊工具

neofetch

neofetch 是系統資訊顯示工具,可在登入時顯示系統摘要。

安裝

sudo apt install neofetch -y

自動顯示

建立 /etc/profile.d/neofetch.sh

#!/bin/bash

export TERM=xterm-256color

RED="31"
BOLDRED="\e[1;${RED}m"
ENDCOLOR="\e[0m"

# 顯示系統資訊
neofetch

# 顯示 Screen sessions
echo -e "${BOLDRED}Screen Sessions:${ENDCOLOR}"
screen -ls 2>/dev/null || echo " No sessions"

# 顯示 tmux sessions
echo -e "${BOLDRED}Tmux Sessions:${ENDCOLOR}"
tmux ls 2>/dev/null || echo " No sessions"

設定執行權限:

sudo chmod +x /etc/profile.d/neofetch.sh

網路工具

curl / wget

HTTP 客戶端工具,用於測試 API 和下載檔案。

# 通常已預裝,若無則安裝
sudo apt install curl wget -y

常用指令

# GET 請求
curl http://localhost:8080/api/health

# POST JSON
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://localhost:8080/api/data

# 下載檔案
wget https://example.com/file.tar.gz

# 顯示回應標頭
curl -I http://localhost:8080/api/health

netcat (nc)

網路診斷工具,用於測試埠號連線。

sudo apt install netcat -y

常用指令

# 測試埠號是否開放
nc -zv localhost 8080

# 監聽埠號
nc -l 8888

日誌工具

Log Navigator,進階日誌檢視工具,支援語法高亮和搜尋。

安裝

sudo apt install lnav -y

使用

# 檢視日誌
lnav /var/log/nginx/access.log

# 檢視多個日誌
lnav /opt/appfuse/logs/*.log /var/log/nginx/*.log

常用快捷鍵

按鍵功能
?說明
/搜尋
n下一個搜尋結果
N上一個搜尋結果
g跳到開頭
G跳到結尾
Tab切換檔案

磁碟工具

ncdu

NCurses Disk Usage,互動式磁碟使用分析工具。

安裝

sudo apt install ncdu -y

使用

# 分析目前目錄
ncdu

# 分析指定目錄
ncdu /opt/appfuse

# 分析整個系統
sudo ncdu /

工具安裝一鍵腳本

建立 /opt/appfuse/bin/install-tools.sh

#!/bin/bash

echo "=== 安裝維運工具 ==="

sudo apt update

# 終端管理
sudo apt install -y screen tmux

# 系統監控
sudo apt install -y glances htop

# 系統資訊
sudo apt install -y neofetch

# 網路工具
sudo apt install -y curl wget netcat

# 日誌工具
sudo apt install -y lnav

# 磁碟工具
sudo apt install -y ncdu

echo "=== 安裝完成 ==="
echo "已安裝: screen, tmux, glances, htop, neofetch, curl, wget, netcat, lnav, ncdu"

執行:

chmod +x /opt/appfuse/bin/install-tools.sh
sudo /opt/appfuse/bin/install-tools.sh

相關文件