Synology VDSM:利用 AI 遷移 Docker 並調整虛擬磁碟大小 (2026)

虛擬 NAS 是那種人們安裝一次,玩上一下午就忘了自己擁有的功能之一。這很可惜,因為 Synology VDSM(運行在 Virtual Machine Manager 內部的 Virtual DSM)悄悄解決了小型自託管中最令人頭痛的兩個問題。首先,在不同機器之間遷移 Docker 堆疊通常需要花費一個晚上繁瑣的工作。其次,當虛擬磁碟空間不足時,大多數人會認為必須重建整個系統。但在 VDSM 上,這兩個問題都不存在。本指南將詳細介紹我們用大約 35 分鐘完成的一次實際遷移:將一個包含五個插件的內部 Redmine 問題追蹤器從一個 VDSM 虛擬機遷移到另一個虛擬機,並由 AI 助理控制 shell。遷移過程中,目標虛擬機器的磁碟空間不足,因此我們將虛擬磁碟從 10 GB 擴展到 20 GB 並繼續遷移。以下所有內容都是實際發生的,包括一個會悄無聲息地破壞應用程式的陷阱。.

SynoPower Club 點:I have watched a lot of people talk themselves out of virtualisation on a NAS because they assume it is for labs and not for real work. The migration in this article was real work — a ticket system three colleagues use every day — and the part that surprised me was not the AI. It was how little ceremony VDSM needs. No hypervisor to license, no separate management server, no export-import dance between incompatible formats. The guest ran out of disk mid-job and I fixed it by typing a bigger number into a text field while it was still running. The whole job took thirty-five minutes and the only outage anyone noticed was ninety seconds on an unrelated website. If you already own a Synology with spare memory, you are one package install away from this.

Synology VDSM 是什麼?

VDSM 是 Synology 的 Virtual DSM:它是 DiskStation Manager 的完整副本,作為客戶作業系統運行在實體 NAS 上的 Virtual Machine Manager 內部。它的行為就像一台獨立的 NAS,擁有自己的 IP 位址、DSM 登入資訊、軟體包和容器管理器。從網路角度來看,它只是區域網路上的另一台 Synology。從硬體角度來看,它只是在你已付費的裝置上運行的額外進程。.

實際優勢在於隔離性。如果所有服務都直接運行在主機上,一個運行異常的容器可能會導致整個辦公室依賴的檔案伺服器癱瘓。將工作負載分散到多個 VDSM 虛擬機器中,每個虛擬機器都有獨立的記憶體上限、CPU 分配和磁碟空間,並且可以在不影響其他虛擬機器的情況下重新啟動其中一個。.

Every NAS that supports Virtual Machine Manager includes one VDSM licence at no cost. Running a second and subsequent guest needs a paid Virtual DSM licence each. That single free instance is enough to follow everything in this article, and it is why so many people already own the capability and have never switched it on. If you need to add, map or unmap a licence later, we have a walkthrough on 管理 VDSM 許可證.

Synology VDSM 與第二台實體 NAS:您需要哪一個?

客觀來說,並非虛擬化更好,而是以彈性換取彈性。第二台實體伺服器可以在第一個實體伺服器發生故障時繼續運行,而虛擬分散式系統(VDSM)虛擬機器則不行。虛擬機器帶來的好處是,你可以在幾分鐘內(而不是幾天)建立、調整大小、建立快照和遷移整個伺服器。.

 VDSM 客人第二個物理NAS
增加一個的成本首位客人免費,之後需購買許可證。整個NAS加上硬碟
準備工作時間到了分分鐘天數,包括運輸時間
調整 CPU、RAM 或磁碟容量編輯字段,重啟訪客購買新硬體
能夠抵禦主機硬體故障是的
快照和克隆內建於 Virtual Machine Manager不適用
遷移到另一個NAS。遷移或複製客戶機將其物理遷移
最適合隔離服務、部署、整合小型伺服器備份目標和真正的冗餘

對於這項工作,選擇顯而易見。我們要將一個使用率不高的問題追蹤系統(它原本佔用一個完整的 VDSM 虛擬機器)整合到一個已經運行網站且有剩餘容量的虛擬機器上。這不需要任何新的硬體。只需要十分鐘和一點耐心。.

