diff --git a/%E4%BF%AE%E6%94%B9%E6%88%90%E5%8F%B0%E5%8C%97%E6%99%82%E5%8D%80.md b/%E4%BF%AE%E6%94%B9%E6%88%90%E5%8F%B0%E5%8C%97%E6%99%82%E5%8D%80.md index e1247ef..6e225a1 100644 --- a/%E4%BF%AE%E6%94%B9%E6%88%90%E5%8F%B0%E5%8C%97%E6%99%82%E5%8D%80.md +++ b/%E4%BF%AE%E6%94%B9%E6%88%90%E5%8F%B0%E5%8C%97%E6%99%82%E5%8D%80.md @@ -1,3 +1,11 @@ -```bash -sudo timedatectl set-timezone Asia/Taipei -``` \ No newline at end of file +# 簡介 + +Ubuntu 預設時區通常為 UTC,會導致系統時間與台灣本地時間相差 8 小時。以下指令將系統時區設定為台北(Asia/Taipei)。 + +# 設定時區 + +```bash +sudo timedatectl set-timezone Asia/Taipei +``` + +設定後可用 `timedatectl` 確認時區是否已套用。 diff --git a/%E5%B0%87PCIe%E7%9B%B4%E9%80%9A%E7%B5%A6PVE%E7%9A%84%E8%99%9B%E6%93%AC%E6%A9%9F.md b/%E5%B0%87PCIe%E7%9B%B4%E9%80%9A%E7%B5%A6PVE%E7%9A%84%E8%99%9B%E6%93%AC%E6%A9%9F.md index 9c27244..3790f05 100644 --- a/%E5%B0%87PCIe%E7%9B%B4%E9%80%9A%E7%B5%A6PVE%E7%9A%84%E8%99%9B%E6%93%AC%E6%A9%9F.md +++ b/%E5%B0%87PCIe%E7%9B%B4%E9%80%9A%E7%B5%A6PVE%E7%9A%84%E8%99%9B%E6%93%AC%E6%A9%9F.md @@ -1,97 +1,120 @@ -# Step 1. 修改引導設定檔 - -```bash -nano /etc/default/grub -``` - -(找到 GRUB_CMDLINE_LINUX_DEFAULT 行,依據 CPU 類型加入參數) - -- Intel CPU:intel_iommu=on iommu=pt - -(範例:``` GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt" ```) - -- AMD CPU:amd_iommu=on iommu=pt - -(更新 Grub 引導並重啟速主機) - -```bash -update-grub && reboot -``` - -(重啟後,輸入 ``` dmesg | grep -e DMAR -e IOMMU ```。若看到 ``` IOMMU enabled ``` 代表啟用成功) - -# Step 2. 載入 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 -``` - -(寫入以下內容) - -```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 -``` - -(重啟後,輸入 ``` lspci -nnk -s 00:0d.0 ```。若看到 ``` Kernel driver in use: vfio-pci ``` 代表隔離成功) - -# Step 5. 將裝置新增至虛擬機 - -- 位置:硬體 > 新增 > PCI 裝置 -- 原始裝置:選取控制器位址 -- [v] All Functions -- [v] ROM-Bar -- [v] PCI-Express - -# PVE 可能是使用 systemd-boot 而非 GRUB - -```bash -nano /etc/kernel/cmdline -``` - -(檢查檔案內是否有以下內容,如果沒有,則直接加在原本內容的尾端) - -``` -intel_iommu=on iommu=pt -``` - -(讓核心參數生效) - -```bash -proxmox-boot-tool refresh -``` \ No newline at end of file +# 簡介 + +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/%E5%BB%B6%E5%B1%95%E7%B3%BB%E7%B5%B1%E7%A1%AC%E7%A2%9F.md b/%E5%BB%B6%E5%B1%95%E7%B3%BB%E7%B5%B1%E7%A1%AC%E7%A2%9F.md index d6ed1d9..f9ebe5e 100644 --- a/%E5%BB%B6%E5%B1%95%E7%B3%BB%E7%B5%B1%E7%A1%AC%E7%A2%9F.md +++ b/%E5%BB%B6%E5%B1%95%E7%B3%BB%E7%B5%B1%E7%A1%AC%E7%A2%9F.md @@ -1,67 +1,85 @@ -# 1. 確認磁碟大小 - -```bash -lsblk -``` - -```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. 調整硬碟大小 - -```bash -sudo fdisk /dev/sda -``` - -```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 大小 - -```bash -sudo pvresize /dev/sda3 -``` - -# 4. 調整 LV 大小 - -```bash -sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv -``` - -```bash -sudo resize2fs /dev/ubuntu-vg/ubuntu-lv -``` \ No newline at end of file +# 簡介 + +當虛擬機磁碟容量在外部(例如 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/%E6%86%91%E8%AD%89-x509-%E5%95%8F%E9%A1%8C.md b/%E6%86%91%E8%AD%89-x509-%E5%95%8F%E9%A1%8C.md index 38d20ea..23786fa 100644 --- a/%E6%86%91%E8%AD%89-x509-%E5%95%8F%E9%A1%8C.md +++ b/%E6%86%91%E8%AD%89-x509-%E5%95%8F%E9%A1%8C.md @@ -1,49 +1,55 @@ -這個問題是因為Ubuntu缺少所需的憑證,透過以下步驟可以解決這個問題。 - -# 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 檔案中的最後。 \ No newline at end of file +# 簡介 + +當網路環境中有防火牆或代理(例如 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/%E9%80%B2%E5%85%A5-busybox-%E5%95%8F%E9%A1%8C.md b/%E9%80%B2%E5%85%A5-busybox-%E5%95%8F%E9%A1%8C.md index f2ba344..d8bcf54 100644 --- a/%E9%80%B2%E5%85%A5-busybox-%E5%95%8F%E9%A1%8C.md +++ b/%E9%80%B2%E5%85%A5-busybox-%E5%95%8F%E9%A1%8C.md @@ -1,17 +1,27 @@ -# 1. 列出所有分區 - -```bash -blkid -``` - -# 2. 修復系統磁區 - -```bash -fsck -y /dev/mapper/ubuntu--vg-ubuntu--lv -``` - -# 3. 離開後,自動進入系統 - -```bash -exit -``` \ No newline at end of file +# 簡介 + +開機時若檔案系統毀損,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/53-%E5%9F%A0%E8%A2%AB%E5%8D%A0%E7%94%A8.md b/53-%E5%9F%A0%E8%A2%AB%E5%8D%A0%E7%94%A8.md index 5f93a87..670cfee 100644 --- a/53-%E5%9F%A0%E8%A2%AB%E5%8D%A0%E7%94%A8.md +++ b/53-%E5%9F%A0%E8%A2%AB%E5%8D%A0%E7%94%A8.md @@ -1,31 +1,43 @@ -# 1. 取消註解 DNSStubListener 並設定為 no - -```bash -sudo nano /etc/systemd/resolved.conf -``` - -``` -[Resolve] -#DNS= -#FallbackDNS= -#Domains= -#LLMNR=no -#MulticastDNS=no -#DNSSEC=no -#DNSOverTLS=no -#Cache=yes -DNSStubListener=no -#ReadEtcHosts=yes -``` - -# 2. 重新建立捷徑 - -```bash -sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf -``` - -# 3. 重新啟動系統服務 - -```bash -sudo systemctl restart systemd-resolved -``` \ No newline at end of file +# 簡介 + +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/Database%EF%BC%9APostgreSQL.md b/Database%EF%BC%9APostgreSQL.md index ff6bea2..ae57c90 100644 --- a/Database%EF%BC%9APostgreSQL.md +++ b/Database%EF%BC%9APostgreSQL.md @@ -1,24 +1,34 @@ -# 安裝 PostgreSQL - -```bash -apt update && apt install -y postgresql -``` - -# 允許外部連線 - -```bash -nano /etc/postgresql/17/main/pg_hba.conf -``` - -允許來自 `192.168.230.221` 連線的 `gitea` 使用者可以存取 - -```ini -... -host gitea gitea 192.168.230.221/24 md5 -``` - -重啟服務 - -```bash -systemctl restart postgresql && systemctl status postgresql -``` \ No newline at end of file +# 簡介 + +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/Database%EF%BC%9ASQLServer.md b/Database%EF%BC%9ASQLServer.md index 865947b..a2acb03 100644 --- a/Database%EF%BC%9ASQLServer.md +++ b/Database%EF%BC%9ASQLServer.md @@ -1,95 +1,113 @@ -# 安裝相關套件 - -```bash -apt update && apt install -y curl -``` - -# 安裝加密簽證 - -```bash -curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc -``` - -# 安裝套件列表 - -```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 -``` - -# 安裝缺少的套件 - -```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 - -## 密碼 - -```bash -/opt/mssql/bin/mssql-conf setup -``` - -## 代理 - -啟用代理後重啟服務 - -```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 加密簽證 - -```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 -``` - -設定環境變數 - -```bash -echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc && source ~/.bashrc -``` \ No newline at end of file +# 簡介 + +本文記錄在 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/Kernel Panic - not syncing%3A VFS%3A Unable to mount root fs on unknown-block.-.md b/Kernel Panic - not syncing%3A VFS%3A Unable to mount root fs on unknown-block.-.md index beaa970..6044d3d 100644 --- a/Kernel Panic - not syncing%3A VFS%3A Unable to mount root fs on unknown-block.-.md +++ b/Kernel Panic - not syncing%3A VFS%3A Unable to mount root fs on unknown-block.-.md @@ -1,35 +1,51 @@ -# 1. 修復損壞的 Kernal - -```bash -sudo apt -f install -``` - -# 2. 列出所有 Kernal - -```bash -dpkg --list | grep linux-image -``` - -# 3. 移除低版本到無法移除 - -```bash -sudo apt purge -y linux-image-x.xx.x-xxx-generic -``` - -# 4. 更新 GRUB 2 - -```bash -sudo update-grub2 -``` - -# 5. 更新 Kernal 到現在的版本 - -```bash -sudo apt update && sudo apt upgrade -y -``` - -# 6. 試著重啟看看是否正常 - -```bash -sudo reboot -``` \ No newline at end of file +# 簡介 + +當核心(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/Service%EF%BC%9AASP.NET.md b/Service%EF%BC%9AASP.NET.md index 4a2ea6e..2b41478 100644 --- a/Service%EF%BC%9AASP.NET.md +++ b/Service%EF%BC%9AASP.NET.md @@ -1,15 +1,27 @@ -```bash -# /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 -``` \ No newline at end of file +# 簡介 + +本文提供以 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/Service%EF%BC%9ACoder.md b/Service%EF%BC%9ACoder.md index 7418bce..5aa0111 100644 --- a/Service%EF%BC%9ACoder.md +++ b/Service%EF%BC%9ACoder.md @@ -1,44 +1,56 @@ -# 安裝 Coder - -```bash -curl -L https://coder.com/install.sh | sh -``` - -# 修改 Coder 綁定的位址 - -```bash -echo 'export CODER_HTTP_ADDRESS=0.0.0.0:3000' >> ~/.bashrc && source ~/.bashrc -``` - -# 啟動 Coder 服務 - -```bash -systemctl enable --now coder -``` - -# 使用 - -```bash -sudo -u postgres psql -``` - -新建使用者與資料庫 - -```sql -CREATE USER coder WITH PASSWORD 'coder'; - -CREATE DATABASE coder; -``` - -設定資料庫權限 - -```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; -``` \ No newline at end of file +# 簡介 + +Coder 是自架的雲端開發環境平台,可在伺服器上建立並管理遠端開發工作區。本文記錄在 Ubuntu 上安裝 Coder,並使用 PostgreSQL 作為資料庫的步驟。 + +# 安裝 Coder + +透過官方安裝腳本安裝。 + +```bash +curl -L https://coder.com/install.sh | sh +``` + +# 修改 Coder 綁定的位址 + +預設僅綁定本機,改為 `0.0.0.0:3000` 以開放外部連線。 + +```bash +echo 'export CODER_HTTP_ADDRESS=0.0.0.0:3000' >> ~/.bashrc && source ~/.bashrc +``` + +# 啟動服務 + +設為開機自動啟動並立即啟動服務。 + +```bash +systemctl enable --now 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; +``` diff --git a/Service%EF%BC%9ADocker.md b/Service%EF%BC%9ADocker.md index 7804a95..3d088bc 100644 --- a/Service%EF%BC%9ADocker.md +++ b/Service%EF%BC%9ADocker.md @@ -1,39 +1,51 @@ -# 安裝 Docker - -```bash -apt update && apt install -y docker.io docker-compose-v2 -``` - -# 將 Docker 權限賦予目前的使用者 - -```bash -usermod -aG docker $USER -``` - -```bash -newgrp docker -``` - -# 問題一 - -(2015/12/05) PVE 的 CT 安裝後無法啟動容器 - -``` -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 -``` - -加上以下內容 - -``` -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 -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AElasticSearch.md b/Service%EF%BC%9AElasticSearch.md index 2ed6b24..57dcfac 100644 --- a/Service%EF%BC%9AElasticSearch.md +++ b/Service%EF%BC%9AElasticSearch.md @@ -1,225 +1,255 @@ -# 下載 elasticsearch 服務 - -```bash -wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz --no-check-certificate -``` - -# 驗證 elasticsearch 服務壓縮檔 - -```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 -``` - -# 解壓縮 elasticsearch 服務 - -```bash -tar -xzf elasticsearch-8.16.0-linux-x86_64.tar.gz -``` - -先啟動一次服務,讓設定檔完整 - -```bash -elasticsearch -``` - -# 設定 elasticsearch 服務 - -```bash -nano elasticsearch-8.16.0/config/elasticsearch.yml -``` - -(修改以下內容) - -```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 -``` - -## 關閉服務 - -```bash -elasticsearch -d -p pid -``` - -取得 PID - -```bash -pkill -F pid -``` - -## 重設密碼 - -```bash -elasticsearch-reset-password -i -u elastic -``` - -## 產生服務金鑰 for kibana - -```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 -``` - -# 設定服務 - -```bash -sudo nano kibana-8.16.0/config/kibana.yml -``` - -(調整內容) - -```bash -# 在所有網路介面啟動服務 -server.host: "0.0.0.0" - -# 設定 elasticsearch 服務位置 -elasticsearch.hosts: ["http://0.0.0.0:9200"] - -# 設定 elasticsearch 存取金鑰 -elasticsearch.serviceAccountToken: "eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9" -``` - -# kibana 指令 - -## 啟動服務 - -```bash -kibana -``` - -## 安裝 elasticsearch 與 kibana - -## 安裝相依套件 - -```bash -sudo apt install -y apt-transport-https -``` - -## 安裝 elasticsearch 與 kibana 服務 - -```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 -``` - -```bash -sudo apt update && sudo apt upgrade -y && sudo apt install -y elasticsearch kibana -``` - -## 新增 elasticsearch 服務 - -```bash -sudo nano /etc/systemd/system/elasticsearch.service -``` - -``` -[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 服務 - -```bash -sudo nano /etc/systemd/system/kibana.service -``` - -``` -[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 -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AEmby.md b/Service%EF%BC%9AEmby.md index a044a02..d5ef504 100644 --- a/Service%EF%BC%9AEmby.md +++ b/Service%EF%BC%9AEmby.md @@ -1,11 +1,19 @@ -# 下載 Emby - -```bash -wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.8.11.0/emby-server-deb_4.8.11.0_amd64.deb -``` - -# 安裝 Emby - -```bash -dpkg -i emby-server-deb_4.8.11.0_amd64.deb -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AGitea.md b/Service%EF%BC%9AGitea.md index 880673b..5ea3945 100644 --- a/Service%EF%BC%9AGitea.md +++ b/Service%EF%BC%9AGitea.md @@ -1,158 +1,178 @@ -# 安裝相關套件 - -```bash -apt update && apt install -y git -``` - -# 下載 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 使用者 - -```bash -adduser \ - --system \ - --shell /bin/bash \ - --gecos 'Git Version Control' \ - --group \ - --disabled-password \ - --home /home/git \ - git -``` - -# 建立系統資料夾 - -```bash -mkdir -p /var/lib/gitea/custom && mkdir -p /var/lib/gitea/data && mkdir -p /var/lib/gitea/log && mkdir /etc/gitea -``` - -設定資料夾權限 - -```bash -chown -R git:git /var/lib/gitea/ && chmod -R 750 /var/lib/gitea/ -``` - -```bash -chown root:git /etc/gitea && chmod 770 /etc/gitea -``` - -設定 Gitea 工作資料夾 - -```bash -echo 'export GITEA_WORK_DIR=/var/lib/gitea/' >> ~/.bashrc && source ~/.bashrc -``` - -設定 Gitea 服務 - -```bash -nano /etc/systemd/system/gitea.service -``` - -內容如下 - -``` -[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 -``` - -啟動 Gitea 服務 - -```bash -systemctl daemon-reload && systemctl enable gitea && systemctl start gitea && systemctl status gitea -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AGiteaRunner.md b/Service%EF%BC%9AGiteaRunner.md index 66e1fb7..40046db 100644 --- a/Service%EF%BC%9AGiteaRunner.md +++ b/Service%EF%BC%9AGiteaRunner.md @@ -1,61 +1,75 @@ -# 安裝需要的套件 - -```bash -apt update && apt install -y nodejs -``` - -# 下載 Gitea 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 -``` - -將 act_runner 設定為可執行檔 - -```bash -chmod +x /usr/local/bin/runner -``` - -# 註冊 Gitea Runner - -設定參數 - -```bash -runner register -``` - -# 設計 Gitea 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 -``` - -啟動服務 - -```bash -systemctl daemon-reload && systemctl enable runner.service && systemctl start runner.service && systemctl status runner.service -``` - -停止服務 - -```bash -systemctl stop act_runner.service && systemctl disable act_runner.service && rm /etc/systemd/system/act_runner.service -``` \ No newline at end of file +# 簡介 + +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 +``` + +下載後將 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/Service%EF%BC%9AGitlab.md b/Service%EF%BC%9AGitlab.md index 3d31596..bb92a4b 100644 --- a/Service%EF%BC%9AGitlab.md +++ b/Service%EF%BC%9AGitlab.md @@ -1,25 +1,33 @@ -# 安裝相關套件 - -```bash -apt update && apt install -y curl -``` - -透過 Script 安裝套件 - -```bash -curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" | bash -``` - -# 安裝 Gitlab - -```bash -EXTERNAL_URL="https://gitlab.jsc.idv.tw" apt install gitlab-ce -``` - -# 取得 root 密碼 - -需要在 24 小時內變更 - -```bash -cat /etc/gitlab/initial_root_password -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AMeTube.md b/Service%EF%BC%9AMeTube.md index 1280268..2089ecf 100644 --- a/Service%EF%BC%9AMeTube.md +++ b/Service%EF%BC%9AMeTube.md @@ -1,68 +1,86 @@ -# 安裝相關套件 - -```bash -apt update && apt install -y git nodejs npm curl ffmpeg -``` - -# 下載 MeTube - -```bash -git clone https://github.com/alexta69/metube.git -``` - -# 安裝 MeTube - -## 前端 - -```bash -cd ~/metube/ui && npm install && node_modules/.bin/ng build -``` - -## 後端 - -```bash -cd ~/metube && curl -LsSf https://astral.sh/uv/install.sh | sh && uv sync -``` - -設定環境變數 - -```bash -echo 'source $HOME/.local/bin/env' >> ~/.bashrc && source ~/.bashrc -``` - -# 執行 MeTube - -```bash -uv run python3 app/main.py -``` - -# 設計 MeTube 服務 - -```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 -``` - -啟動服務 - -```bash -systemctl daemon-reload && systemctl enable metube.service && systemctl start metube.service -``` - -# 連接埠 8081 \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9APicoClaw.md b/Service%EF%BC%9APicoClaw.md index 69f8b4c..502962c 100644 --- a/Service%EF%BC%9APicoClaw.md +++ b/Service%EF%BC%9APicoClaw.md @@ -1,65 +1,85 @@ -# 安裝語言套件 - -## Go - -```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 -echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc && go version -``` - -## NodeJS && NPM - -```bash -apt update && apt install -y nodejs npm -``` - -# 下載原始碼 - -```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 - -```bash -picoclaw-launcher-tui -``` - -# 快速安裝 - -```bash -wget https://github.com/sipeed/picoclaw/releases/download/v0.2.6/picoclaw_x86_64.deb && dpkg -i picoclaw_x86_64.deb -``` - -# 啟動 WebUI for Desktop - -```bash -picoclaw-launcher -public -``` \ No newline at end of file +# 簡介 + +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 +``` + +將 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 +``` + +# 啟動 WebUI for Desktop + +適合桌面環境使用的網頁介面,`-public` 開放外部連線。 + +```bash +picoclaw-launcher -public +``` diff --git a/Service%EF%BC%9ARedis.md b/Service%EF%BC%9ARedis.md index cc9c9a2..ec148be 100644 --- a/Service%EF%BC%9ARedis.md +++ b/Service%EF%BC%9ARedis.md @@ -1,33 +1,47 @@ -# 安裝相依套件 - -```bash -apt update && apt install -y lsb-release curl gpg -``` - -# 安裝 Redis 簽章 - -```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 套件庫 - -```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 -``` - -# 啟動 Redis 伺服器 - -```bash -systemctl enable redis-server && systemctl start redis-server && systemctl status redis-server -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9ATraefik.md b/Service%EF%BC%9ATraefik.md index 4621c31..38a5c29 100644 --- a/Service%EF%BC%9ATraefik.md +++ b/Service%EF%BC%9ATraefik.md @@ -1,212 +1,228 @@ -# 下載 Traefik 壓縮檔 - -```bash -wget https://github.com/traefik/traefik/releases/download/v3.7.4/traefik_v3.7.4_linux_amd64.tar.gz -``` - -# 解壓縮 - -```bash -tar zxvf traefik_v3.7.4_linux_amd64.tar.gz -C /usr/local/bin/ traefik -``` - -# 設計 Traefik 服務 - -```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 -``` - -啟動服務 - -```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 -``` - -範例設定檔 - -```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 -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AVS-Code.md b/Service%EF%BC%9AVS-Code.md index 0dce8a7..dd543df 100644 --- a/Service%EF%BC%9AVS-Code.md +++ b/Service%EF%BC%9AVS-Code.md @@ -1,23 +1,35 @@ -更新套件 - -```bash -apt update && apt install -y curl -``` - -安裝 VS Code - -```bash -curl -fsSL https://code-server.dev/install.sh | sh -``` - -啟動服務 - -```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 -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9AezBookkeeping.md b/Service%EF%BC%9AezBookkeeping.md index 5f85d1f..9f5e2ef 100644 --- a/Service%EF%BC%9AezBookkeeping.md +++ b/Service%EF%BC%9AezBookkeeping.md @@ -1,66 +1,78 @@ -下載 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 服務 - -```bash -nano /etc/systemd/system/ezbookkeeping.service -``` - -服務檔內容 - -``` -[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 -``` - -啟動服務 - -```bash -systemctl daemon-reload && systemctl enable ezbookkeeping.service && systemctl start ezbookkeeping.service && systemctl status ezbookkeeping.service -``` - -# 使用 - -```bash -sudo -u postgres psql -``` - -新建使用者與資料庫 - -```sql -CREATE USER ezbookkeeping WITH PASSWORD 'ezbookkeeping'; - -CREATE DATABASE ezbookkeeping; -``` - -設定資料庫權限 - -```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; -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9Ak3d.md b/Service%EF%BC%9Ak3d.md index 4d687e2..5f7384b 100644 --- a/Service%EF%BC%9Ak3d.md +++ b/Service%EF%BC%9Ak3d.md @@ -1,29 +1,39 @@ -# 安裝 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 個代理 - -```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 -``` \ No newline at end of file +# 簡介 + +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/Service%EF%BC%9Anetplan.md b/Service%EF%BC%9Anetplan.md index bf029ed..02093b9 100644 --- a/Service%EF%BC%9Anetplan.md +++ b/Service%EF%BC%9Anetplan.md @@ -1,42 +1,52 @@ -# 多網路權重設定 - -雙 DHCP - -```yaml -network: - version: 2 - ethernets: - eth0: - dhcp4: true - dhcp4-overrides: - route-metric: 200 - eth1: - dhcp4: true - dhcp4-overrides: - route-metric: 100 -``` - -靜態+動態 - -```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 -``` \ No newline at end of file +# 簡介 + +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 +```