feat(claude): 整理所有文件格式

Jeffery
2026-06-11 10:03:47 +08:00
parent c2a2c245f3
commit 13b4edea57
25 changed files with 1883 additions and 1534 deletions
@@ -1,3 +1,11 @@
```bash # 簡介
sudo timedatectl set-timezone Asia/Taipei
``` Ubuntu 預設時區通常為 UTC,會導致系統時間與台灣本地時間相差 8 小時。以下指令將系統時區設定為台北(Asia/Taipei)。
# 設定時區
```bash
sudo timedatectl set-timezone Asia/Taipei
```
設定後可用 `timedatectl` 確認時區是否已套用。
@@ -1,97 +1,120 @@
# Step 1. 修改引導設定檔 # 簡介
```bash PCIe 直通(Passthrough)可讓 PVE 上的虛擬機直接獨佔某個 PCIe 裝置(例如顯示卡、Thunderbolt 控制器)。重點是先在主機啟用 IOMMU,再以 `vfio-pci` 驅動接管裝置、阻止宿主機使用它,最後將裝置指派給虛擬機。本文以 Thunderbolt 控制器為例。
nano /etc/default/grub
``` # Step 1. 修改引導設定檔
(找到 GRUB_CMDLINE_LINUX_DEFAULT 行,依據 CPU 類型加入參數) 啟用 IOMMU 需在核心開機參數加入對應設定。
- Intel CPUintel_iommu=on iommu=pt ```bash
nano /etc/default/grub
(範例:``` GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt" ```) ```
- AMD CPUamd_iommu=on iommu=pt 找到 `GRUB_CMDLINE_LINUX_DEFAULT` 行,依據 CPU 類型加入參數:
(更新 Grub 引導並重啟速主機) - Intel CPU`intel_iommu=on iommu=pt`
- AMD CPU`amd_iommu=on iommu=pt`
```bash
update-grub && reboot Intel 範例)
```
```
(重啟後,輸入 ``` dmesg | grep -e DMAR -e IOMMU ```。若看到 ``` IOMMU enabled ``` 代表啟用成功) GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"
```
# Step 2. 載入 VFIO 核心模組
更新 GRUB 引導並重啟主機。
```bash
nano /etc/modules ```bash
``` update-grub && reboot
```
(在檔案末尾加上以下四行)
重啟後執行下列指令驗證,若看到 `IOMMU enabled` 代表啟用成功。
```
vfio ```bash
vfio_iommu_type1 dmesg | grep -e DMAR -e IOMMU
vfio_pci ```
vfio_virqfd
``` # Step 2. 載入 VFIO 核心模組
# Step 3. 尋找控制器 ID (以 Thunderbolt 為例) 讓系統開機時自動載入 VFIO 相關模組。
找出控制器的 PCI 位址與硬體 ID ```bash
nano /etc/modules
```bash ```
lspci -nnk | grep -i thunderbolt
``` 在檔案末尾加上以下四行:
- PCI 位址:例如 ``` 00:0d.0 ``` ```
- 硬體 ID:例如 ``` 8086:9a1b ``` vfio
vfio_iommu_type1
# Step 4. 阻斷宿主機驅動 vfio_pci
vfio_virqfd
為了防止 PVE 宿主機搶先佔用控制器,必須強迫它使用 ``` vfio-pci ``` 驅動 ```
```bash # Step 3. 尋找控制器 ID (以 Thunderbolt 為例)
nano /etc/modprobe.d/vfio.conf
``` 找出要直通裝置的 PCI 位址與硬體 ID。
(寫入以下內容) ```bash
lspci -nnk | grep -i thunderbolt
```bash ```
softdep thunderbolt pre: vfio-pci
- PCI 位址:例如 `00:0d.0`
options vfio-pci ids=8086:9a1b,8086:9a1d disable_vga=1 - 硬體 ID:例如 `8086:9a1b`
```
# Step 4. 阻斷宿主機驅動
(更新 initramfs 核心映像並重啟速主機)
為了防止 PVE 宿主機搶先佔用控制器,必須強制它改用 `vfio-pci` 驅動。
```bash
update-initramfs -u -k all && reboot ```bash
``` nano /etc/modprobe.d/vfio.conf
```
(重啟後,輸入 ``` lspci -nnk -s 00:0d.0 ```。若看到 ``` Kernel driver in use: vfio-pci ``` 代表隔離成功)
寫入以下內容(`ids=` 後填入 Step 3 取得的硬體 ID):
# Step 5. 將裝置新增至虛擬機
```bash
- 位置:硬體 > 新增 > PCI 裝置 softdep thunderbolt pre: vfio-pci
- 原始裝置:選取控制器位址
- [v] All Functions options vfio-pci ids=8086:9a1b,8086:9a1d disable_vga=1
- [v] ROM-Bar ```
- [v] PCI-Express
更新 initramfs 核心映像並重啟主機。
# PVE 可能是使用 systemd-boot 而非 GRUB
```bash
```bash update-initramfs -u -k all && reboot
nano /etc/kernel/cmdline ```
```
重啟後執行下列指令驗證,若看到 `Kernel driver in use: vfio-pci` 代表隔離成功。
(檢查檔案內是否有以下內容,如果沒有,則直接加在原本內容的尾端)
```bash
``` lspci -nnk -s 00:0d.0
intel_iommu=on iommu=pt ```
```
# Step 5. 將裝置新增至虛擬機
(讓核心參數生效)
在 PVE 介面為虛擬機加入 PCI 裝置:
```bash
proxmox-boot-tool refresh - 位置:硬體 > 新增 > 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
```
@@ -1,67 +1,85 @@
# 1. 確認磁碟大小 # 簡介
```bash 當虛擬機磁碟容量在外部(例如 PVE)擴充後,Ubuntu 內部不會自動使用新空間。本文記錄將新增空間一路套用到 LVM 邏輯磁區的流程:調整分割區 → 擴充 PV → 擴充 LV → 擴充檔案系統。
lsblk
``` > 注意:`fdisk` 刪除並重建分割區具風險,操作前請先備份重要資料,並確認起始磁區(First sector)維持原值。
```bash # 1. 確認磁碟大小
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 64G 0 disk 先用 `lsblk` 查看目前磁碟與分割狀況。
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 2G 0 part /boot ```bash
└─sda3 8:3 0 30G 0 part lsblk
└─ubuntu--vg-ubuntu--lv 252:0 0 30G 0 lvm / ```
sr0 11:0 1 1024M 0 rom
``` 以下範例中,`sda` 已擴充為 64G,但分割區 `sda3` 與其上的 LVM 仍只有 30G。
# 2. 調整硬碟大小 ```bash
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
```bash sda 8:0 0 64G 0 disk
sudo fdisk /dev/sda ├─sda1 8:1 0 1M 0 part
``` ├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 30G 0 part
```bash └─ubuntu--vg-ubuntu--lv 252:0 0 30G 0 lvm /
Command (m for help): p sr0 11:0 1 1024M 0 rom
Device Start End Sectors Size Type ```
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem # 2. 調整硬碟大小
/dev/sda3 4198400 67108830 62910431 30G Linux filesystem
`fdisk` 刪除舊的 `sda3` 並以相同起始磁區重建為較大的分割區。**刪除分割區時務必選擇保留(N)LVM2 簽章**,否則會破壞磁區。
Command (m for help): d
Partition number (1-3, default 3): ```bash
Partition 3 has been deleted. sudo fdisk /dev/sda
```
Command (m for help): n
Partition number (3-128, default 3): 操作流程如下(`p` 檢視、`d` 刪除、`n` 新增、`w` 寫入):
First sector (3719168-46137310, default 3719168):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (3719168-46137310, default 46135295): ```bash
Created a new partition 3 of type 'Linux filesystem' and of size 62 GiB. Command (m for help): p
Partition #3 contains a LVM2_member signature. Device Start End Sectors Size Type
Do you want to remove the signature? [Y]es/[N]o: N /dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
Command (m for help): p /dev/sda3 4198400 67108830 62910431 30G Linux filesystem
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot Command (m for help): d
/dev/sda2 4096 4198399 4194304 2G Linux filesystem Partition number (1-3, default 3):
/dev/sda3 4198400 124217694 130019295 62G Linux filesystem Partition 3 has been deleted.
Command (m for help): w Command (m for help): n
The partition table has been altered. Partition number (3-128, default 3):
Syncing disks. 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.
# 3. 調整 PV 大小 Partition #3 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: N
```bash
sudo pvresize /dev/sda3 Command (m for help): p
``` Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
# 4. 調整 LV 大小 /dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 124217694 130019295 62G Linux filesystem
```bash
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv Command (m for help): w
``` The partition table has been altered.
Syncing disks.
```bash ```
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
``` # 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
```
+55 -49
@@ -1,49 +1,55 @@
這個問題是因為Ubuntu缺少所需的憑證,透過以下步驟可以解決這個問題。 # 簡介
# 1. 查詢缺少的憑證 當網路環境中有防火牆或代理(例如 Fortinet)對 HTTPS 連線做 SSL 攔截時,Ubuntu 會因為缺少對應的根憑證而出現 x509 憑證錯誤(例如 `docker pull` 失敗)。解決方式是把攔截端的憑證加入系統信任清單。
```bash # 1. 查詢缺少的憑證
openssl s_client -connect registry-1.docker.io:443 -showcerts
``` 連線到目標站台並列出完整憑證鏈。
複製憑證鏈中,最後的憑證金鑰,內容如下(請自己執行,因為憑證可能更新,以下金鑰複製於2025/03/24) ```bash
openssl s_client -connect registry-1.docker.io:443 -showcerts
```bash ```
-----BEGIN CERTIFICATE-----
MIID5jCCAs6gAwIBAgIIIXGGV4x82u0wDQYJKoZIhvcNAQELBQAwgakxCzAJBgNV 複製憑證鏈中最後的憑證金鑰。以下內容請自行執行取得,因為憑證可能更新(以下金鑰複製於 2025/03/24):
BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlTdW5ueXZhbGUx
ETAPBgNVBAoMCEZvcnRpbmV0MR4wHAYDVQQLDBVDZXJ0aWZpY2F0ZSBBdXRob3Jp ```bash
dHkxGTAXBgNVBAMMEEZHNkgxRVRCMjE5MDAzMjcxIzAhBgkqhkiG9w0BCQEWFHN1 -----BEGIN CERTIFICATE-----
cHBvcnRAZm9ydGluZXQuY29tMB4XDTIxMDgyNjIyNTUwMFoXDTMxMDgyNzIyNTUw MIID5jCCAs6gAwIBAgIIIXGGV4x82u0wDQYJKoZIhvcNAQELBQAwgakxCzAJBgNV
MFowgakxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQH BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlTdW5ueXZhbGUx
DAlTdW5ueXZhbGUxETAPBgNVBAoMCEZvcnRpbmV0MR4wHAYDVQQLDBVDZXJ0aWZp ETAPBgNVBAoMCEZvcnRpbmV0MR4wHAYDVQQLDBVDZXJ0aWZpY2F0ZSBBdXRob3Jp
Y2F0ZSBBdXRob3JpdHkxGTAXBgNVBAMMEEZHNkgxRVRCMjE5MDAzMjcxIzAhBgkq dHkxGTAXBgNVBAMMEEZHNkgxRVRCMjE5MDAzMjcxIzAhBgkqhkiG9w0BCQEWFHN1
hkiG9w0BCQEWFHN1cHBvcnRAZm9ydGluZXQuY29tMIIBIjANBgkqhkiG9w0BAQEF cHBvcnRAZm9ydGluZXQuY29tMB4XDTIxMDgyNjIyNTUwMFoXDTMxMDgyNzIyNTUw
AAOCAQ8AMIIBCgKCAQEAr36+xa3QAC3O3GYUghMwnwLY/oJL9S1fG7jHmxsdlhZX MFowgakxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQH
k+4kGSnaFDDAgUM1D8WfM6eeojL2qK82TQF4eRRYGsb9Ls/lHT4O7iDOppF66h1E DAlTdW5ueXZhbGUxETAPBgNVBAoMCEZvcnRpbmV0MR4wHAYDVQQLDBVDZXJ0aWZp
wHuSC6WYT/axv3dyfRkC3/Ic+NGmfn1EOY+XtVdf4ZCSLL/MFAcD5A8Kjxa/wcN0 Y2F0ZSBBdXRob3JpdHkxGTAXBgNVBAMMEEZHNkgxRVRCMjE5MDAzMjcxIzAhBgkq
1xhJMBop5hEENXxoOnc5UJKlyEQYhnpBG4J8cdceRwWTGZmCGkNgUAeivI/amADh hkiG9w0BCQEWFHN1cHBvcnRAZm9ydGluZXQuY29tMIIBIjANBgkqhkiG9w0BAQEF
Ma/StLLxGqKW4zneM4db3vQJexmI+pdeM+UoUDZ++hwWF75byevntNFfYzGYvQnZ AAOCAQ8AMIIBCgKCAQEAr36+xa3QAC3O3GYUghMwnwLY/oJL9S1fG7jHmxsdlhZX
Y1sWyph3uhyVgkx8zylFOeJKGTyCL5gbw66AaTlmSQIDAQABoxAwDjAMBgNVHRME k+4kGSnaFDDAgUM1D8WfM6eeojL2qK82TQF4eRRYGsb9Ls/lHT4O7iDOppF66h1E
BTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQATzLjdJALCzxafMZCAIGi/ZHMBUt3X wHuSC6WYT/axv3dyfRkC3/Ic+NGmfn1EOY+XtVdf4ZCSLL/MFAcD5A8Kjxa/wcN0
HV7jDmjvNGBWyaHR9n/VsfzIojg5Eju10FSB0tBOvRwJT2kzwzXlLVzRQKeKwWbx 1xhJMBop5hEENXxoOnc5UJKlyEQYhnpBG4J8cdceRwWTGZmCGkNgUAeivI/amADh
VxMp+gdBxSaW58u5aJKQTW0FnZQQqUtdsLw+uCCpHIxZuGSOZDzXIm2Gyfq37oBu Ma/StLLxGqKW4zneM4db3vQJexmI+pdeM+UoUDZ++hwWF75byevntNFfYzGYvQnZ
VjWDXFP8RLqGMZFSIapN1i02yMOD2IHfUqBngbpMJxvZa4oHOoVTKW9BkgENyRh+ Y1sWyph3uhyVgkx8zylFOeJKGTyCL5gbw66AaTlmSQIDAQABoxAwDjAMBgNVHRME
XBJuzcWXbsmPKucD5O7CP+n9flP4AAz1BIrHD93ychm5rqAl5gvYD5bGDAdshWnC BTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQATzLjdJALCzxafMZCAIGi/ZHMBUt3X
ng6AGIc94BzGo10X+Ly1YK3zpPiiMx6xx2LNX3XyLUDL3QKMqVJi0G8u HV7jDmjvNGBWyaHR9n/VsfzIojg5Eju10FSB0tBOvRwJT2kzwzXlLVzRQKeKwWbx
-----END CERTIFICATE----- VxMp+gdBxSaW58u5aJKQTW0FnZQQqUtdsLw+uCCpHIxZuGSOZDzXIm2Gyfq37oBu
``` VjWDXFP8RLqGMZFSIapN1i02yMOD2IHfUqBngbpMJxvZa4oHOoVTKW9BkgENyRh+
XBJuzcWXbsmPKucD5O7CP+n9flP4AAz1BIrHD93ychm5rqAl5gvYD5bGDAdshWnC
# 2. 查詢憑證存放的位置 ng6AGIc94BzGo10X+Ly1YK3zpPiiMx6xx2LNX3XyLUDL3QKMqVJi0G8u
-----END CERTIFICATE-----
```bash ```
curl -k -v https://registry-1.docker.io/v2/
``` # 2. 查詢憑證存放的位置
Ubuntu 24.04 存放於以下位置 確認系統信任憑證的存放路徑。
```bash ```bash
/etc/ssl/certs/ca-certificates.crt curl -k -v https://registry-1.docker.io/v2/
``` ```
將剛剛查詢的憑證金鑰加入到 ca-certificates.crt 檔案中的最後。 Ubuntu 24.04 存放於以下位置:
```bash
/etc/ssl/certs/ca-certificates.crt
```
將剛剛查詢到的憑證金鑰,貼到 `ca-certificates.crt` 檔案的最後即可。
+27 -17
@@ -1,17 +1,27 @@
# 1. 列出所有分區 # 簡介
```bash 開機時若檔案系統毀損,Ubuntu 會中斷在 BusyBoxinitramfs)救援環境,停在 `(initramfs)` 提示字元。本文記錄找出根磁區並修復檔案系統,使系統恢復正常開機的步驟。
blkid
``` # 1. 列出所有分區
# 2. 修復系統磁區 找出根檔案系統所在的磁區。
```bash ```bash
fsck -y /dev/mapper/ubuntu--vg-ubuntu--lv blkid
``` ```
# 3. 離開後,自動進入系統 # 2. 修復系統磁區
```bash 對根磁區執行檔案系統檢查與自動修復(`-y` 表示對所有提示自動回答 yes)。
exit
``` ```bash
fsck -y /dev/mapper/ubuntu--vg-ubuntu--lv
```
# 3. 離開後,自動進入系統
修復完成後離開 BusyBox,系統會繼續完成開機。
```bash
exit
```
+43 -31
@@ -1,31 +1,43 @@
# 1. 取消註解 DNSStubListener 並設定為 no # 簡介
```bash Ubuntu 內建的 `systemd-resolved` 會在本機 `127.0.0.53:53` 啟動 DNS stub listener,導致要自行架設 DNS 服務(如 dnsmasq、Pi-hole)時 53 埠被佔用而無法啟動。本文記錄關閉 stub listener、釋放 53 埠的步驟。
sudo nano /etc/systemd/resolved.conf
``` # 1. 取消註解 DNSStubListener 並設定為 no
``` 編輯 systemd-resolved 設定檔。
[Resolve]
#DNS= ```bash
#FallbackDNS= sudo nano /etc/systemd/resolved.conf
#Domains= ```
#LLMNR=no
#MulticastDNS=no `DNSStubListener` 取消註解並設為 `no`
#DNSSEC=no
#DNSOverTLS=no ```
#Cache=yes [Resolve]
DNSStubListener=no #DNS=
#ReadEtcHosts=yes #FallbackDNS=
``` #Domains=
#LLMNR=no
# 2. 重新建立捷徑 #MulticastDNS=no
#DNSSEC=no
```bash #DNSOverTLS=no
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf #Cache=yes
``` DNSStubListener=no
#ReadEtcHosts=yes
# 3. 重新啟動系統服務 ```
```bash # 2. 重新建立捷徑
sudo systemctl restart systemd-resolved
``` `/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
```
+34 -24
@@ -1,24 +1,34 @@
# 安裝 PostgreSQL # 簡介
```bash PostgreSQL 是常用的開源關聯式資料庫。本文記錄在 Ubuntu 上安裝 PostgreSQL,並開放特定主機與使用者外部連線的步驟。
apt update && apt install -y postgresql
``` # 安裝 PostgreSQL
# 允許外部連線 ```bash
apt update && apt install -y postgresql
```bash ```
nano /etc/postgresql/17/main/pg_hba.conf
``` # 允許外部連線
允許來自 `192.168.230.221` 連線的 `gitea` 使用者可以存取 編輯用戶端認證設定檔 `pg_hba.conf`(路徑中的 `17` 為 PostgreSQL 主版本號,請依實際版本調整)。
```ini ```bash
... nano /etc/postgresql/17/main/pg_hba.conf
host gitea gitea 192.168.230.221/24 md5 ```
```
加入下列規則,允許來自 `192.168.230.221` 網段的 `gitea` 使用者,以 md5 密碼驗證存取 `gitea` 資料庫。
重啟服務
```ini
```bash ...
systemctl restart postgresql && systemctl status postgresql host gitea gitea 192.168.230.221/24 md5
``` ```
> 注意:另需確認 `postgresql.conf` 的 `listen_addresses` 已開放對應介面(例如設為 `'*'`),外部連線才會生效。
# 重啟服務
讓設定生效並檢視狀態。
```bash
systemctl restart postgresql && systemctl status postgresql
```
+113 -95
@@ -1,95 +1,113 @@
# 安裝相關套件 # 簡介
```bash 本文記錄在 Ubuntu 上透過 Microsoft 官方套件庫安裝 SQL Server 2022 的步驟,包含基本設定(密碼、代理、定序),以及命令列工具 sqlcmd 的安裝。
apt update && apt install -y curl
``` # 安裝相關套件
# 安裝加密簽證 加入套件庫過程需要 curl。
```bash ```bash
curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc apt update && apt install -y curl
``` ```
# 安裝套件列表 # 安裝加密簽證
```bash 下載並信任 Microsoft 的 GPG 金鑰,供 APT 驗證套件來源。
curl -fsSL https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list | tee /etc/apt/sources.list.d/mssql-server-2022.list
``` ```bash
curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
# 安裝 SQL Server ```
```bash # 安裝套件列表
apt update && apt install -y mssql-server
``` 加入 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
```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
# 設定 SQL Server ```bash
apt update && apt install -y mssql-server
## 密碼 ```
```bash # 安裝缺少的套件
/opt/mssql/bin/mssql-conf setup
``` 若安裝過程缺少 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
啟用代理後重啟服務 ```
```bash # 設定 SQL Server
/opt/mssql/bin/mssql-conf set sqlagent.enabled true && systemctl restart mssql-server
``` ## 密碼
## 定序 執行初始設定精靈,選擇版本並設定 SA 密碼。
停止服務 ```bash
/opt/mssql/bin/mssql-conf setup
```bash ```
systemctl stop mssql-server
``` ## 代理
設定定序 啟用 SQL Server Agent(排程作業)後重啟服務。
```bash ```bash
/opt/mssql/bin/mssql-conf set-collation /opt/mssql/bin/mssql-conf set sqlagent.enabled true && systemctl restart mssql-server
``` ```
* Chinese_Taiwan_Stroke_CI_AS:以筆劃排序,大小寫不區分 (Case Insensitive),重音符號區分 (Accent Sensitive),適合一般文字搜尋。 ## 定序
* Chinese_Taiwan_Stroke_CS_AS:以筆劃排序,大小寫區分 (Case Sensitive),重音符號區分,適合需要區分大小寫的場景 設定定序前須先停止服務
啟動服務 ```bash
systemctl stop mssql-server
```bash ```
systemctl start mssql-server
``` 設定定序。
# 連接埠 1433 ```bash
/opt/mssql/bin/mssql-conf set-collation
# 安裝 sqlcmd 加密簽證 ```
```bash * Chinese_Taiwan_Stroke_CI_AS:以筆劃排序,大小寫不區分 (Case Insensitive),重音符號區分 (Accent Sensitive),適合一般文字搜尋。
curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc
``` * Chinese_Taiwan_Stroke_CS_AS:以筆劃排序,大小寫區分 (Case Sensitive),重音符號區分,適合需要區分大小寫的場景。
# 安裝 sqlcmd 套件列表 設定完成後重新啟動服務。
```bash ```bash
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list systemctl start mssql-server
``` ```
# 安裝 sqlcmd # 連接埠 1433
```bash # 安裝 sqlcmd
apt update && apt install -y mssql-tools18 unixodbc-dev
``` sqlcmd 是 SQL Server 的命令列查詢工具。
設定環境變數 ## 安裝 sqlcmd 加密簽證
```bash ```bash
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc && source ~/.bashrc 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
```
@@ -1,35 +1,51 @@
# 1. 修復損壞的 Kernal # 簡介
```bash 當核心(Kernel)升級不完整或映像檔損壞時,開機會出現 `Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block` 而無法掛載根檔案系統。本文記錄修復損壞套件、移除問題核心並重新安裝正常核心的步驟。
sudo apt -f install
``` > 需在可開機的環境(例如選擇舊版核心開機,或進入救援模式)下執行以下指令。
# 2. 列出所有 Kernal # 1. 修復損壞的 Kernel
```bash 修復先前安裝中斷、相依未滿足的套件。
dpkg --list | grep linux-image
``` ```bash
sudo apt -f install
# 3. 移除低版本到無法移除 ```
```bash # 2. 列出所有 Kernel
sudo apt purge -y linux-image-x.xx.x-xxx-generic
``` 列出系統中已安裝的核心映像。
# 4. 更新 GRUB 2 ```bash
dpkg --list | grep linux-image
```bash ```
sudo update-grub2
``` # 3. 移除低版本到無法移除
# 5. 更新 Kernal 到現在的版本 逐一移除有問題的舊版核心(將 `x.xx.x-xxx` 換成實際版本號),直到無法再移除為止。
```bash ```bash
sudo apt update && sudo apt upgrade -y sudo apt purge -y linux-image-x.xx.x-xxx-generic
``` ```
# 6. 試著重啟看看是否正常 # 4. 更新 GRUB 2
```bash 重新產生開機選單。
sudo reboot
``` ```bash
sudo update-grub2
```
# 5. 更新 Kernel 到現在的版本
更新套件並重新安裝最新核心。
```bash
sudo apt update && sudo apt upgrade -y
```
# 6. 試著重啟看看是否正常
```bash
sudo reboot
```
+27 -15
@@ -1,15 +1,27 @@
```bash # 簡介
# /etc/systemd/system/
本文提供以 systemd 部署 ASP.NET(.NET)應用程式的服務檔範本。將大括號標記的欄位替換為實際值即可:
[Unit]
Description=..write something about project - `{project_name}`:專案(與 dll)名稱
- `{environment_name}`:執行環境,例如 `Production``Staging`
[Service] - `{url}`:服務監聽的位址與連接埠,例如 `http://0.0.0.0:5000`
Type=simple
WorkingDirectory=/home/gitlab-runner/deploy/{project_name} # 建立 ASP.NET 服務
ExecStart=/usr/bin/dotnet /home/gitlab-runner/deploy/{project_name}/{project_name}.dll --environment {environment_name} --urls={url}
Restart=always 建立服務設定檔(路徑:`/etc/systemd/system/`),內容如下:
[Install] ```ini
WantedBy=multi-user.target # /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
```
+56 -44
@@ -1,44 +1,56 @@
# 安裝 Coder # 簡介
```bash Coder 是自架的雲端開發環境平台,可在伺服器上建立並管理遠端開發工作區。本文記錄在 Ubuntu 上安裝 Coder,並使用 PostgreSQL 作為資料庫的步驟。
curl -L https://coder.com/install.sh | sh
``` # 安裝 Coder
# 修改 Coder 綁定的位址 透過官方安裝腳本安裝。
```bash ```bash
echo 'export CODER_HTTP_ADDRESS=0.0.0.0:3000' >> ~/.bashrc && source ~/.bashrc curl -L https://coder.com/install.sh | sh
``` ```
# 啟動 Coder 服務 # 修改 Coder 綁定的位址
```bash 預設僅綁定本機,改為 `0.0.0.0:3000` 以開放外部連線。
systemctl enable --now coder
``` ```bash
echo 'export CODER_HTTP_ADDRESS=0.0.0.0:3000' >> ~/.bashrc && source ~/.bashrc
# 使用 ```
```bash # 啟動服務
sudo -u postgres psql
``` 設為開機自動啟動並立即啟動服務。
新建使用者與資料庫 ```bash
systemctl enable --now coder
```sql ```
CREATE USER coder WITH PASSWORD 'coder';
# 設定資料庫
CREATE DATABASE coder;
``` 以 postgres 系統帳號進入 PostgreSQL 互動介面。
設定資料庫權限 ```bash
sudo -u postgres psql
```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 ```sql
ALTER SCHEMA public OWNER TO coder; CREATE USER coder WITH PASSWORD 'coder';
-- 3. Ensure the user has create permissions (Crucial for Postgres 15+) CREATE DATABASE coder;
GRANT USAGE, CREATE ON SCHEMA public TO 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;
```
+51 -39
@@ -1,39 +1,51 @@
# 安裝 Docker # 簡介
```bash Docker 是容器化平台,用於封裝與執行應用程式。本文記錄在 Ubuntu 上安裝 Docker 與 Docker Compose 的步驟,以及在 PVE 容器(CT)中常見的問題排解。
apt update && apt install -y docker.io docker-compose-v2
``` # 安裝 Docker
# 將 Docker 權限賦予目前的使用者 安裝 Docker 引擎與 Docker Compose v2 外掛。
```bash ```bash
usermod -aG docker $USER apt update && apt install -y docker.io docker-compose-v2
``` ```
```bash # 將 Docker 權限賦予目前的使用者
newgrp docker
``` 將目前使用者加入 docker 群組,之後即可免 sudo 操作 Docker。
# 問題一 ```bash
usermod -aG docker $USER
(2015/12/05) PVE 的 CT 安裝後無法啟動容器 ```
``` 不重新登入即套用新群組(僅對當前 shell 生效)。
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
``` ```bash
newgrp docker
## 解決方法 ```
在 PVE 的 CT 設定檔中加上相容設定 # 常見問題
``` ## 問題一:PVE 的 CT 安裝後無法啟動容器
nano /etc/pve/lxc/(CT ID).conf
``` (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
``` ```
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
``` 在 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
```
+255 -225
@@ -1,225 +1,255 @@
# 下載 elasticsearch 服務 # 簡介
```bash Elasticsearch 是分散式搜尋與分析引擎,Kibana 則是它的視覺化前端。本文記錄兩種在 Ubuntu 上部署兩者的方式:方法一使用官方壓縮檔手動安裝,方法二使用官方 APT 套件庫安裝。
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz --no-check-certificate
``` ---
# 驗證 elasticsearch 服務壓縮檔 # 方法一:使用壓縮檔安裝
```bash ## 下載 Elasticsearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz.sha512 --no-check-certificate
``` ```bash
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz --no-check-certificate
```bash ```
shasum -a 512 -c elasticsearch-8.16.0-linux-x86_64.tar.gz.sha512
``` ## 驗證壓縮檔
# 解壓縮 elasticsearch 服務 下載官方提供的 SHA512 校驗檔。
```bash ```bash
tar -xzf elasticsearch-8.16.0-linux-x86_64.tar.gz wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.0-linux-x86_64.tar.gz.sha512 --no-check-certificate
``` ```
先啟動一次服務,讓設定檔完整 比對壓縮檔雜湊值,確認檔案完整未被竄改。
```bash ```bash
elasticsearch shasum -a 512 -c elasticsearch-8.16.0-linux-x86_64.tar.gz.sha512
``` ```
# 設定 elasticsearch 服務 ## 解壓縮
```bash ```bash
nano elasticsearch-8.16.0/config/elasticsearch.yml tar -xzf elasticsearch-8.16.0-linux-x86_64.tar.gz
``` ```
(修改以下內容) ## 設定 Elasticsearch
```yaml 先啟動一次服務,讓系統自動產生完整的預設設定檔。
# 在全部網路介面啟動服務
network.host: 0.0.0.0 ```bash
elasticsearch
# 改走 http 協定 ```
xpack.security.http.ssl:
enabled: false 編輯設定檔。
# 允許所有介面的網路連線 ```bash
http.host: 0.0.0.0 nano elasticsearch-8.16.0/config/elasticsearch.yml
```
# 允許所有介面的叢集連線
transport.host: 0.0.0.0 修改以下內容(開放各網路介面連線、停用 HTTPS 改走 HTTP):
```
```yaml
# elasticsearch 指令 # 在全部網路介面啟動服務
network.host: 0.0.0.0
## 啟動服務
# 改走 http 協定
```bash xpack.security.http.ssl:
elasticsearch enabled: false
```
# 允許所有介面的網路連線
## 關閉服務 http.host: 0.0.0.0
```bash # 允許所有介面的叢集連線
elasticsearch -d -p pid transport.host: 0.0.0.0
``` ```
取得 PID ## Elasticsearch 常用指令
```bash ### 啟動服務
pkill -F pid
``` ```bash
elasticsearch
## 重設密碼 ```
```bash ### 關閉服務
elasticsearch-reset-password -i -u elastic
``` 以背景模式啟動並記錄 PID。
## 產生服務金鑰 for kibana ```bash
elasticsearch -d -p pid
```bash ```
elasticsearch-create-enrollment-token -s kibana
``` 依 PID 關閉服務。
(輸出) ```bash
pkill -F pid
```bash ```
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9
``` ### 重設 elastic 帳號密碼
# 下載 kibana 服務 ```bash
elasticsearch-reset-password -i -u elastic
```bash ```
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.16.0-linux-x86_64.tar.gz --no-check-certificate
``` ### 產生 Kibana 服務金鑰
# 驗證 kibana 服務壓縮檔 供 Kibana 連線 Elasticsearch 使用。
```bash ```bash
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.16.0-linux-x86_64.tar.gz.sha512 --no-check-certificate elasticsearch-create-enrollment-token -s kibana
``` ```
```bash 輸出範例:
shasum -a 512 -c kibana-8.16.0-linux-x86_64.tar.gz.sha512
``` ```bash
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9
# 解壓縮 kibana 服務 ```
```bash ## 下載 Kibana
tar -xzf kibana-8.16.0-linux-x86_64.tar.gz
``` ```bash
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.16.0-linux-x86_64.tar.gz --no-check-certificate
# 設定服務 ```
```bash ## 驗證 Kibana 壓縮檔
sudo nano kibana-8.16.0/config/kibana.yml
``` ```bash
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.16.0-linux-x86_64.tar.gz.sha512 --no-check-certificate
(調整內容) ```
```bash ```bash
# 在所有網路介面啟動服務 shasum -a 512 -c kibana-8.16.0-linux-x86_64.tar.gz.sha512
server.host: "0.0.0.0" ```
# 設定 elasticsearch 服務位置 ## 解壓縮 Kibana
elasticsearch.hosts: ["http://0.0.0.0:9200"]
```bash
# 設定 elasticsearch 存取金鑰 tar -xzf kibana-8.16.0-linux-x86_64.tar.gz
elasticsearch.serviceAccountToken: "eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9" ```
```
## 設定 Kibana
# kibana 指令
```bash
## 啟動服務 sudo nano kibana-8.16.0/config/kibana.yml
```
```bash
kibana 調整以下內容(開放外部連線、指向 Elasticsearch 並填入前面產生的服務金鑰):
```
```bash
## 安裝 elasticsearch 與 kibana # 在所有網路介面啟動服務
server.host: "0.0.0.0"
## 安裝相依套件
# 設定 elasticsearch 服務位置
```bash elasticsearch.hosts: ["http://0.0.0.0:9200"]
sudo apt install -y apt-transport-https
``` # 設定 elasticsearch 存取金鑰
elasticsearch.serviceAccountToken: "eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4zMC4xMDQ6OTIwMCJdLCJmZ3IiOiIzYTEyMWIwZTk4N2M0YzE5ODczMzdmNmU0OTk1Y2E3M2RmNmMzZmE5YzlkNzU4ZGYxN2M4YmNlOThjNjBiMjAxIiwia2V5IjoidWpEaVFwTUJDcmJ4NjlvajVsRm86SkpTUmQzdFdRTWVsUlIyUGxHbGg2ZyJ9"
## 安裝 elasticsearch 與 kibana 服務 ```
```bash ## 啟動 Kibana
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
kibana
```bash ```
sudo apt update && sudo apt upgrade -y && sudo apt install -y elasticsearch kibana
``` ---
## 新增 elasticsearch 服務 # 方法二:使用 APT 套件庫安裝
```bash ## 安裝相依套件
sudo nano /etc/systemd/system/elasticsearch.service
``` ```bash
sudo apt install -y apt-transport-https
``` ```
[Unit]
Description=elasticsearch ## 加入套件庫並安裝
[Service] 加入官方 8.x APT 套件庫。
Type=simple
User=shuochen ```bash
WorkingDirectory=/home/shuochen/elasticsearch-8.16.0 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
ExecStart=/home/shuochen/elasticsearch-8.16.0/bin/elasticsearch ```
Restart=always
更新套件清單並安裝 Elasticsearch 與 Kibana。
[Install]
WantedBy=multi-user.target ```bash
``` sudo apt update && sudo apt upgrade -y && sudo apt install -y elasticsearch kibana
```
## 啟動 elasticsearch 服務
## 建立 Elasticsearch 服務
```bash
sudo systemctl daemon-reload 建立 systemd 服務設定檔。
```
```bash
```bash sudo nano /etc/systemd/system/elasticsearch.service
sudo systemctl enable elasticsearch ```
```
服務檔內容如下:
```bash
sudo systemctl start elasticsearch ```ini
``` [Unit]
Description=elasticsearch
## 新增 kibana 服務
[Service]
```bash Type=simple
sudo nano /etc/systemd/system/kibana.service User=shuochen
``` WorkingDirectory=/home/shuochen/elasticsearch-8.16.0
ExecStart=/home/shuochen/elasticsearch-8.16.0/bin/elasticsearch
``` Restart=always
[Unit]
Description=kibana [Install]
WantedBy=multi-user.target
[Service] ```
Type=simple
User=shuochen ## 啟動 Elasticsearch 服務
WorkingDirectory=/home/shuochen/kibana-8.16.0
ExecStart=/home/shuochen/kibana-8.16.0/bin/kibana --allow-root ```bash
Restart=always sudo systemctl daemon-reload
```
[Install]
WantedBy=multi-user.target ```bash
``` sudo systemctl enable elasticsearch
```
## 啟動 kibana 服務
```bash
```bash sudo systemctl start elasticsearch
sudo systemctl daemon-reload ```
```
## 建立 Kibana 服務
```bash
sudo systemctl enable kibana 建立 systemd 服務設定檔。
```
```bash
```bash sudo nano /etc/systemd/system/kibana.service
sudo systemctl start kibana ```
```
服務檔內容如下:
```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
```
+19 -11
@@ -1,11 +1,19 @@
# 下載 Emby # 簡介
```bash Emby 是一套媒體伺服器,可整理並串流家中的影音內容。本文記錄在 Ubuntu 上以官方 deb 套件安裝 Emby Server 的步驟。
wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.8.11.0/emby-server-deb_4.8.11.0_amd64.deb
``` # 下載 Emby
# 安裝 Emby 從官方下載指定版本的 deb 安裝套件。
```bash ```bash
dpkg -i emby-server-deb_4.8.11.0_amd64.deb 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
```
+178 -158
@@ -1,158 +1,178 @@
# 安裝相關套件 # 簡介
```bash Gitea 是一套輕量級、可自行架設的 Git 服務(功能類似 GitHub / GitLab)。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署 Gitea 的完整步驟。
apt update && apt install -y git
``` # 安裝相依套件
# 下載 Gitea Gitea 進行版本控制操作時需要系統已安裝 git。
```bash ```bash
wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.25.3/gitea-1.25.3-linux-amd64 apt update && apt install -y git
``` ```
```bash # 下載 Gitea
wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.26.2/gitea-1.26.2-linux-amd64
``` 從官方下載指定版本的二進位檔,放到 `/usr/local/bin/gitea`。以下提供兩個版本,擇一執行即可。
將 gitea 設定為可執行檔 ```bash
wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.25.3/gitea-1.25.3-linux-amd64
```bash ```
chmod +x /usr/local/bin/gitea
``` ```bash
wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.26.2/gitea-1.26.2-linux-amd64
# 新增 git 使用者 ```
```bash 下載後將 gitea 設定為可執行檔。
adduser \
--system \ ```bash
--shell /bin/bash \ chmod +x /usr/local/bin/gitea
--gecos 'Git Version Control' \ ```
--group \
--disabled-password \ # 新增 git 使用者
--home /home/git \
git 基於安全考量,Gitea 以專屬的 `git` 系統帳號執行,而非使用 root。
```
```bash
# 建立系統資料夾 adduser \
--system \
```bash --shell /bin/bash \
mkdir -p /var/lib/gitea/custom && mkdir -p /var/lib/gitea/data && mkdir -p /var/lib/gitea/log && mkdir /etc/gitea --gecos 'Git Version Control' \
``` --group \
--disabled-password \
設定資料夾權限 --home /home/git \
git
```bash ```
chown -R git:git /var/lib/gitea/ && chmod -R 750 /var/lib/gitea/
``` # 建立系統資料夾
```bash 分別建立存放自訂檔案、資料、日誌的目錄,以及設定檔目錄 `/etc/gitea`
chown root:git /etc/gitea && chmod 770 /etc/gitea
``` ```bash
mkdir -p /var/lib/gitea/custom && mkdir -p /var/lib/gitea/data && mkdir -p /var/lib/gitea/log && mkdir /etc/gitea
設定 Gitea 工作資料夾 ```
```bash 將資料目錄的擁有者設為 git,並限制權限。
echo 'export GITEA_WORK_DIR=/var/lib/gitea/' >> ~/.bashrc && source ~/.bashrc
``` ```bash
chown -R git:git /var/lib/gitea/ && chmod -R 750 /var/lib/gitea/
設定 Gitea 服務 ```
```bash 設定檔目錄安裝完成後通常會調回唯讀,這裡先讓 git 群組可寫入以便初始化。
nano /etc/systemd/system/gitea.service
``` ```bash
chown root:git /etc/gitea && chmod 770 /etc/gitea
內容如下 ```
``` # 設定工作目錄環境變數
[Unit]
Description=Gitea (Git with a cup of tea) 告訴 Gitea 它的工作目錄位置。
After=network.target
### ```bash
# Don't forget to add the database service dependencies echo 'export GITEA_WORK_DIR=/var/lib/gitea/' >> ~/.bashrc && source ~/.bashrc
### ```
#
#Wants=mysql.service # 建立 Gitea 服務
#After=mysql.service
# 以 systemd 管理 Gitea,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。
#Wants=mariadb.service
#After=mariadb.service ```bash
# nano /etc/systemd/system/gitea.service
#Wants=postgresql.service ```
#After=postgresql.service
# 服務檔內容如下(保留官方範例註解,可依需要取消註解):
#Wants=memcached.service
#After=memcached.service ```ini
# [Unit]
#Wants=redis.service Description=Gitea (Git with a cup of tea)
#After=redis.service After=network.target
# ###
### # Don't forget to add the database service dependencies
# If using socket activation for main http/s ###
### #
# #Wants=mysql.service
#After=gitea.main.socket #After=mysql.service
#Requires=gitea.main.socket #
# #Wants=mariadb.service
### #After=mariadb.service
# (You can also provide gitea an http fallback and/or ssh socket too) #
# #Wants=postgresql.service
# An example of /etc/systemd/system/gitea.main.socket #After=postgresql.service
### #
## #Wants=memcached.service
## [Unit] #After=memcached.service
## Description=Gitea Web Socket #
## PartOf=gitea.service #Wants=redis.service
## #After=redis.service
## [Socket] #
## Service=gitea.service ###
## ListenStream=<some_port> # If using socket activation for main http/s
## NoDelay=true ###
## #
## [Install] #After=gitea.main.socket
## WantedBy=sockets.target #Requires=gitea.main.socket
## #
### ###
# (You can also provide gitea an http fallback and/or ssh socket too)
[Service] #
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that # An example of /etc/systemd/system/gitea.main.socket
# LimitNOFILE=524288:524288 ###
RestartSec=2s ##
Type=simple ## [Unit]
User=git ## Description=Gitea Web Socket
Group=git ## PartOf=gitea.service
WorkingDirectory=/var/lib/gitea/ ##
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file ## [Socket]
# (manually creating /run/gitea doesn't work, because it would not persist across reboots) ## Service=gitea.service
#RuntimeDirectory=gitea ## ListenStream=<some_port>
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini ## NoDelay=true
Restart=always ##
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea ## [Install]
# If you install Git to directory prefix other than default PATH (which happens ## WantedBy=sockets.target
# 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 [Service]
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin # Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
# If you want to bind Gitea to a port below 1024, uncomment # LimitNOFILE=524288:524288
# the two values below, or use socket activation to pass Gitea its ports as above RestartSec=2s
### Type=simple
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE User=git
#AmbientCapabilities=CAP_NET_BIND_SERVICE Group=git
### WorkingDirectory=/var/lib/gitea/
# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to # If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# set the following value to false to allow capabilities to be applied on gitea process. The following # (manually creating /run/gitea doesn't work, because it would not persist across reboots)
# value if set to true sandboxes gitea service and prevent any processes from running with privileges #RuntimeDirectory=gitea
# in the host user namespace. ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
### Restart=always
#PrivateUsers=false 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
[Install] # distribution version), uncomment below line and add that prefix to PATH
WantedBy=multi-user.target # 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
啟動 Gitea 服務 # 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
```bash ###
systemctl daemon-reload && systemctl enable gitea && systemctl start gitea && systemctl status gitea #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
```
+75 -61
@@ -1,61 +1,75 @@
# 安裝需要的套件 # 簡介
```bash Gitea Runneract_runner)負責執行 Gitea Actions 的 CI/CD 工作流程,需向 Gitea 主機註冊後才能接收任務。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署 Runner 的步驟。
apt update && apt install -y nodejs
``` # 安裝相依套件
# 下載 Gitea Runner 部分 Actions 工作流程需要 Node.js 環境。
```bash ```bash
wget https://gitea.com/gitea/runner/releases/download/v1.0.2/gitea-runner-1.0.2-linux-amd64 -O /usr/local/bin/runner apt update && apt install -y nodejs
``` ```
將 act_runner 設定為可執行檔 # 下載 Gitea Runner
```bash 從官方下載指定版本的二進位檔,放到 `/usr/local/bin/runner`
chmod +x /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
# 註冊 Gitea Runner ```
設定參數 下載後將 runner 設定為可執行檔。
```bash ```bash
runner register chmod +x /usr/local/bin/runner
``` ```
# 設計 Gitea Runner 服務 # 註冊 Gitea Runner
```bash 執行註冊指令,依提示輸入 Gitea 主機位址與註冊權杖(registration token),完成後會在當前目錄產生設定檔。
nano /etc/systemd/system/runner.service
``` ```bash
runner register
服務檔內容 ```
```ini # 建立 Gitea Runner 服務
[Unit]
Description=Gitea Actions runner 以 systemd 管理 Runner,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。
[Service] ```bash
Environment=HOME=/root nano /etc/systemd/system/runner.service
Type=simple ```
WorkingDirectory=/root
ExecStart=/usr/local/bin/runner daemon 服務檔內容如下:
Restart=always
User=root ```ini
[Unit]
[Install] Description=Gitea Actions runner
WantedBy=multi-user.target
``` [Service]
Environment=HOME=/root
啟動服務 Type=simple
WorkingDirectory=/root
```bash ExecStart=/usr/local/bin/runner daemon
systemctl daemon-reload && systemctl enable runner.service && systemctl start runner.service && systemctl status runner.service Restart=always
``` User=root
停止服務 [Install]
WantedBy=multi-user.target
```bash ```
systemctl stop act_runner.service && systemctl disable act_runner.service && rm /etc/systemd/system/act_runner.service
``` # 啟動服務
重新載入 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
```
+33 -25
@@ -1,25 +1,33 @@
# 安裝相關套件 # 簡介
```bash GitLab CE(社群版)是功能完整的自架 Git 平台,內建 CI/CD、Issue 追蹤等功能。本文記錄在 Ubuntu 上透過官方套件庫安裝 GitLab 的步驟。
apt update && apt install -y curl
``` # 安裝相依套件
透過 Script 安裝套件 安裝套件庫腳本與套件下載過程需要 curl。
```bash ```bash
curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" | bash apt update && apt install -y curl
``` ```
# 安裝 Gitlab 透過官方腳本加入 GitLab 套件庫。
```bash ```bash
EXTERNAL_URL="https://gitlab.jsc.idv.tw" apt install gitlab-ce curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" | bash
``` ```
# 取得 root 密碼 # 安裝 Gitlab
需要在 24 小時內變更 安裝時以 `EXTERNAL_URL` 指定對外網址,GitLab 會據此自動完成初始設定。
```bash ```bash
cat /etc/gitlab/initial_root_password EXTERNAL_URL="https://gitlab.jsc.idv.tw" apt install gitlab-ce
``` ```
# 取得 root 密碼
安裝後系統會產生隨機的 root 初始密碼,存放於下列檔案,且必須在 24 小時內登入並變更,逾期該檔案會被自動刪除。
```bash
cat /etc/gitlab/initial_root_password
```
+86 -68
@@ -1,68 +1,86 @@
# 安裝相關套件 # 簡介
```bash MeTube 是 youtube-dl / yt-dlp 的網頁前端,可透過瀏覽器下載影音。本文記錄在 Ubuntu 上由原始碼建置並以 systemd 部署的步驟。
apt update && apt install -y git nodejs npm curl ffmpeg
``` # 安裝相依套件
# 下載 MeTube 建置前端與後端、處理影音時需要這些套件。
```bash ```bash
git clone https://github.com/alexta69/metube.git apt update && apt install -y git nodejs npm curl ffmpeg
``` ```
# 安裝 MeTube # 下載 MeTube
## 前端 從 GitHub 取得原始碼。
```bash ```bash
cd ~/metube/ui && npm install && node_modules/.bin/ng build git clone https://github.com/alexta69/metube.git
``` ```
## 後端 # 安裝 MeTube
```bash ## 前端
cd ~/metube && curl -LsSf https://astral.sh/uv/install.sh | sh && uv sync
``` 安裝前端相依套件並建置 Angular 前端。
設定環境變數 ```bash
cd ~/metube/ui && npm install && node_modules/.bin/ng build
```bash ```
echo 'source $HOME/.local/bin/env' >> ~/.bashrc && source ~/.bashrc
``` ## 後端
# 執行 MeTube 安裝 uv(Python 套件管理工具)並同步後端相依套件。
```bash ```bash
uv run python3 app/main.py cd ~/metube && curl -LsSf https://astral.sh/uv/install.sh | sh && uv sync
``` ```
# 設計 MeTube 服務 將 uv 加入環境變數。
```bash ```bash
nano /etc/systemd/system/metube.service echo 'source $HOME/.local/bin/env' >> ~/.bashrc && source ~/.bashrc
``` ```
服務檔內容 # 執行 MeTube
```ini 手動執行測試是否正常。
[Unit]
Description=MeTube ```bash
uv run python3 app/main.py
[Service] ```
Type=simple
WorkingDirectory=/root/metube # 建立 MeTube 服務
ExecStart=/root/.local/bin/uv run python3 app/main.py
Restart=always 以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。
User=root
```bash
[Install] nano /etc/systemd/system/metube.service
WantedBy=multi-user.target ```
```
服務檔內容如下:
啟動服務
```ini
```bash [Unit]
systemctl daemon-reload && systemctl enable metube.service && systemctl start metube.service Description=MeTube
```
[Service]
# 連接埠 8081 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
+85 -65
@@ -1,65 +1,85 @@
# 安裝語言套件 # 簡介
## Go PicoClaw 是 Sipeed 推出的工具,可由原始碼自行建置,也可直接以套件快速安裝。本文記錄兩種在 Ubuntu 上的安裝方式,以及 TUI / WebUI 兩種啟動方法。
```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 與 Node.js 環境。
```bash ## Go
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc && go version
``` 下載並解壓縮 Go 到 `/usr/local`
## NodeJS && NPM ```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 ```
apt update && apt install -y nodejs npm
``` 將 Go 加入環境變數並確認版本。
# 下載原始碼 ```bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc && go version
```bash ```
git clone https://github.com/sipeed/picoclaw.git
``` ## NodeJS && NPM
# 編譯原始碼 ```bash
apt update && apt install -y nodejs npm
```bash ```
cd ~/picoclaw && make deps
``` # 下載原始碼
為目前平台建構核心二進位檔 從 GitHub 取得原始碼。
```bash ```bash
cd ~/picoclaw && make build git clone https://github.com/sipeed/picoclaw.git
``` ```
為所有 Makefile 管理的平台建立核心二進位檔案 # 編譯原始碼
```bash 安裝建置所需的相依套件。
cd ~/picoclaw && make build-all
``` ```bash
cd ~/picoclaw && make deps
建置與安裝 ```
```bash 為目前平台建構核心二進位檔。
cd ~/picoclaw && make install
``` ```bash
cd ~/picoclaw && make build
# 啟動 TUI for SSH ```
```bash 為所有 Makefile 管理的平台建立核心二進位檔案。
picoclaw-launcher-tui
``` ```bash
cd ~/picoclaw && make build-all
# 快速安裝 ```
```bash 建置並安裝。
wget https://github.com/sipeed/picoclaw/releases/download/v0.2.6/picoclaw_x86_64.deb && dpkg -i picoclaw_x86_64.deb
``` ```bash
cd ~/picoclaw && make install
# 啟動 WebUI for Desktop ```
```bash # 啟動 TUI for SSH
picoclaw-launcher -public
``` 適合透過 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
```
+47 -33
@@ -1,33 +1,47 @@
# 安裝相依套件 # 簡介
```bash Redis 是高效能的記憶體式鍵值資料庫,常用於快取與訊息佇列。本文記錄在 Ubuntu 上透過官方 APT 套件庫安裝 Redis 的步驟。
apt update && apt install -y lsb-release curl gpg
``` # 安裝相依套件
# 安裝 Redis 簽章 加入套件庫過程需要這些工具。
```bash ```bash
curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg apt update && apt install -y lsb-release curl gpg
``` ```
```bash # 安裝 Redis 簽章
chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
``` 下載官方 GPG 金鑰並轉換為 keyring,供 APT 驗證套件來源。
# 加入 Redis 套件庫 ```bash
curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
```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
chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
```bash ```
apt install -y redis
``` # 加入 Redis 套件庫
# 啟動 Redis 伺服器 加入官方套件庫(`$(lsb_release -cs)` 會自動帶入目前 Ubuntu 版本代號)。
```bash ```bash
systemctl enable redis-server && systemctl start redis-server && systemctl status redis-server 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
```
+228 -212
@@ -1,212 +1,228 @@
# 下載 Traefik 壓縮檔 # 簡介
```bash Traefik 是一套現代化的反向代理與負載平衡器,常用於統一管理各服務的對外路由與 TLS。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署 Traefik 的步驟,並附上範例設定檔。
wget https://github.com/traefik/traefik/releases/download/v3.7.4/traefik_v3.7.4_linux_amd64.tar.gz
``` # 下載 Traefik 壓縮檔
# 解壓縮 從官方下載指定版本的壓縮檔。
```bash ```bash
tar zxvf traefik_v3.7.4_linux_amd64.tar.gz -C /usr/local/bin/ traefik wget https://github.com/traefik/traefik/releases/download/v3.7.4/traefik_v3.7.4_linux_amd64.tar.gz
``` ```
# 設計 Traefik 服務 # 解壓縮
```bash 只解出 traefik 執行檔並放到 `/usr/local/bin/`
nano /etc/systemd/system/traefik.service
``` ```bash
tar zxvf traefik_v3.7.4_linux_amd64.tar.gz -C /usr/local/bin/ traefik
服務檔內容 ```
```ini # 建立 Traefik 服務
[Unit]
Description=Traefik Proxy 以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。
[Service] ```bash
Environment=HOME=/root nano /etc/systemd/system/traefik.service
Type=simple ```
WorkingDirectory=/root
ExecStart=/usr/local/bin/traefik --configFile=traefik.toml 服務檔內容如下:
Restart=always
User=root ```ini
[Unit]
[Install] Description=Traefik Proxy
WantedBy=multi-user.target
``` [Service]
Environment=HOME=/root
啟動服務 Type=simple
WorkingDirectory=/root
```bash ExecStart=/usr/local/bin/traefik --configFile=traefik.toml
systemctl daemon-reload && systemctl enable traefik.service && systemctl start traefik.service && systemctl status traefik.service Restart=always
``` User=root
停止服務 [Install]
WantedBy=multi-user.target
```bash ```
systemctl stop traefik.service && systemctl disable traefik.service && rm /etc/systemd/system/traefik.service
``` # 啟動服務
範例設定檔 重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。
```bash ```bash
nano /root/traefik.toml systemctl daemon-reload && systemctl enable traefik.service && systemctl start traefik.service && systemctl status traefik.service
``` ```
```toml # 停止服務
################################################################
# 停止、取消開機啟動並移除服務設定檔。
# Configuration sample for Traefik v2.
# ```bash
# For Traefik v1: https://github.com/traefik/traefik/blob/v1.7/traefik.sample.toml systemctl stop traefik.service && systemctl disable traefik.service && rm /etc/systemd/system/traefik.service
# ```
################################################################
# 範例設定檔
################################################################
# Global configuration 建立設定檔,路徑須與服務檔 `--configFile` 指定的位置一致。
################################################################
[global] ```bash
checkNewVersion = true nano /root/traefik.toml
sendAnonymousUsage = true ```
################################################################ ```toml
# Entrypoints configuration ################################################################
################################################################ #
# Configuration sample for Traefik v2.
# Entrypoints definition #
# # For Traefik v1: https://github.com/traefik/traefik/blob/v1.7/traefik.sample.toml
# Optional #
# Default: ################################################################
[entryPoints]
[entryPoints.web] ################################################################
address = ":80" # Global configuration
################################################################
[entryPoints.websecure] [global]
address = ":443" checkNewVersion = true
sendAnonymousUsage = true
################################################################
# Traefik logs configuration ################################################################
################################################################ # Entrypoints configuration
################################################################
# Traefik logs
# Enabled by default and log to stdout # Entrypoints definition
# #
# Optional # Optional
# # Default:
[log] [entryPoints]
[entryPoints.web]
# Log level address = ":80"
#
# Optional [entryPoints.websecure]
# Default: "ERROR" address = ":443"
#
# level = "DEBUG" ################################################################
# Traefik logs configuration
# Sets the filepath for the traefik log. If not specified, stdout will be used. ################################################################
# Intermediate directories are created if necessary.
# # Traefik logs
# Optional # Enabled by default and log to stdout
# Default: os.Stdout #
# # Optional
# filePath = "log/traefik.log" #
[log]
# Format is either "json" or "common".
# # Log level
# Optional #
# Default: "common" # Optional
# # Default: "ERROR"
# format = "json" #
# level = "DEBUG"
################################################################
# Access logs configuration # Sets the filepath for the traefik log. If not specified, stdout will be used.
################################################################ # Intermediate directories are created if necessary.
#
# Enable access logs # Optional
# By default it will write to stdout and produce logs in the textual # Default: os.Stdout
# Common Log Format (CLF), extended with additional fields. #
# # filePath = "log/traefik.log"
# Optional
# # Format is either "json" or "common".
# [accessLog] #
# Optional
# Sets the file path for the access log. If not specified, stdout will be used. # Default: "common"
# Intermediate directories are created if necessary. #
# # format = "json"
# Optional
# Default: os.Stdout ################################################################
# # Access logs configuration
# filePath = "/path/to/log/log.txt" ################################################################
# Format is either "json", "common", or "genericCLF". # Enable access logs
# - "common": Traefik's extended CLF format (default) # By default it will write to stdout and produce logs in the textual
# - "genericCLF": Standard CLF format compatible with standard log analyzers # Common Log Format (CLF), extended with additional fields.
# - "json": JSON format for structured logging #
# # Optional
# Optional #
# Default: "common" # [accessLog]
#
# format = "json" # Sets the file path for the access log. If not specified, stdout will be used.
# format = "genericCLF" # Intermediate directories are created if necessary.
#
################################################################ # Optional
# API and dashboard configuration # Default: os.Stdout
################################################################ #
# filePath = "/path/to/log/log.txt"
# Enable API and dashboard
[api] # Format is either "json", "common", or "genericCLF".
# - "common": Traefik's extended CLF format (default)
# Enable the API in insecure mode # - "genericCLF": Standard CLF format compatible with standard log analyzers
# # - "json": JSON format for structured logging
# Optional #
# Default: false # Optional
# # Default: "common"
# insecure = true #
# format = "json"
# Enabled Dashboard # format = "genericCLF"
#
# Optional ################################################################
# Default: true # API and dashboard configuration
# ################################################################
# dashboard = false
# Enable API and dashboard
################################################################ [api]
# Ping configuration
################################################################ # Enable the API in insecure mode
#
# Enable ping # Optional
[ping] # Default: false
#
# Name of the related entry point # insecure = true
#
# Optional # Enabled Dashboard
# Default: "traefik" #
# # Optional
# entryPoint = "traefik" # Default: true
#
################################################################ # dashboard = false
# Docker configuration backend
################################################################ ################################################################
# Ping configuration
# Enable Docker configuration backend ################################################################
[providers.docker]
# Enable ping
# Docker server endpoint. Can be a tcp or a unix socket endpoint. [ping]
#
# Required # Name of the related entry point
# Default: "unix:///var/run/docker.sock" #
# # Optional
# endpoint = "tcp://10.10.10.10:2375" # Default: "traefik"
#
# Default host rule. # entryPoint = "traefik"
#
# Optional ################################################################
# Default: "Host(`{{ normalize .Name }}`)" # Docker configuration backend
# ################################################################
# defaultRule = "Host(`{{ normalize .Name }}.docker.localhost`)"
# Enable Docker configuration backend
# Expose containers by default in traefik [providers.docker]
#
# Optional # Docker server endpoint. Can be a tcp or a unix socket endpoint.
# Default: true #
# # Required
# exposedByDefault = false # 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
```
+35 -23
@@ -1,23 +1,35 @@
更新套件 # 簡介
```bash code-server 可在伺服器上執行 VS Code,並透過瀏覽器遠端使用。本文記錄在 Ubuntu 上安裝 code-server 的步驟。
apt update && apt install -y curl
``` # 安裝相依套件
安裝 VS Code 安裝腳本下載過程需要 curl。
```bash ```bash
curl -fsSL https://code-server.dev/install.sh | sh apt update && apt install -y curl
``` ```
啟動服務 # 安裝 VS Code
```bash 透過官方安裝腳本安裝 code-server。
systemctl daemon-reload && systemctl enable --now code-server@$USER && systemctl start code-server@$USER && systemctl status code-server@$USER
``` ```bash
curl -fsSL https://code-server.dev/install.sh | sh
預設密碼 ```
```bash # 啟動服務
cat ~/.config/code-server/config.yaml
``` 設為開機自動啟動並啟動目前使用者的 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
```
+78 -66
@@ -1,66 +1,78 @@
下載 ezBookkeeping # 簡介
```bash ezBookkeeping 是一套自架的個人記帳服務。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署,並使用 PostgreSQL 作為資料庫的步驟。
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
``` # 下載 ezBookkeeping
```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
``` ```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
設計 ezBookkeeping 服務 ```
```bash ```bash
nano /etc/systemd/system/ezbookkeeping.service 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 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。
[Unit]
Description=ezBookkeeping ```bash
nano /etc/systemd/system/ezbookkeeping.service
[Service] ```
Environment=HOME=/root
Type=simple 服務檔內容如下:
WorkingDirectory=/root
ExecStart=/root/ezbookkeeping server run ```ini
Restart=always [Unit]
User=root Description=ezBookkeeping
[Install] [Service]
WantedBy=multi-user.target Environment=HOME=/root
``` Type=simple
WorkingDirectory=/root
啟動服務 ExecStart=/root/ezbookkeeping server run
Restart=always
```bash User=root
systemctl daemon-reload && systemctl enable ezbookkeeping.service && systemctl start ezbookkeeping.service && systemctl status ezbookkeeping.service
``` [Install]
WantedBy=multi-user.target
# 使用 ```
```bash # 啟動服務
sudo -u postgres psql
``` 重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。
新建使用者與資料庫 ```bash
systemctl daemon-reload && systemctl enable ezbookkeeping.service && systemctl start ezbookkeeping.service && systemctl status ezbookkeeping.service
```sql ```
CREATE USER ezbookkeeping WITH PASSWORD 'ezbookkeeping';
# 設定資料庫
CREATE DATABASE ezbookkeeping;
``` 以 postgres 系統帳號進入 PostgreSQL 互動介面。
設定資料庫權限 ```bash
sudo -u postgres psql
```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 ```sql
ALTER SCHEMA public OWNER TO ezbookkeeping; CREATE USER ezbookkeeping WITH PASSWORD 'ezbookkeeping';
-- 3. Ensure the user has create permissions (Crucial for Postgres 15+) CREATE DATABASE ezbookkeeping;
GRANT USAGE, CREATE ON SCHEMA public TO 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;
```
+39 -29
@@ -1,29 +1,39 @@
# 安裝 kubectl & k3d # 簡介
```bash k3d 可在 Docker 中執行輕量級 Kubernetes 發行版 k3s,方便在單機快速建立測試用叢集。本文記錄在 Ubuntu 上安裝 kubectl 與 k3d,並建立叢集的步驟(需先安裝 Docker)。
apt update \
&& apt install -y curl \ # 安裝 kubectl & k3d
&& 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、下載最新版 kubectl 並設為可執行檔、再以官方腳本安裝 k3d。
&& curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
``` ```bash
apt update \
# 建立 1 個伺服器 2 個代理 && 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 \
```bash && chmod +x /usr/local/bin/kubectl \
k3d cluster create ct \ && curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
--servers 1 \ ```
--agents 2 \
--port 80:80@loadbalancer \ # 建立 1 個伺服器 2 個代理
--port 443:443@loadbalancer \
--k3s-arg '--kubelet-arg=feature-gates=KubeletInUserNamespace=true@server:*' \ 建立名為 `ct` 的叢集(1 個 server、2 個 agent),對外開放 80/443,啟用使用者命名空間相容設定,掛載 Docker socket 並建立本地映像登錄。
--k3s-arg '--kubelet-arg=feature-gates=KubeletInUserNamespace=true@agent:*' \
--volume /var/run/docker.sock:/var/run/docker.sock \ ```bash
--registry-create k3d-ct-registry:5000 k3d cluster create ct \
``` --servers 1 \
--agents 2 \
# 驗證節點 --port 80:80@loadbalancer \
--port 443:443@loadbalancer \
```bash --k3s-arg '--kubelet-arg=feature-gates=KubeletInUserNamespace=true@server:*' \
kubectl get nodes --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
```
+52 -42
@@ -1,42 +1,52 @@
# 多網路權重設定 # 簡介
雙 DHCP netplan 是 Ubuntu 的網路設定工具,以 YAML 描述網路介面。本文記錄多網卡環境下,透過路由權重(`metric`)控制預設對外流量走哪張網卡的設定範例。`metric` 數值越小優先權越高。
```yaml 設定檔通常位於 `/etc/netplan/`,修改後以 `netplan apply` 套用。
network:
version: 2 # 多網路權重設定
ethernets:
eth0: ## 雙 DHCP
dhcp4: true
dhcp4-overrides: 兩張網卡都使用 DHCP,透過 `route-metric``eth1`100)優先於 `eth0`200)作為對外路由。
route-metric: 200
eth1: ```yaml
dhcp4: true network:
dhcp4-overrides: version: 2
route-metric: 100 ethernets:
``` eth0:
dhcp4: true
靜態+動態 dhcp4-overrides:
route-metric: 200
```yaml eth1:
network: dhcp4: true
version: 2 dhcp4-overrides:
ethernets: route-metric: 100
ens18: ```
addresses:
- "172.25.43.200/20" ## 靜態 + 動態
nameservers:
addresses: `ens18` 使用靜態 IPmetric 200),`ens19` 使用 DHCPmetric 100),對外流量優先走 metric 較小的 `ens19`
- 168.95.1.1
- 8.8.8.8 ```yaml
search: [] network:
routes: version: 2
- to: "0.0.0.0/0" ethernets:
via: "172.25.32.1" ens18:
metric: 200 addresses:
ens19: - "172.25.43.200/20"
dhcp4: true nameservers:
routes: addresses:
- to: "0.0.0.0/0" - 168.95.1.1
metric: 100 - 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
```