開始之前你需要準備什麼

Before anything else, give the assistant its own login rather than handing over yours. In DSM open Control Panel, go to User & Group and click Create. Name it something unmistakable — we used claude with the description AI control — and let DSM generate a strong random password.

Creating a dedicated DSM account for AI SSH access before a VDSM migration
A dedicated account, named so that nobody has to guess what it is for.

On the next screen, tick administrators. This is not optional: DSM only permits members of the administrators group to log in over SSH, so an account outside that group cannot reach the shell at all. Do the same on both VDSM guests, then make sure SSH is switched on under Control Panel, Terminal & SNMP.

Adding the AI account to the administrators group so it can SSH into the VDSM guest
DSM only lets members of the administrators group in over SSH, so this box has to be ticked.

When the work is finished, disable the account. That is the whole point of making a separate one. Edit the user in Control Panel and switch it off, or delete it outright; access is revoked in one click without touching your own credentials, and everything the assistant did stays attributable to a login that exists for exactly that purpose. Leaving a permanently enabled administrator account lying around because it was convenient once is how small estates accumulate access nobody remembers granting.

兩台 VDSM 虛擬機,兩台虛擬機都啟用了 SSH,在目標虛擬機上安裝了容器管理器。您還需要注意一點,這一點幾乎每個人第一次都會犯:Docker 二進位檔案不在 DSM 的預設 PATH 環境變數中。軟體包二進位檔案位於軟體包目錄下,因此每個命令都需要完整路徑或 shell 別名。.

出發前請務必確認目的地是否有空位,而不是在轉機途中才檢查。以下命令是完整的飛行前檢查流程,適用於所有 VDSM 旅客。.

One more thing before any of it: take a snapshot of both guests in Virtual Machine Manager. Snapshots are in the free edition of Virtual Machine Manager, not just Pro, and it will keep up to 32 of them per guest. A VDSM snapshot captures the whole machine, so if an import goes wrong or a command does something you did not intend, you roll the guest back instead of rebuilding it. It costs seconds and it is the single cheapest insurance in this entire process. Take one on the source as well as the destination, because the source is your fallback.

# Docker 不在 DSM 的 PATH 環境變數中 - 請使用完整路徑 D=/volume1/@appstore/ContainerManager/usr/bin/docker # 正在運行的是什麼?它基於什麼構建? sudo $D ps -a sudo $D images # 目標磁碟區還剩下多少空間? df -h /volume1 # 目標虛擬機器實際上有多少可用記憶體? free -m

VDSM Docker 遷移四步驟指南

我們執行了以下四個步驟,它們適用於需要在 VDSM 虛擬機器之間遷移的任何容器堆疊。順序很重要:首先停止應用程式容器,以防止在轉儲過程中向資料庫寫入任何資料;資料庫容器保持運行,以便可以乾淨地進行轉儲。.

Take a VDSM snapshot, then snapshot the container itself

Take a Virtual Machine Manager snapshot of both guests first – it is in the free edition and it is your undo button for everything that follows. Then stop the application container and run docker commit against it to capture its filesystem as a new image. This is the step people skip, and skipping it is what breaks the migration. Bind-mounted paths are excluded from a commit, so the data volume still has to be handled separately in step two.

匯出資料庫並歸檔資料卷

在資料庫容器仍在運作的情況下,使用 mariadb-dump 和單一事務標誌進行邏輯轉儲。然後將綁定掛載的資料目錄打包成 tar 檔案。之所以優先選擇邏輯轉儲而不是複製原始資料文件,是因為目標位置的鏡像標籤幾乎不可能與資料庫建置版本完全相同。.

將所有內容直播給目的地客人

透過 SSH 將來源端的 docker save 映像壓縮到目標端的檔案中,然後對資料歸檔檔案執行相同的操作。我們 816 MB 的鏡像被壓縮到 366 MB,並在大約一分鐘內透過區域網路傳輸完畢。在遠端載入鏡像,並使用 preserve-permissions 標誌解壓縮歸檔檔案。.

先啟動資料庫,導入數據,再啟動應用程式。

僅啟動資料庫服務,等待其接受連接,匯入轉儲文件,並確認表和行數與來源文件一致。確認無誤後再啟動應用程式容器。將重啟策略設定為始終重啟,以確保堆疊在虛擬機器重新啟動後仍然有效。.

