From 53206ca15e7fc56ec3366db3b8730565fbbb8617 Mon Sep 17 00:00:00 2001 From: jiantw83 Date: Wed, 14 Oct 2026 04:46:28 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20JSC=20=E7=9F=A5=E8=AD=98?= =?UTF-8?q?=E5=BA=AB=EF=BC=88=E5=85=AB=E7=AB=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.1-修改成台北時區.md | 13 + 1.2-延展系統硬碟.md | 87 ++++++ 1.3-憑證-x509-問題.md | 57 ++++ 1.4-進入-busybox-問題.md | 29 ++ 1.5-Kernel-Panic:VFS-無法掛載-root-fs.md | 53 ++++ 1.6-常用工具.md | 35 +++ 1.7-使用舊的右鍵選項.md | 5 + 2.1-netplan.md | 54 ++++ 2.2-53-埠被占用.md | 45 +++ 2.3-掛載-SMB.md | 69 +++++ 2.4-停用-SMB-服務.md | 19 ++ 2.5-TGT.md | 46 ++++ 2.6-OpenSSH.md | 7 + 2.7-OpenWrt.md | 43 +++ 2.8-DiskStation-Manager.md | 95 +++++++ 3.1-套件更新設定.md | 33 +++ 3.2-硬碟直通.md | 20 ++ 3.3-將PCIe直通給PVE的虛擬機.md | 122 +++++++++ 3.4-相關參考紀錄.md | 10 + 3.5-解決Windows安裝WSL後死機的問題.md | 7 + 3.6-Hyper-V.md | 39 +++ 3.7-WSL:從零開始.md | 13 + 3.8-WSL:安裝-Ubuntu-26.04.md | 13 + 3.9-避免虛擬化啟動失敗.md | 16 ++ 4.1-Docker(Ubuntu).md | 53 ++++ 4.2-Docker(Raspberry-Pi).md | 21 ++ 4.3-K3s.md | 9 + 4.4-k3d.md | 41 +++ 4.5-Traefik.md | 230 ++++++++++++++++ 5.1-PostgreSQL.md | 36 +++ 5.2-SQLServer.md | 115 ++++++++ 5.3-Redis.md | 49 ++++ 5.4-ElasticSearch.md | 257 ++++++++++++++++++ 6.1-Gitea.md | 180 ++++++++++++ 6.10-VS-Code.md | 37 +++ 6.11-Coder.md | 88 ++++++ 6.12-Oh-My-Posh.md | 13 + 6.2-GiteaRunner(Ubuntu).md | 81 ++++++ 6.3-Gitea-Runner.md | 65 +++++ 6.4-GiteaRunner(Alpine).md | 74 +++++ 6.5-Gitlab.md | 35 +++ 6.6-ASP.NET.md | 29 ++ 6.7-Django.md | 41 +++ 6.8-Node-JS.md | 19 ++ 6.9-C#-SDK.md | 23 ++ 7.1-ccstatusline.md | 26 ++ 7.2-CLIProxyAPI.md | 39 +++ 7.3-OpenClaw.md | 55 ++++ 7.4-OpenCode.md | 53 ++++ 7.5-PicoClaw.md | 95 +++++++ ...解決方案內,所有專案的註解,並整理-README.md | 29 ++ 8.1-Emby.md | 21 ++ 8.2-MeTube.md | 88 ++++++ 8.3-Vaultwarden.md | 15 + 8.4-ezBookkeeping.md | 80 ++++++ Home.md | 22 ++ 第1章-系統維護.md | 13 + 第2章-網路與儲存.md | 14 + 第3章-虛擬化.md | 15 + 第4章-容器與編排.md | 11 + 第5章-資料庫與搜尋.md | 10 + 第6章-開發與持續整合.md | 18 ++ 第7章-AI-工具.md | 12 + 第8章-應用服務.md | 10 + 64 files changed, 3052 insertions(+) create mode 100644 1.1-修改成台北時區.md create mode 100644 1.2-延展系統硬碟.md create mode 100644 1.3-憑證-x509-問題.md create mode 100644 1.4-進入-busybox-問題.md create mode 100644 1.5-Kernel-Panic:VFS-無法掛載-root-fs.md create mode 100644 1.6-常用工具.md create mode 100644 1.7-使用舊的右鍵選項.md create mode 100644 2.1-netplan.md create mode 100644 2.2-53-埠被占用.md create mode 100644 2.3-掛載-SMB.md create mode 100644 2.4-停用-SMB-服務.md create mode 100644 2.5-TGT.md create mode 100644 2.6-OpenSSH.md create mode 100644 2.7-OpenWrt.md create mode 100644 2.8-DiskStation-Manager.md create mode 100644 3.1-套件更新設定.md create mode 100644 3.2-硬碟直通.md create mode 100644 3.3-將PCIe直通給PVE的虛擬機.md create mode 100644 3.4-相關參考紀錄.md create mode 100644 3.5-解決Windows安裝WSL後死機的問題.md create mode 100644 3.6-Hyper-V.md create mode 100644 3.7-WSL:從零開始.md create mode 100644 3.8-WSL:安裝-Ubuntu-26.04.md create mode 100644 3.9-避免虛擬化啟動失敗.md create mode 100644 4.1-Docker(Ubuntu).md create mode 100644 4.2-Docker(Raspberry-Pi).md create mode 100644 4.3-K3s.md create mode 100644 4.4-k3d.md create mode 100644 4.5-Traefik.md create mode 100644 5.1-PostgreSQL.md create mode 100644 5.2-SQLServer.md create mode 100644 5.3-Redis.md create mode 100644 5.4-ElasticSearch.md create mode 100644 6.1-Gitea.md create mode 100644 6.10-VS-Code.md create mode 100644 6.11-Coder.md create mode 100644 6.12-Oh-My-Posh.md create mode 100644 6.2-GiteaRunner(Ubuntu).md create mode 100644 6.3-Gitea-Runner.md create mode 100644 6.4-GiteaRunner(Alpine).md create mode 100644 6.5-Gitlab.md create mode 100644 6.6-ASP.NET.md create mode 100644 6.7-Django.md create mode 100644 6.8-Node-JS.md create mode 100644 6.9-C#-SDK.md create mode 100644 7.1-ccstatusline.md create mode 100644 7.2-CLIProxyAPI.md create mode 100644 7.3-OpenClaw.md create mode 100644 7.4-OpenCode.md create mode 100644 7.5-PicoClaw.md create mode 100644 7.6-補充解決方案內,所有專案的註解,並整理-README.md create mode 100644 8.1-Emby.md create mode 100644 8.2-MeTube.md create mode 100644 8.3-Vaultwarden.md create mode 100644 8.4-ezBookkeeping.md create mode 100644 第1章-系統維護.md create mode 100644 第2章-網路與儲存.md create mode 100644 第3章-虛擬化.md create mode 100644 第4章-容器與編排.md create mode 100644 第5章-資料庫與搜尋.md create mode 100644 第6章-開發與持續整合.md create mode 100644 第7章-AI-工具.md create mode 100644 第8章-應用服務.md diff --git a/1.1-修改成台北時區.md b/1.1-修改成台北時區.md new file mode 100644 index 0000000..80677f1 --- /dev/null +++ b/1.1-修改成台北時區.md @@ -0,0 +1,13 @@ +> 第1章 系統維護 · 來源:Ubuntu 知識庫 + +# 簡介 + +Ubuntu 預設時區通常為 UTC,會導致系統時間與台灣本地時間相差 8 小時。以下指令將系統時區設定為台北(Asia/Taipei)。 + +# 設定時區 + +```bash +sudo timedatectl set-timezone Asia/Taipei +``` + +設定後可用 `timedatectl` 確認時區是否已套用。 diff --git a/1.2-延展系統硬碟.md b/1.2-延展系統硬碟.md new file mode 100644 index 0000000..169d10f --- /dev/null +++ b/1.2-延展系統硬碟.md @@ -0,0 +1,87 @@ +> 第1章 系統維護 · 來源:Ubuntu 知識庫 + +# 簡介 + +當虛擬機磁碟容量在外部(例如 PVE)擴充後,Ubuntu 內部不會自動使用新空間。本文記錄將新增空間一路套用到 LVM 邏輯磁區的流程:調整分割區 → 擴充 PV → 擴充 LV → 擴充檔案系統。 + +> 注意:`fdisk` 刪除並重建分割區具風險,操作前請先備份重要資料,並確認起始磁區(First sector)維持原值。 + +# 1. 確認磁碟大小 + +先用 `lsblk` 查看目前磁碟與分割狀況。 + +```bash +lsblk +``` + +以下範例中,`sda` 已擴充為 64G,但分割區 `sda3` 與其上的 LVM 仍只有 30G。 + +```bash +NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS +sda 8:0 0 64G 0 disk +├─sda1 8:1 0 1M 0 part +├─sda2 8:2 0 2G 0 part /boot +└─sda3 8:3 0 30G 0 part + └─ubuntu--vg-ubuntu--lv 252:0 0 30G 0 lvm / +sr0 11:0 1 1024M 0 rom +``` + +# 2. 調整硬碟大小 + +用 `fdisk` 刪除舊的 `sda3` 並以相同起始磁區重建為較大的分割區。**刪除分割區時務必選擇保留(N)LVM2 簽章**,否則會破壞磁區。 + +```bash +sudo fdisk /dev/sda +``` + +操作流程如下(`p` 檢視、`d` 刪除、`n` 新增、`w` 寫入): + +```bash +Command (m for help): p +Device Start End Sectors Size Type +/dev/sda1 2048 4095 2048 1M BIOS boot +/dev/sda2 4096 4198399 4194304 2G Linux filesystem +/dev/sda3 4198400 67108830 62910431 30G Linux filesystem + +Command (m for help): d +Partition number (1-3, default 3): +Partition 3 has been deleted. + +Command (m for help): n +Partition number (3-128, default 3): +First sector (3719168-46137310, default 3719168): +Last sector, +/-sectors or +/-size{K,M,G,T,P} (3719168-46137310, default 46135295): +Created a new partition 3 of type 'Linux filesystem' and of size 62 GiB. +Partition #3 contains a LVM2_member signature. +Do you want to remove the signature? [Y]es/[N]o: N + +Command (m for help): p +Device Start End Sectors Size Type +/dev/sda1 2048 4095 2048 1M BIOS boot +/dev/sda2 4096 4198399 4194304 2G Linux filesystem +/dev/sda3 4198400 124217694 130019295 62G Linux filesystem + +Command (m for help): w +The partition table has been altered. +Syncing disks. +``` + +# 3. 調整 PV 大小 + +讓 LVM 的實體磁區(Physical Volume)認得擴大後的分割區。 + +```bash +sudo pvresize /dev/sda3 +``` + +# 4. 調整 LV 大小 + +將邏輯磁區(Logical Volume)擴充到吃下所有剩餘空間,再擴充其上的檔案系統。 + +```bash +sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv +``` + +```bash +sudo resize2fs /dev/ubuntu-vg/ubuntu-lv +``` diff --git a/1.3-憑證-x509-問題.md b/1.3-憑證-x509-問題.md new file mode 100644 index 0000000..40a377b --- /dev/null +++ b/1.3-憑證-x509-問題.md @@ -0,0 +1,57 @@ +> 第1章 系統維護 · 來源:Ubuntu 知識庫 + +# 簡介 + +當網路環境中有防火牆或代理(例如 Fortinet)對 HTTPS 連線做 SSL 攔截時,Ubuntu 會因為缺少對應的根憑證而出現 x509 憑證錯誤(例如 `docker pull` 失敗)。解決方式是把攔截端的憑證加入系統信任清單。 + +# 1. 查詢缺少的憑證 + +連線到目標站台並列出完整憑證鏈。 + +```bash +openssl s_client -connect registry-1.docker.io:443 -showcerts +``` + +複製憑證鏈中最後的憑證金鑰。以下內容請自行執行取得,因為憑證可能更新(以下金鑰複製於 2025/03/24): + +```bash +-----BEGIN CERTIFICATE----- +MIID5jCCAs6gAwIBAgIIIXGGV4x82u0wDQYJKoZIhvcNAQELBQAwgakxCzAJBgNV +BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlTdW5ueXZhbGUx +ETAPBgNVBAoMCEZvcnRpbmV0MR4wHAYDVQQLDBVDZXJ0aWZpY2F0ZSBBdXRob3Jp +dHkxGTAXBgNVBAMMEEZHNkgxRVRCMjE5MDAzMjcxIzAhBgkqhkiG9w0BCQEWFHN1 +cHBvcnRAZm9ydGluZXQuY29tMB4XDTIxMDgyNjIyNTUwMFoXDTMxMDgyNzIyNTUw +MFowgakxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQH +DAlTdW5ueXZhbGUxETAPBgNVBAoMCEZvcnRpbmV0MR4wHAYDVQQLDBVDZXJ0aWZp +Y2F0ZSBBdXRob3JpdHkxGTAXBgNVBAMMEEZHNkgxRVRCMjE5MDAzMjcxIzAhBgkq +hkiG9w0BCQEWFHN1cHBvcnRAZm9ydGluZXQuY29tMIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAr36+xa3QAC3O3GYUghMwnwLY/oJL9S1fG7jHmxsdlhZX +k+4kGSnaFDDAgUM1D8WfM6eeojL2qK82TQF4eRRYGsb9Ls/lHT4O7iDOppF66h1E +wHuSC6WYT/axv3dyfRkC3/Ic+NGmfn1EOY+XtVdf4ZCSLL/MFAcD5A8Kjxa/wcN0 +1xhJMBop5hEENXxoOnc5UJKlyEQYhnpBG4J8cdceRwWTGZmCGkNgUAeivI/amADh +Ma/StLLxGqKW4zneM4db3vQJexmI+pdeM+UoUDZ++hwWF75byevntNFfYzGYvQnZ +Y1sWyph3uhyVgkx8zylFOeJKGTyCL5gbw66AaTlmSQIDAQABoxAwDjAMBgNVHRME +BTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQATzLjdJALCzxafMZCAIGi/ZHMBUt3X +HV7jDmjvNGBWyaHR9n/VsfzIojg5Eju10FSB0tBOvRwJT2kzwzXlLVzRQKeKwWbx +VxMp+gdBxSaW58u5aJKQTW0FnZQQqUtdsLw+uCCpHIxZuGSOZDzXIm2Gyfq37oBu +VjWDXFP8RLqGMZFSIapN1i02yMOD2IHfUqBngbpMJxvZa4oHOoVTKW9BkgENyRh+ +XBJuzcWXbsmPKucD5O7CP+n9flP4AAz1BIrHD93ychm5rqAl5gvYD5bGDAdshWnC +ng6AGIc94BzGo10X+Ly1YK3zpPiiMx6xx2LNX3XyLUDL3QKMqVJi0G8u +-----END CERTIFICATE----- +``` + +# 2. 查詢憑證存放的位置 + +確認系統信任憑證的存放路徑。 + +```bash +curl -k -v https://registry-1.docker.io/v2/ +``` + +Ubuntu 24.04 存放於以下位置: + +```bash +/etc/ssl/certs/ca-certificates.crt +``` + +將剛剛查詢到的憑證金鑰,貼到 `ca-certificates.crt` 檔案的最後即可。 diff --git a/1.4-進入-busybox-問題.md b/1.4-進入-busybox-問題.md new file mode 100644 index 0000000..0a18c03 --- /dev/null +++ b/1.4-進入-busybox-問題.md @@ -0,0 +1,29 @@ +> 第1章 系統維護 · 來源:Ubuntu 知識庫 + +# 簡介 + +開機時若檔案系統毀損,Ubuntu 會中斷在 BusyBox(initramfs)救援環境,停在 `(initramfs)` 提示字元。本文記錄找出根磁區並修復檔案系統,使系統恢復正常開機的步驟。 + +# 1. 列出所有分區 + +找出根檔案系統所在的磁區。 + +```bash +blkid +``` + +# 2. 修復系統磁區 + +對根磁區執行檔案系統檢查與自動修復(`-y` 表示對所有提示自動回答 yes)。 + +```bash +fsck -y /dev/mapper/ubuntu--vg-ubuntu--lv +``` + +# 3. 離開後,自動進入系統 + +修復完成後離開 BusyBox,系統會繼續完成開機。 + +```bash +exit +``` diff --git a/1.5-Kernel-Panic:VFS-無法掛載-root-fs.md b/1.5-Kernel-Panic:VFS-無法掛載-root-fs.md new file mode 100644 index 0000000..f43e5db --- /dev/null +++ b/1.5-Kernel-Panic:VFS-無法掛載-root-fs.md @@ -0,0 +1,53 @@ +> 第1章 系統維護 · 來源:Ubuntu 知識庫 + +# 簡介 + +當核心(Kernel)升級不完整或映像檔損壞時,開機會出現 `Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block` 而無法掛載根檔案系統。本文記錄修復損壞套件、移除問題核心並重新安裝正常核心的步驟。 + +> 需在可開機的環境(例如選擇舊版核心開機,或進入救援模式)下執行以下指令。 + +# 1. 修復損壞的 Kernel + +修復先前安裝中斷、相依未滿足的套件。 + +```bash +sudo apt -f install +``` + +# 2. 列出所有 Kernel + +列出系統中已安裝的核心映像。 + +```bash +dpkg --list | grep linux-image +``` + +# 3. 移除低版本到無法移除 + +逐一移除有問題的舊版核心(將 `x.xx.x-xxx` 換成實際版本號),直到無法再移除為止。 + +```bash +sudo apt purge -y linux-image-x.xx.x-xxx-generic +``` + +# 4. 更新 GRUB 2 + +重新產生開機選單。 + +```bash +sudo update-grub2 +``` + +# 5. 更新 Kernel 到現在的版本 + +更新套件並重新安裝最新核心。 + +```bash +sudo apt update && sudo apt upgrade -y +``` + +# 6. 試著重啟看看是否正常 + +```bash +sudo reboot +``` diff --git a/1.6-常用工具.md b/1.6-常用工具.md new file mode 100644 index 0000000..96c4d42 --- /dev/null +++ b/1.6-常用工具.md @@ -0,0 +1,35 @@ +> 第1章 系統維護 · 來源:Ubuntu 知識庫 + +# [Node JS](https://gitea.jsc.idv.tw/knowledges/Ubuntu/wiki/Tool%EF%BC%9ANode-JS) + +# Claude Code CLI + +```bash +curl -fsSL https://claude.ai/install.sh | bash +``` + +```bash +echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc +``` + +# ccstatusline:Claude Code CLI 狀態列 + +```bash +apt install -y libatomic1 && npm config set strict-ssl false && npx -y ccstatusline@latest +``` + +# Codex CLI + +```bash +curl -fsSL https://chatgpt.com/codex/install.sh | sh +``` + +# herdr:AI Agent 管理 + +```bash +curl -fsSL https://herdr.dev/install.sh | sh +``` + +```bash +herdr integration install claude && herdr integration install codex +``` diff --git a/1.7-使用舊的右鍵選項.md b/1.7-使用舊的右鍵選項.md new file mode 100644 index 0000000..94c7737 --- /dev/null +++ b/1.7-使用舊的右鍵選項.md @@ -0,0 +1,5 @@ +> 第1章 系統維護 · 來源:Windows 知識庫 + +```powershell +reg add “HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32” /f /ve +``` diff --git a/2.1-netplan.md b/2.1-netplan.md new file mode 100644 index 0000000..3237ef0 --- /dev/null +++ b/2.1-netplan.md @@ -0,0 +1,54 @@ +> 第2章 網路與儲存 · 來源:Ubuntu 知識庫 + +# 簡介 + +netplan 是 Ubuntu 的網路設定工具,以 YAML 描述網路介面。本文記錄多網卡環境下,透過路由權重(`metric`)控制預設對外流量走哪張網卡的設定範例。`metric` 數值越小優先權越高。 + +設定檔通常位於 `/etc/netplan/`,修改後以 `netplan apply` 套用。 + +# 多網路權重設定 + +## 雙 DHCP + +兩張網卡都使用 DHCP,透過 `route-metric` 讓 `eth1`(100)優先於 `eth0`(200)作為對外路由。 + +```yaml +network: + version: 2 + ethernets: + eth0: + dhcp4: true + dhcp4-overrides: + route-metric: 200 + eth1: + dhcp4: true + dhcp4-overrides: + route-metric: 100 +``` + +## 靜態 + 動態 + +`ens18` 使用靜態 IP(metric 200),`ens19` 使用 DHCP(metric 100),對外流量優先走 metric 較小的 `ens19`。 + +```yaml +network: + version: 2 + ethernets: + ens18: + addresses: + - "172.25.43.200/20" + nameservers: + addresses: + - 168.95.1.1 + - 8.8.8.8 + search: [] + routes: + - to: "0.0.0.0/0" + via: "172.25.32.1" + metric: 200 + ens19: + dhcp4: true + routes: + - to: "0.0.0.0/0" + metric: 100 +``` diff --git a/2.2-53-埠被占用.md b/2.2-53-埠被占用.md new file mode 100644 index 0000000..d8363e9 --- /dev/null +++ b/2.2-53-埠被占用.md @@ -0,0 +1,45 @@ +> 第2章 網路與儲存 · 來源:Ubuntu 知識庫 + +# 簡介 + +Ubuntu 內建的 `systemd-resolved` 會在本機 `127.0.0.53:53` 啟動 DNS stub listener,導致要自行架設 DNS 服務(如 dnsmasq、Pi-hole)時 53 埠被佔用而無法啟動。本文記錄關閉 stub listener、釋放 53 埠的步驟。 + +# 1. 取消註解 DNSStubListener 並設定為 no + +編輯 systemd-resolved 設定檔。 + +```bash +sudo nano /etc/systemd/resolved.conf +``` + +將 `DNSStubListener` 取消註解並設為 `no`。 + +``` +[Resolve] +#DNS= +#FallbackDNS= +#Domains= +#LLMNR=no +#MulticastDNS=no +#DNSSEC=no +#DNSOverTLS=no +#Cache=yes +DNSStubListener=no +#ReadEtcHosts=yes +``` + +# 2. 重新建立捷徑 + +將 `/etc/resolv.conf` 指向 systemd-resolved 實際產生的設定檔。 + +```bash +sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf +``` + +# 3. 重新啟動系統服務 + +讓設定生效,53 埠即釋出。 + +```bash +sudo systemctl restart systemd-resolved +``` diff --git a/2.3-掛載-SMB.md b/2.3-掛載-SMB.md new file mode 100644 index 0000000..30da905 --- /dev/null +++ b/2.3-掛載-SMB.md @@ -0,0 +1,69 @@ +> 第2章 網路與儲存 · 來源:Proxmox VE 知識庫 + +# 1. 安裝 CIFS 工具 + +```bash +apt update && apt install -y cifs-utils +``` + +# 2. 建立 SMB 驗證檔 + +```bash +nano /root/.smbcredentials +``` + +(內容如下) + +``` +username=SMB帳號 +password=SMB密碼 +domain=WORKGROUP +``` + +設定權限 + +```bash +chmod 600 /root/.smbcredentials +``` + +# 3. 掛載 SMB 資料夾 + +```bash +nano /etc/fstab +``` + +(加入以下內容) + +``` +///emby /mnt/ds918/emby cifs credentials=/root/.smbcredentials,uid=100000,gid=100000 0 0 +``` + +uid=100000,gid=100000:對 unprivileged LXC container 很重要,這樣權限會對應到 container 內的 root 使用者(id 100000) + +若是 privileged container,可用 uid=0,gid=0 + +```bash +nano /etc/pve/lxc/.conf +``` + +(加入以下內容) + +``` +mp0: /mnt/ds918/emby,mp=/emby +``` + +# 4. 建立掛載的資料夾 + +```bash +mkdir -p /mnt/ds918/emby +``` + +# 5. 重新掛載資料夾 + +```bash +systemctl daemon-reload +``` + +```bash +mount -a +``` diff --git a/2.4-停用-SMB-服務.md b/2.4-停用-SMB-服務.md new file mode 100644 index 0000000..5a54750 --- /dev/null +++ b/2.4-停用-SMB-服務.md @@ -0,0 +1,19 @@ +> 第2章 網路與儲存 · 來源:Windows 知識庫 + +# 停用 SMB1 功能 + +```powershell +Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol +``` + +# 停用開機啟動 + +```powershell +Set-Service -Name LanmanServer -StartupType Disabled +``` + +# 立即停止服務 + +```powershell +Stop-Service -Name LanmanServer -Force +``` diff --git a/2.5-TGT.md b/2.5-TGT.md new file mode 100644 index 0000000..c7b6d83 --- /dev/null +++ b/2.5-TGT.md @@ -0,0 +1,46 @@ +> 第2章 網路與儲存 · 來源:Debian 知識庫 + +如果使用 PVE 的 CT,版本需要選擇 12.X + +# 安裝相關套件 + +```bash +apt update && apt install -y tgt lvm2 +``` + +# 啟動 TGT 服務 + +```bash +systemctl enable tgt && systemctl start tgt +``` + +# 建立 LVM 虛擬磁碟 + +```bash +dd if=/dev/zero of=/root/target.img bs=1G count=0 seek=512 +``` + +- of:位置 +- bs:單位 +- count:? +- seek:數量,範例為 512G (bs * seek) + +# 設定 TGT 服務到 LVM 虛擬磁碟 + +```bash +nano /etc/tgt/conf.d/target.conf +``` + +內容如下 + +```xml + + backing-store /root/target.img + +``` + +# 重啟 TGT 服務 + +```bash +systemctl restart tgt && tgt-admin --show +``` diff --git a/2.6-OpenSSH.md b/2.6-OpenSSH.md new file mode 100644 index 0000000..033754d --- /dev/null +++ b/2.6-OpenSSH.md @@ -0,0 +1,7 @@ +> 第2章 網路與儲存 · 來源:Windows 知識庫 + +# 將 OpenSSH 的預設工具改為 Powershell + +```powershell +New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\bin\bash.exe" -PropertyType String -Force +``` diff --git a/2.7-OpenWrt.md b/2.7-OpenWrt.md new file mode 100644 index 0000000..4c70baf --- /dev/null +++ b/2.7-OpenWrt.md @@ -0,0 +1,43 @@ +> 第2章 網路與儲存 · 來源:Proxmox VE 知識庫 + +# 1. 下載映像檔壓縮檔 + +```bash +wget https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/openwrt-23.05.3-x86-64-generic-ext4-combined.img.gz +``` + +# 2. 解壓縮映像檔 + +```bash +gzip -d openwrt-23.05.3-x86-64-generic-ext4-combined.img.gz +``` + +# 3. 將映像檔移到 ISO + +```bash +cp openwrt-23.05.3-x86-64-generic-ext4-combined.img /var/lib/vz/template/iso +``` + +# 4. 建立無硬碟的虛擬機,紀錄虛擬機編號 +# 5. 將映像檔指派到虛擬機 + +```bash +qm disk import 201 /var/lib/vz/template/iso/openwrt-23.05.3-x86-64-generic-ext4-combined.img local-lvm +``` + +# 6. 虛擬機選項: 開機順序全部取消 +# 7. 進入虛擬機,修改網路 + +```bash +vi /etc/config/network +``` + +```bash +service network restart +``` + +# 8. 嘗試連線OpenWRT + +Username: root + +Password: diff --git a/2.8-DiskStation-Manager.md b/2.8-DiskStation-Manager.md new file mode 100644 index 0000000..29bf38b --- /dev/null +++ b/2.8-DiskStation-Manager.md @@ -0,0 +1,95 @@ +> 第2章 網路與儲存 · 來源:Proxmox VE 知識庫 + +# 1. 下載引導檔 + +從 [Github](https://github.com/RROrg/rr) 的 [Release](https://github.com/RROrg/rr/releases/tag/25.6.5) 下載引導檔 + +```bash +wget https://github.com/RROrg/rr/releases/download/25.6.5/rr-25.6.5.img.zip +``` + +# 2. 解壓縮檔案 + +解壓縮檔案並移動到 PVE 的 ISO 資料夾 + +```bash +unzip rr-25.6.5.img.zip && mv rr.img /var/lib/vz/template/iso/rr-25.6.5.img +``` + +# 3. 建立虛擬機 + +3.1. 一般設定,指定 VM ID 並記住,之後加入引導映像檔時需要指定 + +![1.png](Images/1.png) + +3.2. 作業系統設定,不要使用任何媒體,之後使用 RR 映像檔,引導開機 + +![2.png](Images/2.png) + +3.3. 系統設定 + +![3.png](Images/3.png) + +3.4. 磁碟設定,加入三個相同規格的虛擬磁碟,之後用來建立 RAID 的磁碟集區 + +![4.png](Images/4.png) + +3.5. CPU 設定,選擇 host 取得最好的虛擬核心效能,啟用 NUMA 讓 DSM 可以使用 Container Manager + +![5.png](Images/5.png) + +3.6. 記憶體設定,先設定為 4G 安裝完成後再依照宿主機的資源設定 + +![6.png](Images/6.png) + +3.7. 網路設定,選擇 VirtIO 或 Intel E1000 的效能最好 + +![7.png](Images/7.png) + +# 4. 加入 RR 引導檔 + +```bash +qm importdisk 100 /var/lib/vz/template/iso/rr-25.6.5.img local-lvm +``` + +# 5. 將 RR 引導檔改為 SATA + +![8.png](Images/8.png) + +# 6. 將 RR 引導檔改為第一開機順位 + +![9.png](Images/9.png) + +# 7. 設定引導檔 + +![10.png](Images/10.png) + +(載入完成) + +![11.png](Images/11.png) + +從網頁輸入引導檔顯示的網址(http://192.168.30.100:7681),進入引導設定介面 + +![12.png](Images/12.png) + +# 8. 設定引導的主機型號 + +![13.png](Images/13.png) + +# 9. 設定引導的系統版本 + +![14.png](Images/14.png) + +![15.png](Images/15.png) + +# 10. 編譯引導 + +![16.png](Images/16.png) + +# 11. 啟動引導 + +![17.png](Images/17.png) + +啟動引導,待核心載入完成,即可透過連結進入 DSM 設定介面(http://192.168.30.100:5000) + +![18.png](Images/18.png) diff --git a/3.1-套件更新設定.md b/3.1-套件更新設定.md new file mode 100644 index 0000000..02c85d3 --- /dev/null +++ b/3.1-套件更新設定.md @@ -0,0 +1,33 @@ +> 第3章 虛擬化 · 來源:Proxmox VE 知識庫 + +# 更換 Debian 官方套件鏡像 + +```bash +nano /etc/apt/sources.list +``` + +內容如下 + +``` +deb http://ftp.tw.debian.org/debian bookworm main contrib non-free non-free-firmware +deb http://ftp.tw.debian.org/debian bookworm-updates main contrib non-free non-free-firmware +deb http://security.debian.org/ bookworm-security main contrib non-free non-free-firmware +``` + +# Proxmox VE 官方套件來源 + +```bash +rm /etc/apt/sources.list.d/* && nano /etc/apt/sources.list.d/pve-no-subscription.list +``` + +內容如下 + +``` +deb http://download.proxmox.com/debian/pve bookworm pve-no-subscription +``` + +# 清除快取、更新套件清單 + +```bash +apt clean && apt update +``` diff --git a/3.2-硬碟直通.md b/3.2-硬碟直通.md new file mode 100644 index 0000000..58d1998 --- /dev/null +++ b/3.2-硬碟直通.md @@ -0,0 +1,20 @@ +> 第3章 虛擬化 · 來源:Proxmox VE 知識庫 + +# 列出所有硬碟 + +```bash +ls -l /dev/disk/by-id +``` + +(輸出) + +``` +lrwxrwxrwx 1 root root 9 Sep 12 23:04 ata-CT2000BX500SSD1_2221E63542A2 -> ../../sda +... +``` + +# 將硬碟直通給虛擬機 + +```bash +qm set 253 --sata2 /dev/disk/by-id/ata-CT2000BX500SSD1_2221E63542A2 +``` diff --git a/3.3-將PCIe直通給PVE的虛擬機.md b/3.3-將PCIe直通給PVE的虛擬機.md new file mode 100644 index 0000000..443366a --- /dev/null +++ b/3.3-將PCIe直通給PVE的虛擬機.md @@ -0,0 +1,122 @@ +> 第3章 虛擬化 · 來源:Ubuntu 知識庫 + +# 簡介 + +PCIe 直通(Passthrough)可讓 PVE 上的虛擬機直接獨佔某個 PCIe 裝置(例如顯示卡、Thunderbolt 控制器)。重點是先在主機啟用 IOMMU,再以 `vfio-pci` 驅動接管裝置、阻止宿主機使用它,最後將裝置指派給虛擬機。本文以 Thunderbolt 控制器為例。 + +# Step 1. 修改引導設定檔 + +啟用 IOMMU 需在核心開機參數加入對應設定。 + +```bash +nano /etc/default/grub +``` + +找到 `GRUB_CMDLINE_LINUX_DEFAULT` 行,依據 CPU 類型加入參數: + +- Intel CPU:`intel_iommu=on iommu=pt` +- AMD CPU:`amd_iommu=on iommu=pt` + +(Intel 範例) + +``` +GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt" +``` + +更新 GRUB 引導並重啟主機。 + +```bash +update-grub && reboot +``` + +重啟後執行下列指令驗證,若看到 `IOMMU enabled` 代表啟用成功。 + +```bash +dmesg | grep -e DMAR -e IOMMU +``` + +# Step 2. 載入 VFIO 核心模組 + +讓系統開機時自動載入 VFIO 相關模組。 + +```bash +nano /etc/modules +``` + +在檔案末尾加上以下四行: + +``` +vfio +vfio_iommu_type1 +vfio_pci +vfio_virqfd +``` + +# Step 3. 尋找控制器 ID (以 Thunderbolt 為例) + +找出要直通裝置的 PCI 位址與硬體 ID。 + +```bash +lspci -nnk | grep -i thunderbolt +``` + +- PCI 位址:例如 `00:0d.0` +- 硬體 ID:例如 `8086:9a1b` + +# Step 4. 阻斷宿主機驅動 + +為了防止 PVE 宿主機搶先佔用控制器,必須強制它改用 `vfio-pci` 驅動。 + +```bash +nano /etc/modprobe.d/vfio.conf +``` + +寫入以下內容(`ids=` 後填入 Step 3 取得的硬體 ID): + +```bash +softdep thunderbolt pre: vfio-pci + +options vfio-pci ids=8086:9a1b,8086:9a1d disable_vga=1 +``` + +更新 initramfs 核心映像並重啟主機。 + +```bash +update-initramfs -u -k all && reboot +``` + +重啟後執行下列指令驗證,若看到 `Kernel driver in use: vfio-pci` 代表隔離成功。 + +```bash +lspci -nnk -s 00:0d.0 +``` + +# Step 5. 將裝置新增至虛擬機 + +在 PVE 介面為虛擬機加入 PCI 裝置: + +- 位置:硬體 > 新增 > PCI 裝置 +- 原始裝置:選取控制器位址 +- [v] All Functions +- [v] ROM-Bar +- [v] PCI-Express + +# 補充:PVE 可能使用 systemd-boot 而非 GRUB + +較新的 PVE 安裝可能以 systemd-boot 開機,此時 Step 1 改 GRUB 不會生效,需改設定核心命令列。 + +```bash +nano /etc/kernel/cmdline +``` + +檢查檔案內是否有以下內容,如果沒有,則直接加在原本內容的尾端。 + +``` +intel_iommu=on iommu=pt +``` + +讓核心參數生效。 + +```bash +proxmox-boot-tool refresh +``` diff --git a/3.4-相關參考紀錄.md b/3.4-相關參考紀錄.md new file mode 100644 index 0000000..4583aea --- /dev/null +++ b/3.4-相關參考紀錄.md @@ -0,0 +1,10 @@ +> 第3章 虛擬化 · 來源:Proxmox VE 知識庫 + +- [Proxmox VE 初始化硬碟分割區與配置ZFS儲存區(Raidz)](https://www.albert-yu.com/blog/proxmox-ve-%E5%88%9D%E5%A7%8B%E5%8C%96%E7%A1%AC%E7%A2%9F%E5%88%86%E5%89%B2%E5%8D%80%E8%88%87%E9%85%8D%E7%BD%AEzfs%E5%84%B2%E5%AD%98%E5%8D%80raidz/) +- [Pimox - Proxmox V7 for the Raspberry Pi](https://github.com/pimox/pimox7) +- [Installing Mikrotik RouterOS on Proxmox VE easily](https://www.apalrd.net/posts/2023/tip_routeros/) +- [Linux VM Templates in Proxmox on EASY MODE using Prebuilt Cloud Init Images!](https://www.apalrd.net/posts/2023/pve_cloud/) +- [Proxmox PVE上安裝Openwrt的幾個重點:VM or LXC?哪個鏡像?網卡直通?一鍵安裝?](https://upsangel.com/openwrt/how-to-install-openwrt-on-proxmox/) +- [Deploy a DSM VM and Manage Disks Dynamically Using a Script in Proxmox VE](https://kingtam.win/archives/rr-dsm.html) +- [2024年PVE8最新安装使用指南](https://post.smzdm.com/p/al82z7ee/) +- [Proxmox VE 如何設定直通硬碟【虛擬機Server2016示範教學】](https://eheima.com/5722/pve-qmset-sata#:~:text=%E7%A4%BA%E7%AF%84%E5%A6%82%E4%B8%8B%E5%9C%96%EF%BC%8C%20%E8%80%81%E9%BB%91%20%E5%B0%87%E9%80%99%E6%AC%A1%E6%BA%96%E5%82%99%E7%9A%841TB%E7%A1%AC%E7%A2%9F%E7%9B%B4%E9%80%9A%E7%B5%A6Server2016%E8%99%9B%E6%93%AC%E6%A9%9FVM%20ID%E7%82%BA100%EF%BC%8C%E4%B8%A6%E6%8E%9B%E5%9C%A8%E8%99%9B%E6%93%AC%E6%A9%9Fsata2%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%8C%20%E4%B8%A6%E5%B0%87%E7%AC%AC%E4%BA%8C%E6%AD%A5%E9%A9%9F%E6%9F%A5%E8%A9%A2%E5%87%BA%E4%BE%86%E7%9A%84%E7%A1%AC%E7%A2%9FID%E8%B2%BC%E5%9C%A8%E6%8C%87%E4%BB%A4%E7%AF%84%E6%9C%AC%E7%9A%84%E6%9C%80%E5%BE%8C%EF%BC%8C,%E7%B5%84%E5%90%88%E5%BE%8C%E6%88%91%E8%A6%81%E7%9B%B4%E9%80%9A%E7%9A%84%E6%8C%87%E4%BB%A4%E5%B0%B1%E6%98%AF%EF%BC%9A%E3%80%8Cqm%20set%20100%20--sata1%20%2Fdev%2Fdisk%2Fby-id%2Fata-ST1000DM003-1CH162_S1D8F613%E3%80%8D) diff --git a/3.5-解決Windows安裝WSL後死機的問題.md b/3.5-解決Windows安裝WSL後死機的問題.md new file mode 100644 index 0000000..5a79a33 --- /dev/null +++ b/3.5-解決Windows安裝WSL後死機的問題.md @@ -0,0 +1,7 @@ +> 第3章 虛擬化 · 來源:Proxmox VE 知識庫 + +# 在設定檔加上以下內容 + +``` +args: -cpu host,kvm=on +``` diff --git a/3.6-Hyper-V.md b/3.6-Hyper-V.md new file mode 100644 index 0000000..70452b4 --- /dev/null +++ b/3.6-Hyper-V.md @@ -0,0 +1,39 @@ +> 第3章 虛擬化 · 來源:Windows 知識庫 + +### 啟用 KVM + +```powershell +Set-VMProcessor -VMName "" -ExposeVirtualizationExtensions $true +``` + +### 偽裝 MAC 地址 for PVE + +因為虛擬機共用同一張網路卡,為了防止流量進到 PVE 後,不再往虛擬機送,因此需要偽裝 MAC 地址 + +```powershell +Get-VMNetworkAdapter -VMName "" | Set-VMNetworkAdapter -MacAddressSpoofing On +``` + +# 限制虛擬硬碟的讀寫速度(IOPS) + +一個 IOPS 為 8KB / s,如果要限制虛擬硬碟只能使用 100MB / s 的速度,則 IOPS 應該設定為 12800 (100 * 1024 / 8) + +# 加入具 NAT 功能的虛擬交換器 + +加入新的虛擬交換器 + +```powershell +New-VMSwitch -SwitchName "NAT Switch" -SwitchType Internal +``` + +設定交換器的 IP + +```powershell +New-NetIPAddress -IPAddress 192.168.30.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NAT Switch)" +``` + +設定 NAT + +```powershell +New-NetNat -Name "NAT Network" -InternalIPInterfaceAddressPrefix 192.168.30.0/24 +``` diff --git a/3.7-WSL:從零開始.md b/3.7-WSL:從零開始.md new file mode 100644 index 0000000..cf8d5df --- /dev/null +++ b/3.7-WSL:從零開始.md @@ -0,0 +1,13 @@ +> 第3章 虛擬化 · 來源:Windows 知識庫 + +# 安裝必要元件 (含 ubuntu) + +```powershell +wsl --install +``` + +# 更新 (Windows 元件安裝完成,可以直接更新) + +```powershell +wsl --update +``` diff --git a/3.8-WSL:安裝-Ubuntu-26.04.md b/3.8-WSL:安裝-Ubuntu-26.04.md new file mode 100644 index 0000000..0a5d3ef --- /dev/null +++ b/3.8-WSL:安裝-Ubuntu-26.04.md @@ -0,0 +1,13 @@ +> 第3章 虛擬化 · 來源:Windows 知識庫 + +# 停止 WSL 服務 + +```powershell +wsl --shutdown +``` + +# 安裝 Ubuntu 26.04 完成直接啟動 + +```powershell +wsl --install Ubuntu-26.04 +``` diff --git a/3.9-避免虛擬化啟動失敗.md b/3.9-避免虛擬化啟動失敗.md new file mode 100644 index 0000000..852aeee --- /dev/null +++ b/3.9-避免虛擬化啟動失敗.md @@ -0,0 +1,16 @@ +> 第3章 虛擬化 · 來源:Raspberry Pi 知識庫 + +```bash +sudo nano /boot/cmdline.txt +``` + +(修改內容) + +```bash +cgroup_memory=1 +cgroup_enable=memory +``` + +```bash +sudo reboot +``` diff --git a/4.1-Docker(Ubuntu).md b/4.1-Docker(Ubuntu).md new file mode 100644 index 0000000..e97ceba --- /dev/null +++ b/4.1-Docker(Ubuntu).md @@ -0,0 +1,53 @@ +> 第4章 容器與編排 · 來源:Ubuntu 知識庫 + +# 簡介 + +Docker 是容器化平台,用於封裝與執行應用程式。本文記錄在 Ubuntu 上安裝 Docker 與 Docker Compose 的步驟,以及在 PVE 容器(CT)中常見的問題排解。 + +# 安裝 Docker + +安裝 Docker 引擎與 Docker Compose v2 外掛。 + +```bash +apt update && apt install -y docker.io docker-compose-v2 +``` + +# 將 Docker 權限賦予目前的使用者 + +將目前使用者加入 docker 群組,之後即可免 sudo 操作 Docker。 + +```bash +usermod -aG docker $USER +``` + +不重新登入即套用新群組(僅對當前 shell 生效)。 + +```bash +newgrp docker +``` + +# 常見問題 + +## 問題一:PVE 的 CT 安裝後無法啟動容器 + +(2015/12/05) 在 PVE 的 LXC 容器中啟動 Docker 容器時出現以下錯誤: + +``` +Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: open sysctl net.ipv4.ip_unprivileged_port_start file: reopen fd 8: permission denied +``` + +### 解決方法 + +在 PVE 宿主機上編輯該 CT 的設定檔,加上相容設定。 + +``` +nano /etc/pve/lxc/(CT ID).conf +``` + +加上以下內容後重啟該 CT: + +``` +lxc.apparmor.profile: unconfined +lxc.mount.entry: /dev/null sys/module/apparmor/parameters/enabled none bind 0 0 +lxc.mount.entry: /proc/sys/net/ipv4/ip_unprivileged_port_start proc/sys/net/ipv4/ip_unprivileged_port_start none bind 0 0 +``` diff --git a/4.2-Docker(Raspberry-Pi).md b/4.2-Docker(Raspberry-Pi).md new file mode 100644 index 0000000..2cd2fcc --- /dev/null +++ b/4.2-Docker(Raspberry-Pi).md @@ -0,0 +1,21 @@ +> 第4章 容器與編排 · 來源:Raspberry Pi 知識庫 + +# 1. 安裝 docker 服務 + +```bash +curl -fsSL https://get.docker.com -o get-docker.sh +``` + +```bash +sudo sh get-docker.sh +``` + +# 2. 將使用者加入 docker 權限與群組,省去 sudo + +```bash +sudo usermod -aG docker $USER +``` + +```bash +newgrp docker +``` diff --git a/4.3-K3s.md b/4.3-K3s.md new file mode 100644 index 0000000..20ed5ae --- /dev/null +++ b/4.3-K3s.md @@ -0,0 +1,9 @@ +> 第4章 容器與編排 · 來源:Raspberry Pi 知識庫 + +```bash +sudo curl -sfL https://get.k3s.io | sh - +``` + +```bash +sudo systemctl status k3s +``` diff --git a/4.4-k3d.md b/4.4-k3d.md new file mode 100644 index 0000000..dbf1615 --- /dev/null +++ b/4.4-k3d.md @@ -0,0 +1,41 @@ +> 第4章 容器與編排 · 來源:Ubuntu 知識庫 + +# 簡介 + +k3d 可在 Docker 中執行輕量級 Kubernetes 發行版 k3s,方便在單機快速建立測試用叢集。本文記錄在 Ubuntu 上安裝 kubectl 與 k3d,並建立叢集的步驟(需先安裝 Docker)。 + +# 安裝 kubectl & k3d + +一次完成:安裝 curl、下載最新版 kubectl 並設為可執行檔、再以官方腳本安裝 k3d。 + +```bash +apt update \ +&& apt install -y curl \ +&& wget "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -O /usr/local/bin/kubectl \ +&& chmod +x /usr/local/bin/kubectl \ +&& curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash +``` + +# 建立 1 個伺服器 2 個代理 + +建立名為 `ct` 的叢集(1 個 server、2 個 agent),對外開放 80/443,啟用使用者命名空間相容設定,掛載 Docker socket 並建立本地映像登錄。 + +```bash +k3d cluster create ct \ +--servers 1 \ +--agents 2 \ +--port 80:80@loadbalancer \ +--port 443:443@loadbalancer \ +--k3s-arg '--kubelet-arg=feature-gates=KubeletInUserNamespace=true@server:*' \ +--k3s-arg '--kubelet-arg=feature-gates=KubeletInUserNamespace=true@agent:*' \ +--volume /var/run/docker.sock:/var/run/docker.sock \ +--registry-create k3d-ct-registry:5000 +``` + +# 驗證節點 + +確認叢集節點皆已就緒。 + +```bash +kubectl get nodes +``` diff --git a/4.5-Traefik.md b/4.5-Traefik.md new file mode 100644 index 0000000..810b1c4 --- /dev/null +++ b/4.5-Traefik.md @@ -0,0 +1,230 @@ +> 第4章 容器與編排 · 來源:Ubuntu 知識庫 + +# 簡介 + +Traefik 是一套現代化的反向代理與負載平衡器,常用於統一管理各服務的對外路由與 TLS。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署 Traefik 的步驟,並附上範例設定檔。 + +# 下載 Traefik 壓縮檔 + +從官方下載指定版本的壓縮檔。 + +```bash +wget https://github.com/traefik/traefik/releases/download/v3.7.4/traefik_v3.7.4_linux_amd64.tar.gz +``` + +# 解壓縮 + +只解出 traefik 執行檔並放到 `/usr/local/bin/`。 + +```bash +tar zxvf traefik_v3.7.4_linux_amd64.tar.gz -C /usr/local/bin/ traefik +``` + +# 建立 Traefik 服務 + +以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。 + +```bash +nano /etc/systemd/system/traefik.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=Traefik Proxy + +[Service] +Environment=HOME=/root +Type=simple +WorkingDirectory=/root +ExecStart=/usr/local/bin/traefik --configFile=traefik.toml +Restart=always +User=root + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。 + +```bash +systemctl daemon-reload && systemctl enable traefik.service && systemctl start traefik.service && systemctl status traefik.service +``` + +# 停止服務 + +停止、取消開機啟動並移除服務設定檔。 + +```bash +systemctl stop traefik.service && systemctl disable traefik.service && rm /etc/systemd/system/traefik.service +``` + +# 範例設定檔 + +建立設定檔,路徑須與服務檔 `--configFile` 指定的位置一致。 + +```bash +nano /root/traefik.toml +``` + +```toml +################################################################ +# +# Configuration sample for Traefik v2. +# +# For Traefik v1: https://github.com/traefik/traefik/blob/v1.7/traefik.sample.toml +# +################################################################ + +################################################################ +# Global configuration +################################################################ +[global] + checkNewVersion = true + sendAnonymousUsage = true + +################################################################ +# Entrypoints configuration +################################################################ + +# Entrypoints definition +# +# Optional +# Default: +[entryPoints] + [entryPoints.web] + address = ":80" + + [entryPoints.websecure] + address = ":443" + +################################################################ +# Traefik logs configuration +################################################################ + +# Traefik logs +# Enabled by default and log to stdout +# +# Optional +# +[log] + + # Log level + # + # Optional + # Default: "ERROR" + # + # level = "DEBUG" + + # Sets the filepath for the traefik log. If not specified, stdout will be used. + # Intermediate directories are created if necessary. + # + # Optional + # Default: os.Stdout + # + # filePath = "log/traefik.log" + + # Format is either "json" or "common". + # + # Optional + # Default: "common" + # + # format = "json" + +################################################################ +# Access logs configuration +################################################################ + +# Enable access logs +# By default it will write to stdout and produce logs in the textual +# Common Log Format (CLF), extended with additional fields. +# +# Optional +# +# [accessLog] + + # Sets the file path for the access log. If not specified, stdout will be used. + # Intermediate directories are created if necessary. + # + # Optional + # Default: os.Stdout + # + # filePath = "/path/to/log/log.txt" + + # Format is either "json", "common", or "genericCLF". + # - "common": Traefik's extended CLF format (default) + # - "genericCLF": Standard CLF format compatible with standard log analyzers + # - "json": JSON format for structured logging + # + # Optional + # Default: "common" + # + # format = "json" + # format = "genericCLF" + +################################################################ +# API and dashboard configuration +################################################################ + +# Enable API and dashboard +[api] + + # Enable the API in insecure mode + # + # Optional + # Default: false + # + # insecure = true + + # Enabled Dashboard + # + # Optional + # Default: true + # + # dashboard = false + +################################################################ +# Ping configuration +################################################################ + +# Enable ping +[ping] + + # Name of the related entry point + # + # Optional + # Default: "traefik" + # + # entryPoint = "traefik" + +################################################################ +# Docker configuration backend +################################################################ + +# Enable Docker configuration backend +[providers.docker] + + # Docker server endpoint. Can be a tcp or a unix socket endpoint. + # + # Required + # Default: "unix:///var/run/docker.sock" + # + # endpoint = "tcp://10.10.10.10:2375" + + # Default host rule. + # + # Optional + # Default: "Host(`{{ normalize .Name }}`)" + # + # defaultRule = "Host(`{{ normalize .Name }}.docker.localhost`)" + + # Expose containers by default in traefik + # + # Optional + # Default: true + # + # exposedByDefault = false +``` diff --git a/5.1-PostgreSQL.md b/5.1-PostgreSQL.md new file mode 100644 index 0000000..eaa34dd --- /dev/null +++ b/5.1-PostgreSQL.md @@ -0,0 +1,36 @@ +> 第5章 資料庫與搜尋 · 來源:Ubuntu 知識庫 + +# 簡介 + +PostgreSQL 是常用的開源關聯式資料庫。本文記錄在 Ubuntu 上安裝 PostgreSQL,並開放特定主機與使用者外部連線的步驟。 + +# 安裝 PostgreSQL + +```bash +apt update && apt install -y postgresql +``` + +# 允許外部連線 + +編輯用戶端認證設定檔 `pg_hba.conf`(路徑中的 `17` 為 PostgreSQL 主版本號,請依實際版本調整)。 + +```bash +nano /etc/postgresql/17/main/pg_hba.conf +``` + +加入下列規則,允許來自 `192.168.230.221` 網段的 `gitea` 使用者,以 md5 密碼驗證存取 `gitea` 資料庫。 + +```ini +... +host gitea gitea 192.168.230.221/24 md5 +``` + +> 注意:另需確認 `postgresql.conf` 的 `listen_addresses` 已開放對應介面(例如設為 `'*'`),外部連線才會生效。 + +# 重啟服務 + +讓設定生效並檢視狀態。 + +```bash +systemctl restart postgresql && systemctl status postgresql +``` diff --git a/5.2-SQLServer.md b/5.2-SQLServer.md new file mode 100644 index 0000000..7a714f6 --- /dev/null +++ b/5.2-SQLServer.md @@ -0,0 +1,115 @@ +> 第5章 資料庫與搜尋 · 來源:Ubuntu 知識庫 + +# 簡介 + +本文記錄在 Ubuntu 上透過 Microsoft 官方套件庫安裝 SQL Server 2022 的步驟,包含基本設定(密碼、代理、定序),以及命令列工具 sqlcmd 的安裝。 + +# 安裝相關套件 + +加入套件庫過程需要 curl。 + +```bash +apt update && apt install -y curl +``` + +# 安裝加密簽證 + +下載並信任 Microsoft 的 GPG 金鑰,供 APT 驗證套件來源。 + +```bash +curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc +``` + +# 安裝套件列表 + +加入 SQL Server 2022 的套件庫(套件庫路徑使用 Ubuntu 22.04)。 + +```bash +curl -fsSL https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list | tee /etc/apt/sources.list.d/mssql-server-2022.list +``` + +# 安裝 SQL Server + +```bash +apt update && apt install -y mssql-server +``` + +# 安裝缺少的套件 + +若安裝過程缺少 libldap 相依套件,手動下載並安裝。 + +```bash +wget http://archive.ubuntu.com/ubuntu/pool/main/o/openldap/libldap-2.5-0_2.5.11+dfsg-1~exp1ubuntu3_amd64.deb && dpkg -i libldap-2.5-0_2.5.11+dfsg-1~exp1ubuntu3_amd64.deb +``` + +# 設定 SQL Server + +## 密碼 + +執行初始設定精靈,選擇版本並設定 SA 密碼。 + +```bash +/opt/mssql/bin/mssql-conf setup +``` + +## 代理 + +啟用 SQL Server Agent(排程作業)後重啟服務。 + +```bash +/opt/mssql/bin/mssql-conf set sqlagent.enabled true && systemctl restart mssql-server +``` + +## 定序 + +設定定序前須先停止服務。 + +```bash +systemctl stop mssql-server +``` + +設定定序。 + +```bash +/opt/mssql/bin/mssql-conf set-collation +``` + +* Chinese_Taiwan_Stroke_CI_AS:以筆劃排序,大小寫不區分 (Case Insensitive),重音符號區分 (Accent Sensitive),適合一般文字搜尋。 + +* Chinese_Taiwan_Stroke_CS_AS:以筆劃排序,大小寫區分 (Case Sensitive),重音符號區分,適合需要區分大小寫的場景。 + +設定完成後重新啟動服務。 + +```bash +systemctl start mssql-server +``` + +# 連接埠 1433 + +# 安裝 sqlcmd + +sqlcmd 是 SQL Server 的命令列查詢工具。 + +## 安裝 sqlcmd 加密簽證 + +```bash +curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc +``` + +## 安裝 sqlcmd 套件列表 + +```bash +curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list +``` + +## 安裝 sqlcmd + +```bash +apt update && apt install -y mssql-tools18 unixodbc-dev +``` + +將 sqlcmd 加入環境變數。 + +```bash +echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc && source ~/.bashrc +``` diff --git a/5.3-Redis.md b/5.3-Redis.md new file mode 100644 index 0000000..b4881ac --- /dev/null +++ b/5.3-Redis.md @@ -0,0 +1,49 @@ +> 第5章 資料庫與搜尋 · 來源:Ubuntu 知識庫 + +# 簡介 + +Redis 是高效能的記憶體式鍵值資料庫,常用於快取與訊息佇列。本文記錄在 Ubuntu 上透過官方 APT 套件庫安裝 Redis 的步驟。 + +# 安裝相依套件 + +加入套件庫過程需要這些工具。 + +```bash +apt update && apt install -y lsb-release curl gpg +``` + +# 安裝 Redis 簽章 + +下載官方 GPG 金鑰並轉換為 keyring,供 APT 驗證套件來源。 + +```bash +curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg +``` + +設定金鑰檔的讀取權限。 + +```bash +chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg +``` + +# 加入 Redis 套件庫 + +加入官方套件庫(`$(lsb_release -cs)` 會自動帶入目前 Ubuntu 版本代號)。 + +```bash +echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list +``` + +# 安裝 Redis + +```bash +apt install -y redis +``` + +# 啟動服務 + +設為開機自動啟動、啟動服務並檢視狀態。 + +```bash +systemctl enable redis-server && systemctl start redis-server && systemctl status redis-server +``` diff --git a/5.4-ElasticSearch.md b/5.4-ElasticSearch.md new file mode 100644 index 0000000..7a09653 --- /dev/null +++ b/5.4-ElasticSearch.md @@ -0,0 +1,257 @@ +> 第5章 資料庫與搜尋 · 來源:Ubuntu 知識庫 + +# 簡介 + +Elasticsearch 是分散式搜尋與分析引擎,Kibana 則是它的視覺化前端。本文記錄兩種在 Ubuntu 上部署兩者的方式:方法一使用官方壓縮檔手動安裝,方法二使用官方 APT 套件庫安裝。 + +--- + +# 方法一:使用壓縮檔安裝 + +## 下載 Elasticsearch + +```bash +wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz --no-check-certificate +``` + +## 驗證壓縮檔 + +下載官方提供的 SHA512 校驗檔。 + +```bash +wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz.sha512 --no-check-certificate +``` + +比對壓縮檔雜湊值,確認檔案完整未被竄改。 + +```bash +shasum -a 512 -c elasticsearch-8.16.0-linux-x86_64.tar.gz.sha512 +``` + +## 解壓縮 + +```bash +tar -xzf elasticsearch-8.16.0-linux-x86_64.tar.gz +``` + +## 設定 Elasticsearch + +先啟動一次服務,讓系統自動產生完整的預設設定檔。 + +```bash +elasticsearch +``` + +編輯設定檔。 + +```bash +nano elasticsearch-8.16.0/config/elasticsearch.yml +``` + +修改以下內容(開放各網路介面連線、停用 HTTPS 改走 HTTP): + +```yaml +# 在全部網路介面啟動服務 +network.host: 0.0.0.0 + +# 改走 http 協定 +xpack.security.http.ssl: + enabled: false + +# 允許所有介面的網路連線 +http.host: 0.0.0.0 + +# 允許所有介面的叢集連線 +transport.host: 0.0.0.0 +``` + +## Elasticsearch 常用指令 + +### 啟動服務 + +```bash +elasticsearch +``` + +### 關閉服務 + +以背景模式啟動並記錄 PID。 + +```bash +elasticsearch -d -p pid +``` + +依 PID 關閉服務。 + +```bash +pkill -F pid +``` + +### 重設 elastic 帳號密碼 + +```bash +elasticsearch-reset-password -i -u elastic +``` + +### 產生 Kibana 服務金鑰 + +供 Kibana 連線 Elasticsearch 使用。 + +```bash +elasticsearch-create-enrollment-token -s kibana +``` + +輸出範例: + +```bash +eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9 +``` + +## 下載 Kibana + +```bash +wget https://artifacts.elastic.co/downloads/kibana/kibana-8.16.0-linux-x86_64.tar.gz --no-check-certificate +``` + +## 驗證 Kibana 壓縮檔 + +```bash +wget https://artifacts.elastic.co/downloads/kibana/kibana-8.16.0-linux-x86_64.tar.gz.sha512 --no-check-certificate +``` + +```bash +shasum -a 512 -c kibana-8.16.0-linux-x86_64.tar.gz.sha512 +``` + +## 解壓縮 Kibana + +```bash +tar -xzf kibana-8.16.0-linux-x86_64.tar.gz +``` + +## 設定 Kibana + +```bash +sudo nano kibana-8.16.0/config/kibana.yml +``` + +調整以下內容(開放外部連線、指向 Elasticsearch 並填入前面產生的服務金鑰): + +```bash +# 在所有網路介面啟動服務 +server.host: "0.0.0.0" + +# 設定 elasticsearch 服務位置 +elasticsearch.hosts: ["http://0.0.0.0:9200"] + +# 設定 elasticsearch 存取金鑰 +elasticsearch.serviceAccountToken: "eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9" +``` + +## 啟動 Kibana + +```bash +kibana +``` + +--- + +# 方法二:使用 APT 套件庫安裝 + +## 安裝相依套件 + +```bash +sudo apt install -y apt-transport-https +``` + +## 加入套件庫並安裝 + +加入官方 8.x APT 套件庫。 + +```bash +echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list +``` + +更新套件清單並安裝 Elasticsearch 與 Kibana。 + +```bash +sudo apt update && sudo apt upgrade -y && sudo apt install -y elasticsearch kibana +``` + +## 建立 Elasticsearch 服務 + +建立 systemd 服務設定檔。 + +```bash +sudo nano /etc/systemd/system/elasticsearch.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=elasticsearch + +[Service] +Type=simple +User=shuochen +WorkingDirectory=/home/shuochen/elasticsearch-8.16.0 +ExecStart=/home/shuochen/elasticsearch-8.16.0/bin/elasticsearch +Restart=always + +[Install] +WantedBy=multi-user.target +``` + +## 啟動 Elasticsearch 服務 + +```bash +sudo systemctl daemon-reload +``` + +```bash +sudo systemctl enable elasticsearch +``` + +```bash +sudo systemctl start elasticsearch +``` + +## 建立 Kibana 服務 + +建立 systemd 服務設定檔。 + +```bash +sudo nano /etc/systemd/system/kibana.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=kibana + +[Service] +Type=simple +User=shuochen +WorkingDirectory=/home/shuochen/kibana-8.16.0 +ExecStart=/home/shuochen/kibana-8.16.0/bin/kibana --allow-root +Restart=always + +[Install] +WantedBy=multi-user.target +``` + +## 啟動 Kibana 服務 + +```bash +sudo systemctl daemon-reload +``` + +```bash +sudo systemctl enable kibana +``` + +```bash +sudo systemctl start kibana +``` diff --git a/6.1-Gitea.md b/6.1-Gitea.md new file mode 100644 index 0000000..774c8ca --- /dev/null +++ b/6.1-Gitea.md @@ -0,0 +1,180 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 簡介 + +Gitea 是一套輕量級、可自行架設的 Git 服務(功能類似 GitHub / GitLab)。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署 Gitea 的完整步驟。 + +# 安裝相依套件 + +Gitea 進行版本控制操作時需要系統已安裝 git。 + +```bash +apt update && apt install -y git +``` + +# 下載 Gitea + +從官方下載指定版本的二進位檔,放到 `/usr/local/bin/gitea`。以下提供兩個版本,擇一執行即可。 + +```bash +wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.25.3/gitea-1.25.3-linux-amd64 +``` + +```bash +wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.26.2/gitea-1.26.2-linux-amd64 +``` + +下載後將 gitea 設定為可執行檔。 + +```bash +chmod +x /usr/local/bin/gitea +``` + +# 新增 git 使用者 + +基於安全考量,Gitea 以專屬的 `git` 系統帳號執行,而非使用 root。 + +```bash +adduser \ + --system \ + --shell /bin/bash \ + --gecos 'Git Version Control' \ + --group \ + --disabled-password \ + --home /home/git \ + git +``` + +# 建立系統資料夾 + +分別建立存放自訂檔案、資料、日誌的目錄,以及設定檔目錄 `/etc/gitea`。 + +```bash +mkdir -p /var/lib/gitea/custom && mkdir -p /var/lib/gitea/data && mkdir -p /var/lib/gitea/log && mkdir /etc/gitea +``` + +將資料目錄的擁有者設為 git,並限制權限。 + +```bash +chown -R git:git /var/lib/gitea/ && chmod -R 750 /var/lib/gitea/ +``` + +設定檔目錄安裝完成後通常會調回唯讀,這裡先讓 git 群組可寫入以便初始化。 + +```bash +chown root:git /etc/gitea && chmod 770 /etc/gitea +``` + +# 設定工作目錄環境變數 + +告訴 Gitea 它的工作目錄位置。 + +```bash +echo 'export GITEA_WORK_DIR=/var/lib/gitea/' >> ~/.bashrc && source ~/.bashrc +``` + +# 建立 Gitea 服務 + +以 systemd 管理 Gitea,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。 + +```bash +nano /etc/systemd/system/gitea.service +``` + +服務檔內容如下(保留官方範例註解,可依需要取消註解): + +```ini +[Unit] +Description=Gitea (Git with a cup of tea) +After=network.target +### +# Don't forget to add the database service dependencies +### +# +#Wants=mysql.service +#After=mysql.service +# +#Wants=mariadb.service +#After=mariadb.service +# +#Wants=postgresql.service +#After=postgresql.service +# +#Wants=memcached.service +#After=memcached.service +# +#Wants=redis.service +#After=redis.service +# +### +# If using socket activation for main http/s +### +# +#After=gitea.main.socket +#Requires=gitea.main.socket +# +### +# (You can also provide gitea an http fallback and/or ssh socket too) +# +# An example of /etc/systemd/system/gitea.main.socket +### +## +## [Unit] +## Description=Gitea Web Socket +## PartOf=gitea.service +## +## [Socket] +## Service=gitea.service +## ListenStream= +## NoDelay=true +## +## [Install] +## WantedBy=sockets.target +## +### + +[Service] +# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that +# LimitNOFILE=524288:524288 +RestartSec=2s +Type=simple +User=git +Group=git +WorkingDirectory=/var/lib/gitea/ +# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file +# (manually creating /run/gitea doesn't work, because it would not persist across reboots) +#RuntimeDirectory=gitea +ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini +Restart=always +Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea +# If you install Git to directory prefix other than default PATH (which happens +# for example if you install other versions of Git side-to-side with +# distribution version), uncomment below line and add that prefix to PATH +# Don't forget to place git-lfs binary on the PATH below if you want to enable +# Git LFS support +#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin +# If you want to bind Gitea to a port below 1024, uncomment +# the two values below, or use socket activation to pass Gitea its ports as above +### +#CapabilityBoundingSet=CAP_NET_BIND_SERVICE +#AmbientCapabilities=CAP_NET_BIND_SERVICE +### +# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to +# set the following value to false to allow capabilities to be applied on gitea process. The following +# value if set to true sandboxes gitea service and prevent any processes from running with privileges +# in the host user namespace. +### +#PrivateUsers=false +### + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。 + +```bash +systemctl daemon-reload && systemctl enable gitea && systemctl start gitea && systemctl status gitea +``` diff --git a/6.10-VS-Code.md b/6.10-VS-Code.md new file mode 100644 index 0000000..7e7da43 --- /dev/null +++ b/6.10-VS-Code.md @@ -0,0 +1,37 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 簡介 + +code-server 可在伺服器上執行 VS Code,並透過瀏覽器遠端使用。本文記錄在 Ubuntu 上安裝 code-server 的步驟。 + +# 安裝相依套件 + +安裝腳本下載過程需要 curl。 + +```bash +apt update && apt install -y curl +``` + +# 安裝 VS Code + +透過官方安裝腳本安裝 code-server。 + +```bash +curl -fsSL https://code-server.dev/install.sh | sh +``` + +# 啟動服務 + +設為開機自動啟動並啟動目前使用者的 code-server 服務,再檢視狀態。 + +```bash +systemctl daemon-reload && systemctl enable --now code-server@$USER && systemctl start code-server@$USER && systemctl status code-server@$USER +``` + +# 預設密碼 + +首次啟動後,登入密碼會自動產生並寫入設定檔。 + +```bash +cat ~/.config/code-server/config.yaml +``` diff --git a/6.11-Coder.md b/6.11-Coder.md new file mode 100644 index 0000000..3acddc9 --- /dev/null +++ b/6.11-Coder.md @@ -0,0 +1,88 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 簡介 + +Coder 是自架的雲端開發環境平台,可在伺服器上建立並管理遠端開發工作區。本文記錄在 Ubuntu 上安裝 Coder,並使用 PostgreSQL 作為資料庫的步驟。 + +# 安裝 Coder + +透過官方安裝腳本安裝。 + +```bash +curl -L https://coder.com/install.sh | sh +``` + +# 修改 Coder 綁定的位址 + +```bash +nano /etc/coder.d/coder.env +``` + +(設定如下) + +``` +CODER_ACCESS_URL=https://coder.jsc.idv.tw + +CODER_HTTP_ADDRESS=0.0.0.0:80 +CODER_PG_CONNECTION_URL=postgres://postgres:<密碼>@192.168.3.101:5432/coder?sslmode=disable +``` + +# 設定 Coder 服務檔 + +```bash +systemctl edit coder +``` + +(如下內容一定要修改,其他選擇性) + +``` +[Service] +EnvironmentFile=/etc/coder.d/coder.env +User=coder +Group=coder +``` + +# 啟動服務 + +設為開機自動啟動並立即啟動服務。 + +```bash +systemctl daemon-reload && systemctl enable --now coder && systemctl status coder +``` + +# 設定資料庫 + +以 postgres 系統帳號進入 PostgreSQL 互動介面。 + +```bash +sudo -u postgres psql +``` + +新建專屬使用者與資料庫。 + +```sql +CREATE USER coder WITH PASSWORD 'coder'; + +CREATE DATABASE coder; +``` + +設定資料庫權限(Postgres 15 以後,schema 權限需另外授予,否則應用程式無法建立資料表)。 + +```sql +-- 1. Give ownership of the database to the app user +ALTER DATABASE coder OWNER TO coder; + +-- 2. Give ownership of the public schema to the app user +ALTER SCHEMA public OWNER TO coder; + +-- 3. Ensure the user has create permissions (Crucial for Postgres 15+) +GRANT USAGE, CREATE ON SCHEMA public TO coder; +``` + +# 設定 Docker Provider + +設定 Docker 權限給 Coder + +```bash +usermod -aG docker coder +``` diff --git a/6.12-Oh-My-Posh.md b/6.12-Oh-My-Posh.md new file mode 100644 index 0000000..ee0f199 --- /dev/null +++ b/6.12-Oh-My-Posh.md @@ -0,0 +1,13 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 安裝 Oh My Posh + +```bash +curl -s https://ohmyposh.dev/install.sh | bash -s +``` + +(啟動 bash 就初始化工具) + +```bash +echo 'eval "$(oh-my-posh init bash)"' >> ~/.bashrc +``` diff --git a/6.2-GiteaRunner(Ubuntu).md b/6.2-GiteaRunner(Ubuntu).md new file mode 100644 index 0000000..076af95 --- /dev/null +++ b/6.2-GiteaRunner(Ubuntu).md @@ -0,0 +1,81 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 簡介 + +Gitea Runner(act_runner)負責執行 Gitea Actions 的 CI/CD 工作流程,需向 Gitea 主機註冊後才能接收任務。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署 Runner 的步驟。 + +# 安裝相依套件 + +部分 Actions 工作流程需要 Node.js 環境。 + +```bash +apt update && apt install -y nodejs +``` + +# 下載 Gitea Runner + +從官方下載指定版本的二進位檔,放到 `/usr/local/bin/runner`。 + +```bash +wget https://gitea.com/gitea/runner/releases/download/v1.0.2/gitea-runner-1.0.2-linux-amd64 -O /usr/local/bin/runner +``` + +```bash +wget https://gitea.com/gitea/runner/releases/download/v1.0.8/gitea-runner-1.0.8-linux-amd64 -O /usr/local/bin/runner +``` + +下載後將 runner 設定為可執行檔。 + +```bash +chmod +x /usr/local/bin/runner +``` + +# 註冊 Gitea Runner + +執行註冊指令,依提示輸入 Gitea 主機位址與註冊權杖(registration token),完成後會在當前目錄產生設定檔。 + +```bash +runner register +``` + +# 建立 Gitea Runner 服務 + +以 systemd 管理 Runner,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。 + +```bash +nano /etc/systemd/system/runner.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=Gitea Actions runner + +[Service] +Environment=HOME=/root +Type=simple +WorkingDirectory=/root +ExecStart=/usr/local/bin/runner daemon +Restart=always +User=root + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。 + +```bash +systemctl daemon-reload && systemctl enable runner.service && systemctl start runner.service && systemctl status runner.service +``` + +# 停止服務 + +停止並移除舊版(act_runner)服務時使用。 + +```bash +systemctl stop act_runner.service && systemctl disable act_runner.service && rm /etc/systemd/system/act_runner.service +``` diff --git a/6.3-Gitea-Runner.md b/6.3-Gitea-Runner.md new file mode 100644 index 0000000..8523151 --- /dev/null +++ b/6.3-Gitea-Runner.md @@ -0,0 +1,65 @@ +> 第6章 開發與持續整合 · 來源:Windows 知識庫 + +# 從 Github Release Page 下載 Gitea Runner,並重新命名成 act_runner.exe + +Github Release Page: https://gitea.com/gitea/act_runner/releases + +v0.2.11: https://gitea.com/gitea/act_runner/releases/download/v0.2.11/act_runner-0.2.11-windows-amd64.exe + +```powershell +Invoke-WebRequest https://gitea.com/gitea/act_runner/releases/download/v0.2.11/act_runner-0.2.11-windows-amd64.exe -OutFile act_runner.exe +``` + +# 註冊 Gitea Runner 到 Gitea Server 產生 .runner 檔 + +```powershell +$instance="" +``` + +```powershell +$token="" +``` + +```powershell +$labels="" +``` + +```powershell +$name="" +``` + +```powershell +.\act_runner.exe register --no-interactive --instance $instance --token $token --labels $labels --name $name +``` + +# 從 Github Release Page 下載 WinSW,並重新命名成 winsw.exe + +Github Release Page: https://github.com/winsw/winsw/releases + +v2.12.0: https://github.com/winsw/winsw/releases/download/v2.12.0/WinSW-x64.exe + +```powershell +Invoke-WebRequest https://github.com/winsw/winsw/releases/download/v2.12.0/WinSW-x64.exe -OutFile winsw.exe +``` + +建立配置檔,且檔案名稱需要跟 WinSW 一樣,如 winsw.xml + +```xml + + gitea_runner + Gitea Runner + This service runs Gitea Runner. + act_runner.exe + daemon + +``` + +安裝並啟動服務 + +```powershell +.\winsw.exe install +``` + +```powershell +.\winsw.exe start +``` diff --git a/6.4-GiteaRunner(Alpine).md b/6.4-GiteaRunner(Alpine).md new file mode 100644 index 0000000..85078ca --- /dev/null +++ b/6.4-GiteaRunner(Alpine).md @@ -0,0 +1,74 @@ +> 第6章 開發與持續整合 · 來源:Alpine 知識庫 + +# 下載 Gitea Runner + +```bash +wget https://gitea.com/gitea/act_runner/releases/download/v0.2.13/act_runner-0.2.13-linux-amd64 -O /usr/local/bin/act_runner +``` + +將 act_runner 設定為可執行檔 + +```bash +chmod +x /usr/local/bin/act_runner +``` + +# 註冊 Gitea Runner + +設定參數 + +```bash +GITEA_URL='https://gitea.jsc.idv.tw' +``` + +```bash +REGISTER_TOKEN='' +``` + +```bash +RUNNER_LABELS='ct-docker' +``` + +```bash +RUNNER_NAME='ct-docker' +``` + +```bash +act_runner register --no-interactive --instance $GITEA_URL --token $REGISTER_TOKEN --labels $RUNNER_LABELS --name $RUNNER_NAME +``` + +# 設計 Gitea Runner 服務 + +```bash +nano /etc/init.d/act_runner +``` + +服務檔內容 + +```ini +#!/sbin/openrc-run + +name="act_runner" +directory="/root" +description="Gitea Actions runner" +command="/usr/local/bin/act_runner" +command_args="daemon" +command_user="root" +command_background="yes" +pidfile="/run/${name}.pid" + +depend() { + need net +} +``` + +將服務改為可執行 + +```bash +chmod +x /etc/init.d/act_runner +``` + +啟動服務 + +```bash +rc-service act_runner start && rc-service act_runner status && rc-update add act_runner +``` diff --git a/6.5-Gitlab.md b/6.5-Gitlab.md new file mode 100644 index 0000000..d6bee28 --- /dev/null +++ b/6.5-Gitlab.md @@ -0,0 +1,35 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 簡介 + +GitLab CE(社群版)是功能完整的自架 Git 平台,內建 CI/CD、Issue 追蹤等功能。本文記錄在 Ubuntu 上透過官方套件庫安裝 GitLab 的步驟。 + +# 安裝相依套件 + +安裝套件庫腳本與套件下載過程需要 curl。 + +```bash +apt update && apt install -y curl +``` + +透過官方腳本加入 GitLab 套件庫。 + +```bash +curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" | bash +``` + +# 安裝 Gitlab + +安裝時以 `EXTERNAL_URL` 指定對外網址,GitLab 會據此自動完成初始設定。 + +```bash +EXTERNAL_URL="https://gitlab.jsc.idv.tw" apt install gitlab-ce +``` + +# 取得 root 密碼 + +安裝後系統會產生隨機的 root 初始密碼,存放於下列檔案,且必須在 24 小時內登入並變更,逾期該檔案會被自動刪除。 + +```bash +cat /etc/gitlab/initial_root_password +``` diff --git a/6.6-ASP.NET.md b/6.6-ASP.NET.md new file mode 100644 index 0000000..acd3584 --- /dev/null +++ b/6.6-ASP.NET.md @@ -0,0 +1,29 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 簡介 + +本文提供以 systemd 部署 ASP.NET(.NET)應用程式的服務檔範本。將大括號標記的欄位替換為實際值即可: + +- `{project_name}`:專案(與 dll)名稱 +- `{environment_name}`:執行環境,例如 `Production`、`Staging` +- `{url}`:服務監聽的位址與連接埠,例如 `http://0.0.0.0:5000` + +# 建立 ASP.NET 服務 + +建立服務設定檔(路徑:`/etc/systemd/system/`),內容如下: + +```ini +# /etc/systemd/system/ + +[Unit] +Description=..write something about project + +[Service] +Type=simple +WorkingDirectory=/home/gitlab-runner/deploy/{project_name} +ExecStart=/usr/bin/dotnet /home/gitlab-runner/deploy/{project_name}/{project_name}.dll --environment {environment_name} --urls={url} +Restart=always + +[Install] +WantedBy=multi-user.target +``` diff --git a/6.7-Django.md b/6.7-Django.md new file mode 100644 index 0000000..2b25192 --- /dev/null +++ b/6.7-Django.md @@ -0,0 +1,41 @@ +> 第6章 開發與持續整合 · 來源:Python 知識庫 + +# 安裝 Django + +```bash +pip3 install Django +``` + +# 建立專案 + +```bash +mkdir djangotutorial && django-admin startproject mysite djangotutorial +``` + +# 啟動專案 + +在 setting.py 將主機位置加入 ALLOWED_HOSTS + +```python3 +ALLOWED_HOSTS = [ "192.168.30.107" ] +``` + +開發模式 + +```bash +python3 manage.py runserver 0.0.0.0:8000 +``` + +生產模式(wsgi) + +使用 gunicorn + +```bash +pip3 install gunicorn +``` + +透過 gunicorn 啟動 + +```bash +gunicorn --bind 0.0.0.0:8000 mysite.wsgi:application +``` diff --git a/6.8-Node-JS.md b/6.8-Node-JS.md new file mode 100644 index 0000000..73123be --- /dev/null +++ b/6.8-Node-JS.md @@ -0,0 +1,19 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 安裝相依套件 + +```bash +apt update && apt install -y curl unzip +``` + +# 下載並安裝 fnm: + +```bash +curl -o- https://fnm.vercel.app/install | bash +``` + +# 下載並安裝 Node.js: + +```bash +fnm install 26 +``` diff --git a/6.9-C#-SDK.md b/6.9-C#-SDK.md new file mode 100644 index 0000000..ae81e6b --- /dev/null +++ b/6.9-C#-SDK.md @@ -0,0 +1,23 @@ +> 第6章 開發與持續整合 · 來源:Ubuntu 知識庫 + +# 下載 C# SDK 安裝套件: + +```bash +wget https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +``` + +```bash +wget https://packages.microsoft.com/config/debian/13/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +``` + +# 安裝 C# SDK 套件: + +```bash +dpkg -i packages-microsoft-prod.deb +``` + +# 安裝 C# .NET 10 + +```bash +apt update && apt install -y dotnet-sdk-10.0 +``` diff --git a/7.1-ccstatusline.md b/7.1-ccstatusline.md new file mode 100644 index 0000000..f6d56d8 --- /dev/null +++ b/7.1-ccstatusline.md @@ -0,0 +1,26 @@ +> 第7章 AI 工具 · 來源:Ubuntu 知識庫 + +# 設定 Claude 狀態列使用此風格 + +```bash +nano ~/.claude/settings.json +``` + +(附加以下內容) + +```json +{ + "statusLine": { + "type": "command", + "command": "npx -y ccstatusline@latest", + "padding": 0, + "refreshInterval": 10 + } +} +``` + +# 設定 ccstatusline + +```bash +npx -y ccstatusline@latest +``` diff --git a/7.2-CLIProxyAPI.md b/7.2-CLIProxyAPI.md new file mode 100644 index 0000000..4437380 --- /dev/null +++ b/7.2-CLIProxyAPI.md @@ -0,0 +1,39 @@ +> 第7章 AI 工具 · 來源:Ubuntu 知識庫 + +# 安裝套件 [Tool:Node JS](https://gitea.jsc.idv.tw/knowledges/Ubuntu/wiki/Tool%EF%BC%9ANode-JS) + +# 安裝服務 + +```bash +npm install -g cliproxyapi --registry=https://gitea.jsc.idv.tw/api/packages/jiantw83/npm +``` + +# 設定服務 + +```bash +nano /etc/systemd/system/cliproxyapi.service +``` + +(貼入以下內容) + +``` +[Unit] +Description=CLI Proxy from API + +[Service] +Environment=PATH=/root/.local/share/fnm/node-versions/v26.7.0/installation/bin:/root/.local/share/fnm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin +Type=simple +WorkingDirectory=/root +ExecStart=/root/.local/share/fnm/node-versions/v26.7.0/installation/bin/cliproxyapi +Restart=always +User=root + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +```bash +systemctl daemon-reload && systemctl enable cliproxyapi.service && systemctl start cliproxyapi.service && systemctl status cliproxyapi.service +``` diff --git a/7.3-OpenClaw.md b/7.3-OpenClaw.md new file mode 100644 index 0000000..1e88955 --- /dev/null +++ b/7.3-OpenClaw.md @@ -0,0 +1,55 @@ +> 第7章 AI 工具 · 來源:Ubuntu 知識庫 + +# 更新系統套件 + +```bash +apt update && apt upgrade -y && apt install -y curl wget git unzip +``` + +# 安裝 NodeJS + +```bash +curl -fsSL https://nodesource.com | bash - +``` + +```bash +apt install -y nodejs +``` + +# 安裝 OpenClaw + +```bash +curl -fsSL https://openclaw.ai/install.sh | bash +``` + +# 驗證 OpenClaw 版本 + +```bash +openclaw version +``` + +# 初始化 OpenClaw 系統 + +```bash +openclaw onboard --install-daemon +``` + +# 啟動 OpenClaw 服務 + +```bash +sudo loginctl enable-linger $USER +``` + +```bash +openclaw gateway status --port 18789 +``` + +# 設定 OpenClaw 密碼 + +```bash +echo "$(openssl rand -hex 32)" > openclaw-token +``` + +```bash +openclaw config set gateway.auth.token "$(cat openclaw-token)" +``` diff --git a/7.4-OpenCode.md b/7.4-OpenCode.md new file mode 100644 index 0000000..2dc74d1 --- /dev/null +++ b/7.4-OpenCode.md @@ -0,0 +1,53 @@ +> 第7章 AI 工具 · 來源:Ubuntu 知識庫 + +# 簡介 + +# 下載 OpenCode + +```bash +curl -fsSL https://opencode.ai/install | bash +``` + +# 建立 OpenCode 服務 + +設定使用者名稱與密碼 + +```bash +echo "export OPENCODE_SERVER_USERNAME='jiantw83'" >> ~/.bashrc +``` + +```bash +echo "export OPENCODE_SERVER_PASSWORD='<密碼>'" >> ~/.bashrc +``` + +以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。 + +```bash +nano /etc/systemd/system/opencode.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=OpenCode + +[Service] +Environment=HOME=/root +Type=simple +WorkingDirectory=/root +ExecStart=/root/.opencode/bin/opencode serve --hostname 0.0.0.0 --mdns true --mdns-domain opencode.jsc.idv.me +Restart=always +User=root + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。 + +```bash +systemctl daemon-reload && systemctl enable opencode.service && systemctl start opencode.service && systemctl status opencode.service +``` diff --git a/7.5-PicoClaw.md b/7.5-PicoClaw.md new file mode 100644 index 0000000..9045535 --- /dev/null +++ b/7.5-PicoClaw.md @@ -0,0 +1,95 @@ +> 第7章 AI 工具 · 來源:Ubuntu 知識庫 + +# 簡介 + +PicoClaw 是 Sipeed 推出的工具,可由原始碼自行建置,也可直接以套件快速安裝。本文記錄兩種在 Ubuntu 上的安裝方式,以及 TUI / WebUI 兩種啟動方法。 + +# 安裝語言套件 + +由原始碼建置需要 Go 與 Node.js 環境。 + +## Go + +下載並解壓縮 Go 到 `/usr/local`。 + +```bash +wget https://go.dev/dl/go1.26.2.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.26.2.linux-amd64.tar.gz +``` + +```bash +wget https://go.dev/dl/go1.26.5.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.26.5.linux-amd64.tar.gz +``` + +將 Go 加入環境變數並確認版本。 + +```bash +echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc && go version +``` + +## NodeJS && NPM + +```bash +apt update && apt install -y nodejs npm +``` + +# 下載原始碼 + +從 GitHub 取得原始碼。 + +```bash +git clone https://github.com/sipeed/picoclaw.git +``` + +# 編譯原始碼 + +安裝建置所需的相依套件。 + +```bash +cd ~/picoclaw && make deps +``` + +為目前平台建構核心二進位檔。 + +```bash +cd ~/picoclaw && make build +``` + +為所有 Makefile 管理的平台建立核心二進位檔案。 + +```bash +cd ~/picoclaw && make build-all +``` + +建置並安裝。 + +```bash +cd ~/picoclaw && make install +``` + +# 啟動 TUI for SSH + +適合透過 SSH 連線時使用的文字介面。 + +```bash +picoclaw-launcher-tui +``` + +# 快速安裝 + +若不想自行建置,可直接下載 deb 套件安裝。 + +```bash +wget https://github.com/sipeed/picoclaw/releases/download/v0.2.6/picoclaw_x86_64.deb && dpkg -i picoclaw_x86_64.deb +``` + +```bash +wget https://github.com/sipeed/picoclaw/releases/download/v0.3.1/picoclaw_x86_64.deb && dpkg -i picoclaw_x86_64.deb +``` + +# 啟動 WebUI for Desktop + +適合桌面環境使用的網頁介面,`-public` 開放外部連線。 + +```bash +picoclaw-launcher -public +``` diff --git a/7.6-補充解決方案內,所有專案的註解,並整理-README.md b/7.6-補充解決方案內,所有專案的註解,並整理-README.md new file mode 100644 index 0000000..e44284e --- /dev/null +++ b/7.6-補充解決方案內,所有專案的註解,並整理-README.md @@ -0,0 +1,29 @@ +> 第7章 AI 工具 · 來源:Prompt 知識庫 + +``` +請幫我補上這個解決方案內的所有註解,包括: + +1. **XML 文件註解**: + - 類別、介面、列舉的 和 + - 所有方法的 和 + - **所有方法參數的 ** + - 所有回傳值的 + - 所有屬性的 + +2. **方法內部註解**: + - 說明關鍵操作的用途 + - 解釋複雜邏輯的原因 + - 方法的實作與介面的註解相同 + +3. **README 文件**: + - 每個專案一個 README.md + - 包含使用範例 + - 說明輸入輸出參數 + - 整理方法的操作流程 + +請確保: +- **建構子的所有參數都要有 註解** +- 每個方法的每個參數都要有 註解 +- 註解要清楚說明參數的用途和預期值 +- 使用繁體中文撰寫所有註解 +``` diff --git a/8.1-Emby.md b/8.1-Emby.md new file mode 100644 index 0000000..e0baacd --- /dev/null +++ b/8.1-Emby.md @@ -0,0 +1,21 @@ +> 第8章 應用服務 · 來源:Ubuntu 知識庫 + +# 簡介 + +Emby 是一套媒體伺服器,可整理並串流家中的影音內容。本文記錄在 Ubuntu 上以官方 deb 套件安裝 Emby Server 的步驟。 + +# 下載 Emby + +從官方下載指定版本的 deb 安裝套件。 + +```bash +wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.8.11.0/emby-server-deb_4.8.11.0_amd64.deb +``` + +# 安裝 Emby + +以 dpkg 安裝下載的套件,安裝後 Emby 會自動註冊為系統服務並啟動。 + +```bash +dpkg -i emby-server-deb_4.8.11.0_amd64.deb +``` diff --git a/8.2-MeTube.md b/8.2-MeTube.md new file mode 100644 index 0000000..48a42e6 --- /dev/null +++ b/8.2-MeTube.md @@ -0,0 +1,88 @@ +> 第8章 應用服務 · 來源:Ubuntu 知識庫 + +# 簡介 + +MeTube 是 youtube-dl / yt-dlp 的網頁前端,可透過瀏覽器下載影音。本文記錄在 Ubuntu 上由原始碼建置並以 systemd 部署的步驟。 + +# 安裝相依套件 + +建置前端與後端、處理影音時需要這些套件。 + +```bash +apt update && apt install -y git nodejs npm curl ffmpeg +``` + +# 下載 MeTube + +從 GitHub 取得原始碼。 + +```bash +git clone https://github.com/alexta69/metube.git +``` + +# 安裝 MeTube + +## 前端 + +安裝前端相依套件並建置 Angular 前端。 + +```bash +cd ~/metube/ui && npm install && node_modules/.bin/ng build +``` + +## 後端 + +安裝 uv(Python 套件管理工具)並同步後端相依套件。 + +```bash +cd ~/metube && curl -LsSf https://astral.sh/uv/install.sh | sh && uv sync +``` + +將 uv 加入環境變數。 + +```bash +echo 'source $HOME/.local/bin/env' >> ~/.bashrc && source ~/.bashrc +``` + +# 執行 MeTube + +手動執行測試是否正常。 + +```bash +uv run python3 app/main.py +``` + +# 建立 MeTube 服務 + +以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。 + +```bash +nano /etc/systemd/system/metube.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=MeTube + +[Service] +Type=simple +WorkingDirectory=/root/metube +ExecStart=/root/.local/bin/uv run python3 app/main.py +Restart=always +User=root + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +重新載入 systemd 設定、設為開機自動啟動並啟動服務。 + +```bash +systemctl daemon-reload && systemctl enable metube.service && systemctl start metube.service +``` + +# 連接埠 8081 diff --git a/8.3-Vaultwarden.md b/8.3-Vaultwarden.md new file mode 100644 index 0000000..6802cf4 --- /dev/null +++ b/8.3-Vaultwarden.md @@ -0,0 +1,15 @@ +> 第8章 應用服務 · 來源:Ubuntu 知識庫 + +# 簡介 + + + +# 安裝 Vaultwarden + +```bash +wget -qO- https://vaultwarden-deb.pages.dev/dists/trixie/install.sh | bash +``` + +```bash +apt update && apt install vaultwarden +``` diff --git a/8.4-ezBookkeeping.md b/8.4-ezBookkeeping.md new file mode 100644 index 0000000..9c7863a --- /dev/null +++ b/8.4-ezBookkeeping.md @@ -0,0 +1,80 @@ +> 第8章 應用服務 · 來源:Ubuntu 知識庫 + +# 簡介 + +ezBookkeeping 是一套自架的個人記帳服務。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署,並使用 PostgreSQL 作為資料庫的步驟。 + +# 下載 ezBookkeeping + +從官方下載指定版本的壓縮檔並解壓縮,以下提供兩個版本,擇一執行即可。 + +```bash +wget https://github.com/mayswind/ezbookkeeping/releases/download/v1.4.0/ezbookkeeping-v1.4.0-linux-amd64.tar.gz && tar zxvf ezbookkeeping-v1.4.0-linux-amd64.tar.gz +``` + +```bash +wget https://github.com/mayswind/ezbookkeeping/releases/download/v1.5.1/ezbookkeeping-v1.5.1-linux-amd64.tar.gz && tar zxvf ezbookkeeping-v1.5.1-linux-amd64.tar.gz +``` + +# 建立 ezBookkeeping 服務 + +以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。 + +```bash +nano /etc/systemd/system/ezbookkeeping.service +``` + +服務檔內容如下: + +```ini +[Unit] +Description=ezBookkeeping + +[Service] +Environment=HOME=/root +Type=simple +WorkingDirectory=/root +ExecStart=/root/ezbookkeeping server run +Restart=always +User=root + +[Install] +WantedBy=multi-user.target +``` + +# 啟動服務 + +重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。 + +```bash +systemctl daemon-reload && systemctl enable ezbookkeeping.service && systemctl start ezbookkeeping.service && systemctl status ezbookkeeping.service +``` + +# 設定資料庫 + +以 postgres 系統帳號進入 PostgreSQL 互動介面。 + +```bash +sudo -u postgres psql +``` + +新建專屬使用者與資料庫。 + +```sql +CREATE USER ezbookkeeping WITH PASSWORD 'ezbookkeeping'; + +CREATE DATABASE ezbookkeeping; +``` + +設定資料庫權限(Postgres 15 以後,schema 權限需另外授予,否則應用程式無法建立資料表)。 + +```sql +-- 1. Give ownership of the database to the app user +ALTER DATABASE ezbookkeeping OWNER TO ezbookkeeping; + +-- 2. Give ownership of the public schema to the app user +ALTER SCHEMA public OWNER TO ezbookkeeping; + +-- 3. Ensure the user has create permissions (Crucial for Postgres 15+) +GRANT USAGE, CREATE ON SCHEMA public TO ezbookkeeping; +``` diff --git a/Home.md b/Home.md index 76fe97a..ae772c5 100644 --- a/Home.md +++ b/Home.md @@ -1 +1,23 @@ # JSC 知識庫 + +以「一本書」整理自 [knowledges](https://gitea.jsc.idv.tw/knowledges) 各知識庫的 wiki,依領域分為八章。每頁是一個可直接照做的步驟紀錄。 + +## 目錄 + +1. [第1章 系統維護](%E7%AC%AC1%E7%AB%A0-%E7%B3%BB%E7%B5%B1%E7%B6%AD%E8%AD%B7):開機、磁碟、憑證、時區等作業系統層級的排錯與設定。(7 篇) +2. [第2章 網路與儲存](%E7%AC%AC2%E7%AB%A0-%E7%B6%B2%E8%B7%AF%E8%88%87%E5%84%B2%E5%AD%98):網路設定、連接埠、SMB 分享、iSCSI、SSH,以及路由器與 NAS 虛擬機。(8 篇) +3. [第3章 虛擬化](%E7%AC%AC3%E7%AB%A0-%E8%99%9B%E6%93%AC%E5%8C%96):Proxmox VE、Hyper-V、WSL 與直通設定。(9 篇) +4. [第4章 容器與編排](%E7%AC%AC4%E7%AB%A0-%E5%AE%B9%E5%99%A8%E8%88%87%E7%B7%A8%E6%8E%92):Docker、K3s、k3d 與 Traefik 反向代理。(5 篇) +5. [第5章 資料庫與搜尋](%E7%AC%AC5%E7%AB%A0-%E8%B3%87%E6%96%99%E5%BA%AB%E8%88%87%E6%90%9C%E5%B0%8B):PostgreSQL、SQL Server、Redis、Elasticsearch。(4 篇) +6. [第6章 開發與持續整合](%E7%AC%AC6%E7%AB%A0-%E9%96%8B%E7%99%BC%E8%88%87%E6%8C%81%E7%BA%8C%E6%95%B4%E5%90%88):程式碼託管、Runner、語言執行環境與開發工具。(12 篇) +7. [第7章 AI 工具](%E7%AC%AC7%E7%AB%A0-AI-%E5%B7%A5%E5%85%B7):Claude、CLIProxyAPI、OpenClaw、OpenCode、PicoClaw 與提示詞。(6 篇) +8. [第8章 應用服務](%E7%AC%AC8%E7%AB%A0-%E6%87%89%E7%94%A8%E6%9C%8D%E5%8B%99):影音、密碼庫、記帳等自架應用。(4 篇) + +## 閱讀 + +安裝 `jsc-wiki` 插件後可直接在 Claude Code 讀取:`/jsc-wiki:wiki` 看目錄與搜尋,或 `/jsc-wiki:system`、`/jsc-wiki:network` 等依領域查詢。 + +## 說明 + +- 內容中的密碼與 token 已改為 `<密碼>`、`` 等占位符,使用時請自行替換。 +- `CONTENTS` 是內部工作流程規格,不屬於知識,未收錄。 diff --git a/第1章-系統維護.md b/第1章-系統維護.md new file mode 100644 index 0000000..26648f5 --- /dev/null +++ b/第1章-系統維護.md @@ -0,0 +1,13 @@ +# 第1章 系統維護 + +開機、磁碟、憑證、時區等作業系統層級的排錯與設定。 + +- [1.1 修改成台北時區](1.1-%E4%BF%AE%E6%94%B9%E6%88%90%E5%8F%B0%E5%8C%97%E6%99%82%E5%8D%80)(Ubuntu) +- [1.2 延展系統硬碟](1.2-%E5%BB%B6%E5%B1%95%E7%B3%BB%E7%B5%B1%E7%A1%AC%E7%A2%9F)(Ubuntu) +- [1.3 憑證 x509 問題](1.3-%E6%86%91%E8%AD%89-x509-%E5%95%8F%E9%A1%8C)(Ubuntu) +- [1.4 進入 busybox 問題](1.4-%E9%80%B2%E5%85%A5-busybox-%E5%95%8F%E9%A1%8C)(Ubuntu) +- [1.5 Kernel Panic:VFS 無法掛載 root fs](1.5-Kernel-Panic%EF%BC%9AVFS-%E7%84%A1%E6%B3%95%E6%8E%9B%E8%BC%89-root-fs)(Ubuntu) +- [1.6 常用工具](1.6-%E5%B8%B8%E7%94%A8%E5%B7%A5%E5%85%B7)(Ubuntu) +- [1.7 使用舊的右鍵選項](1.7-%E4%BD%BF%E7%94%A8%E8%88%8A%E7%9A%84%E5%8F%B3%E9%8D%B5%E9%81%B8%E9%A0%85)(Windows) + +[回目錄](Home) diff --git a/第2章-網路與儲存.md b/第2章-網路與儲存.md new file mode 100644 index 0000000..9bcc109 --- /dev/null +++ b/第2章-網路與儲存.md @@ -0,0 +1,14 @@ +# 第2章 網路與儲存 + +網路設定、連接埠、SMB 分享、iSCSI、SSH,以及路由器與 NAS 虛擬機。 + +- [2.1 netplan](2.1-netplan)(Ubuntu) +- [2.2 53 埠被占用](2.2-53-%E5%9F%A0%E8%A2%AB%E5%8D%A0%E7%94%A8)(Ubuntu) +- [2.3 掛載 SMB](2.3-%E6%8E%9B%E8%BC%89-SMB)(Proxmox VE) +- [2.4 停用 SMB 服務](2.4-%E5%81%9C%E7%94%A8-SMB-%E6%9C%8D%E5%8B%99)(Windows) +- [2.5 TGT](2.5-TGT)(Debian) +- [2.6 OpenSSH](2.6-OpenSSH)(Windows) +- [2.7 OpenWrt](2.7-OpenWrt)(Proxmox VE) +- [2.8 DiskStation Manager](2.8-DiskStation-Manager)(Proxmox VE) + +[回目錄](Home) diff --git a/第3章-虛擬化.md b/第3章-虛擬化.md new file mode 100644 index 0000000..b7210b8 --- /dev/null +++ b/第3章-虛擬化.md @@ -0,0 +1,15 @@ +# 第3章 虛擬化 + +Proxmox VE、Hyper-V、WSL 與直通設定。 + +- [3.1 套件更新設定](3.1-%E5%A5%97%E4%BB%B6%E6%9B%B4%E6%96%B0%E8%A8%AD%E5%AE%9A)(Proxmox VE) +- [3.2 硬碟直通](3.2-%E7%A1%AC%E7%A2%9F%E7%9B%B4%E9%80%9A)(Proxmox VE) +- [3.3 將PCIe直通給PVE的虛擬機](3.3-%E5%B0%87PCIe%E7%9B%B4%E9%80%9A%E7%B5%A6PVE%E7%9A%84%E8%99%9B%E6%93%AC%E6%A9%9F)(Ubuntu) +- [3.4 相關參考紀錄](3.4-%E7%9B%B8%E9%97%9C%E5%8F%83%E8%80%83%E7%B4%80%E9%8C%84)(Proxmox VE) +- [3.5 解決Windows安裝WSL後死機的問題](3.5-%E8%A7%A3%E6%B1%BAWindows%E5%AE%89%E8%A3%9DWSL%E5%BE%8C%E6%AD%BB%E6%A9%9F%E7%9A%84%E5%95%8F%E9%A1%8C)(Proxmox VE) +- [3.6 Hyper-V](3.6-Hyper-V)(Windows) +- [3.7 WSL:從零開始](3.7-WSL%EF%BC%9A%E5%BE%9E%E9%9B%B6%E9%96%8B%E5%A7%8B)(Windows) +- [3.8 WSL:安裝 Ubuntu 26.04](3.8-WSL%EF%BC%9A%E5%AE%89%E8%A3%9D-Ubuntu-26.04)(Windows) +- [3.9 避免虛擬化啟動失敗](3.9-%E9%81%BF%E5%85%8D%E8%99%9B%E6%93%AC%E5%8C%96%E5%95%9F%E5%8B%95%E5%A4%B1%E6%95%97)(Raspberry Pi) + +[回目錄](Home) diff --git a/第4章-容器與編排.md b/第4章-容器與編排.md new file mode 100644 index 0000000..519f75c --- /dev/null +++ b/第4章-容器與編排.md @@ -0,0 +1,11 @@ +# 第4章 容器與編排 + +Docker、K3s、k3d 與 Traefik 反向代理。 + +- [4.1 Docker(Ubuntu)](4.1-Docker%EF%BC%88Ubuntu%EF%BC%89)(Ubuntu) +- [4.2 Docker(Raspberry Pi)](4.2-Docker%EF%BC%88Raspberry-Pi%EF%BC%89)(Raspberry Pi) +- [4.3 K3s](4.3-K3s)(Raspberry Pi) +- [4.4 k3d](4.4-k3d)(Ubuntu) +- [4.5 Traefik](4.5-Traefik)(Ubuntu) + +[回目錄](Home) diff --git a/第5章-資料庫與搜尋.md b/第5章-資料庫與搜尋.md new file mode 100644 index 0000000..225bc38 --- /dev/null +++ b/第5章-資料庫與搜尋.md @@ -0,0 +1,10 @@ +# 第5章 資料庫與搜尋 + +PostgreSQL、SQL Server、Redis、Elasticsearch。 + +- [5.1 PostgreSQL](5.1-PostgreSQL)(Ubuntu) +- [5.2 SQLServer](5.2-SQLServer)(Ubuntu) +- [5.3 Redis](5.3-Redis)(Ubuntu) +- [5.4 ElasticSearch](5.4-ElasticSearch)(Ubuntu) + +[回目錄](Home) diff --git a/第6章-開發與持續整合.md b/第6章-開發與持續整合.md new file mode 100644 index 0000000..e1e4af9 --- /dev/null +++ b/第6章-開發與持續整合.md @@ -0,0 +1,18 @@ +# 第6章 開發與持續整合 + +程式碼託管、Runner、語言執行環境與開發工具。 + +- [6.1 Gitea](6.1-Gitea)(Ubuntu) +- [6.2 GiteaRunner(Ubuntu)](6.2-GiteaRunner%EF%BC%88Ubuntu%EF%BC%89)(Ubuntu) +- [6.3 Gitea Runner](6.3-Gitea-Runner)(Windows) +- [6.4 GiteaRunner(Alpine)](6.4-GiteaRunner%EF%BC%88Alpine%EF%BC%89)(Alpine) +- [6.5 Gitlab](6.5-Gitlab)(Ubuntu) +- [6.6 ASP.NET](6.6-ASP.NET)(Ubuntu) +- [6.7 Django](6.7-Django)(Python) +- [6.8 Node JS](6.8-Node-JS)(Ubuntu) +- [6.9 C# SDK](6.9-C%23-SDK)(Ubuntu) +- [6.10 VS Code](6.10-VS-Code)(Ubuntu) +- [6.11 Coder](6.11-Coder)(Ubuntu) +- [6.12 Oh My Posh](6.12-Oh-My-Posh)(Ubuntu) + +[回目錄](Home) diff --git a/第7章-AI-工具.md b/第7章-AI-工具.md new file mode 100644 index 0000000..72dca03 --- /dev/null +++ b/第7章-AI-工具.md @@ -0,0 +1,12 @@ +# 第7章 AI 工具 + +Claude、CLIProxyAPI、OpenClaw、OpenCode、PicoClaw 與提示詞。 + +- [7.1 ccstatusline](7.1-ccstatusline)(Ubuntu) +- [7.2 CLIProxyAPI](7.2-CLIProxyAPI)(Ubuntu) +- [7.3 OpenClaw](7.3-OpenClaw)(Ubuntu) +- [7.4 OpenCode](7.4-OpenCode)(Ubuntu) +- [7.5 PicoClaw](7.5-PicoClaw)(Ubuntu) +- [7.6 補充解決方案內,所有專案的註解,並整理 README](7.6-%E8%A3%9C%E5%85%85%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88%E5%85%A7%EF%BC%8C%E6%89%80%E6%9C%89%E5%B0%88%E6%A1%88%E7%9A%84%E8%A8%BB%E8%A7%A3%EF%BC%8C%E4%B8%A6%E6%95%B4%E7%90%86-README)(Prompt) + +[回目錄](Home) diff --git a/第8章-應用服務.md b/第8章-應用服務.md new file mode 100644 index 0000000..0adf703 --- /dev/null +++ b/第8章-應用服務.md @@ -0,0 +1,10 @@ +# 第8章 應用服務 + +影音、密碼庫、記帳等自架應用。 + +- [8.1 Emby](8.1-Emby)(Ubuntu) +- [8.2 MeTube](8.2-MeTube)(Ubuntu) +- [8.3 Vaultwarden](8.3-Vaultwarden)(Ubuntu) +- [8.4 ezBookkeeping](8.4-ezBookkeeping)(Ubuntu) + +[回目錄](Home)