為什麼 Compose 檔案不是整個容器

這就是陷阱所在,光是這一點就值得你花點時間去了解一下。我們 Redmine 堆疊的 compose 檔案宣告了兩個綁定掛載點:一個用於上傳的文件,一個用於資料庫。閱讀該檔案後,你可能會理所當然地認為,在新虛擬機器上重新建立堆疊意味著複製兩個目錄並執行 `docker compose up` 命令。.

事實並非如此。多年來,五個外掛程式、這些外掛程式引入的 Ruby gems、郵件配置以及幾個修改過的初始化檔案都被直接安裝到了運行中的容器中。所有這些都沒有放在任何卷中。一條命令就讓我們明白了情況有多糟。.

# 容器和它所源自的鏡像之間有多少個檔案不同? sudo $D diff Redmine | wc -l 6764 # 容器內插件,沒有任何磁碟區支援 sudo $D exec Redmine ls /usr/src/redmine/plugins

拉取一個全新的官方鏡像會產生一個不包含任何插件的容器,該容器指向的資料庫仍然保留著遷移過程中創建的 144 個表。應用程式不會發出明顯的錯誤提示。它會啟動,看起來幾乎一切正常,然後出現難以診斷的故障。將正在運行的容器提交到鏡像可以完全避免這個問題,但代價是需要更大的傳輸時間。在區域網路內兩個 VDSM 虛擬機器之間傳輸,這大約需要一分鐘,所以每次都值得這樣做。.

小型團隊如何使用 VDSM 整合伺服器

這種遷移模式是大多數小型團隊最終都需要的。幾年下來,你會累積一些用途單一的虛擬機:一個用於維基,一個用於工單跟踪,一個用於監控儀錶板(如我們之前描述的結構)。 家庭資料中心概覽)。每台設備在建造之初都設計得非常寬敞,而現在每台設備都只以當初設計容量的一小部分運行,而主機卻超負荷運轉,一切都感覺有點慢。.

使用 VDSM 進行整合意味著將空閒工作負載合併到一個已啟動的虛擬機器中。我們的工單追蹤器原本佔用一個完整的虛擬機,擁有獨立的 CPU 分配和 1GB 內存,而每天只有三個人訪問幾次。將其遷移到現有 Web 堆疊旁邊後,直接釋放了 CPU 分配,但目標容器佔用了大約 480MB 的常駐記憶體。.

確保安全的關鍵在於正確地停用來源服務,而不是讓它繼續運作。我們將舊容器的重新啟動策略設為“否”,停止了它們,並在目錄中留下一個文字文件,說明服務現在的運行位置,然後關閉虛擬機並停用自動啟動。這樣就形成了一個完整的回溯點,即使主機重啟,它也不會悄悄地重新啟動並開始接收新實例永遠不會看到的寫入操作。重複的副本是導致一次看似完美的遷移在一個月後演變成資料遺失事件的典型原因。.

調整空間不足的虛擬磁碟的大小

進出一半時,目標位置空間不足。這卷容量為 9.6 GB,剩餘空間 1.5 GB,而我們正準備添加一個 816 MB 的鏡像檔案和 123 MB 的應用程式資料。在實體 NAS 上,到此為止,直到新硬碟到貨。但在 VDSM 中,這則是一個文字方塊。.

在 Virtual Machine Manager 中編輯 Synology VDSM 虛擬機器的虛擬磁碟大小
在 Virtual Machine Manager 中,擴充虛擬磁碟是一個功能-無需重建磁碟區,無需重新安裝。.

Open the guest’s settings in Virtual Machine Manager, go to the Storage tab, type the new size and click OK. The guest does not have to be shut down for this. The disk grows while the machine keeps running, which is why this is a fundamentally different experience from adding capacity to bare hardware. The one rule worth knowing is that a virtual disk can only grow, never shrink, so there is no undo and no reason to be shy about the number.

What makes it genuinely painless is what happens inside the guest. DSM expands the partition and the filesystem to fill the new space by itself. There is no Storage Manager wizard to run, no partition table to edit, no volume to rebuild and no data to migrate. Our volume went from 9.6 GB with 1.5 GB free to 20 GB with 13 GB free, and the containers carried on. This is the single strongest argument for putting a service on VDSM rather than on bare hardware: getting the sizing wrong is cheap to fix later.

將 Synology VDSM 虛擬機器的大小從 10 GB 調整到 20 GB 後,虛擬磁碟使用情況
重新啟動後,虛擬機器報告已佔用全部 20 GB 空間,並且內部磁碟區已擴充。.

AI助理實際上做了什麼

這裡有必要嚴謹一些,因為「AI 移動了我的伺服器」這種說法既容易讓人輕信,也容易讓人難以置信。這個助手並沒有什麼神奇的洞見。它只是對 VDSM 的兩位客人進行了簡單的操作,而且它的系統性遠超一個疲憊不堪、一天工作下來的人。.

它最有價值的一點是,在進行任何操作之前運行了 `docker diff` 命令,發現了 6764 個已更改的文件,並拒絕了顯而易見的方案。任何遵循 compose 檔案的人都不會有理由執行這個命令。其次有價值的一點是驗證:導入完成後,它統計了雙方的表、問題、項目、日誌條目和附件的數量,檢查了每個附件文件是否都存在於磁碟上,列出了應用程式已註冊的插件版本,並確認沒有待處理的資料庫遷移。這是一份繁瑣的檢查清單,而繁瑣的檢查清單正是下午五點最容易被忽略的。.

它仍然需要人類對後果做出判斷。重啟 VDSM 用戶端來增加記憶體意味著關閉一個正在運行的網站,這是一個需要詢問而不是想當然的決定。刪除任何內容也是如此。把助手當作一雙不知疲倦、動作非常迅速且一絲不苟的手來檢查,而那些不可逆的操作則留給自己。.

哪裡可以找到更多官方資源

Virtual Machine Manager 軟體包承載所有 VDSM 用戶機,它已在 DSM 中存在多年,並且已有完善的文件支援。以下三個教學將介紹軟體包的安裝、建立客戶機以及您將要使用的介面概覽。.

Virtual Machine Manager套餐可接待Virtual DSM客人,帶您全面了解此套餐。.
從頭開始建立 DSM 虛擬機,包括許可證提示。.
雖然年代較早,但仍準確地介紹如何在 Virtual Machine Manager 內安裝 Virtual DSM。.

在將VDSM用於生產之前,您需要了解其限制。

首先,記憶體比 CPU 更容易成為瓶頸。我們的目標虛擬機只有 2GB 內存,在我們添加任何內容之前就已經使用了交換空間。第二個應用程式和第二個資料庫大約需要額外 480MB 內存,所以我們將其增加到 4GB。在規劃遷移之前,而不是之後,檢查目標虛擬機器的可用記憶體。.

其次,VDSM 虛擬磁碟只會成長而不會縮小。如果過度配置,您無法透過編輯欄位來回收空間;縮小磁碟的唯一方法是建立一個新的虛擬機器並將資料遷移到其中。選擇一個兩年後您仍然滿意的數值。.

Third, licensing. One guest is included with the NAS; every additional guest needs its own Virtual DSM licence. Clustering across several NAS units, live migration and the larger snapshot retention are VMM Pro features rather than standard ones. If your consolidation plan involves splitting one busy guest into four tidy ones, price that before you design it.

第四,應避免的幾種情況。不要將虛擬機器的虛擬磁碟放在與備份相同的實體磁碟區上,並稱之為備份。不要在與繁忙的檔案伺服器共用機械硬碟的虛擬機器上執行持續大量寫入的資料庫。不要將 VDSM 視為第二台機器的替代品,因為如果主機崩潰,其上的所有虛擬機器都會同時崩潰。此外,不要遷移從未檢查過的容器,原因已在上文「compose-file」部分中說明。.

Fifth, credentials. A migration touches database passwords, environment variables and configuration files. Ours moved a compose file holding plaintext database credentials, so it was placed deliberately outside the web server’s document root. A compose file left inside a document root is downloadable by anyone who guesses the filename, and that is a depressingly common way credentials leak. If you let an assistant script a migration, read where it is writing files. And when the job is done, disable the account you created for the assistant rather than leaving a live administrator login behind.

Sixth, snapshot before you touch anything. A VDSM snapshot in Virtual Machine Manager takes seconds, is available without the Pro licence, and turns almost every mistake in this article into a two-minute rollback. It is the one step worth adding to any migration runbook, whether a human or an assistant is doing the typing.

最後,務必進行驗證而非臆測。本文中的每一項論點都已在運行系統中進行了驗證:核對了雙方的表計數、檢查了磁碟上是否存在附件文件、確認了應用程式註冊的插件版本、檢查了是否存在待處理的遷移,並完整重啟了整個堆疊以驗證其能夠自行恢復。服務響應並不意味著遷移完成。只有當您證明遷移在 VDSM 虛擬機器重新啟動後仍然有效,且舊副本不再接受寫入作業時,遷移才算完成。.

A note on where to get those licences, since it is what we do: SynoPower Club sells Synology licences with round-the-clock instant key delivery. The two that matter here are the Virtual DSM licence, which you need for every guest past the free one, and the VMM Pro licence if you want clustering, live migration or 255 snapshots per guest instead of 32. The full licence catalogue covers Surveillance Station and MailPlus as well.

參考

經常問的問題

Synology VDSM 是免費的嗎?

所有支援 Virtual Machine Manager 的 NAS 設備都免費包含一個 Virtual DSM 許可證,足以永久運行一個虛擬機器。額外的虛擬機器需要付費許可證。 Virtual Machine Manager 軟體包本身可從套件中心免費下載。.

Synology VDSM 能否運作 Docker 容器?

是的。 Virtual DSM虛擬機器是一個完整的DSM系統,因此您可以像在實體NAS上一樣,透過套件中心安裝容器管理器。本文中的遷移操作是在兩個虛擬機器之間遷移一個包含兩個容器的堆疊,而無需對容器本身進行任何更改。.

Do I need to shut the guest down to enlarge a virtual disk?

No, and you do not need to reinstall anything either. Raise the size in the Storage tab of Virtual Machine Manager and the disk grows while the guest keeps running. DSM inside the guest expands the partition and filesystem on its own, so there is no Storage Manager wizard and no volume to rebuild. The only rule is that a virtual disk can grow but never shrink.

Synology VDSM 與在主機 NAS 上執行 Docker 相比有何不同?

直接在主機上運行容器更簡單,速度也略快,因為不需要虛擬化層。而虛擬機器則提供了隔離性:記憶體上限固定、獨立的分散式系統管理 (DSM) 需要重啟,以及可以進行快照或遷移的整個伺服器。主機用於必須始終正常運作的任務,而虛擬機器則用於可以進行故障排除的任務。.

Should I take a VDSM snapshot before migrating?

Yes, and it is free. Snapshots are included in the standard edition of Virtual Machine Manager, which keeps up to 32 per guest, and a snapshot captures the whole machine rather than one folder. Take one on the source and one on the destination before you start. This matters even more when an AI assistant is driving the shell: keep the source intact until the destination is verified, require confirmation before anything irreversible, and read what is about to run rather than approving on reflex.

如果容器內沒有捲,那麼安裝在容器內的檔案會發生什麼事?

它們只存在於容器的可寫層中,一旦容器從鏡像重新創建,它們就會立即消失。在遷移容器之前,請執行 `docker diff` 指令來查看容器的差異。如果差異很大,請將容器提交到鏡像中,然後遷移該鏡像,而不是從鏡像倉庫拉取一個新鏡像。.

像這樣的遷移需要多長時間?

對於一個小型堆疊,包括驗證在內,整個過程大約需要 35 分鐘。透過千兆區域網路傳輸一個 366 MB 的壓縮鏡像本身大約需要 1 分鐘。大部分時間都花在了檢查原始檔和確認結果上,這部分絕對不能操之過急。.

我可以將 Synology VDSM 虛擬機器在 NAS 設備之間遷移嗎?

是的。 Virtual Machine Manager 可以將虛擬機器遷移或複製到同一叢集中的另一個 NAS,這比遷移虛擬機器內部的容器要好得多,而且通常效果更佳。像我們在這裡所做的那樣移動容器,更適合將兩個虛擬機器合併為一個,而不是遷移整個虛擬機器。.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


評分
5.0
閱讀我們的評論