在云端自動化設(shè)置和交付虛擬機
- 通過使用 Testcloud 自動化設(shè)置過程并交付一個準備運行的虛擬機,在幾分鐘之內(nèi)準備好一個云鏡像。
如果你是一個在云端使用 Fedora qcow2 鏡像 的開發(fā)者或者愛好者,在一個鏡像準備使用之前,你總是不得不做一大堆初始化設(shè)置。我對此深有體會,所以我很想找到一種使設(shè)置過程更加簡單的方法。碰巧,整個 Fedora 質(zhì)量保證團隊也有同感,所以我們開發(fā)了 Testcloud 。
Testcloud 是一個可以輕松的在幾分鐘之內(nèi)準備云鏡像測試的工具。它用幾個命令就可以在云端自動化設(shè)置并交付準備運行的虛擬機(VM)。
Testcloud:
- 下載 qcow2 鏡像
- 用你選擇的名稱創(chuàng)建實例
- 創(chuàng)建一個密碼為 passw0rd,用戶名為 fedora 的用戶
- 分配一個 IP 地址,以便于你之后用 SSH 登錄到云端
- 啟動、停止、刪除和列出一個實例
安裝 Testcloud
要開始你的旅程,首先你必須安裝 Testcloud 軟件包。你可以通過終端或者“軟件”應(yīng)用來安裝它。在這兩種情況下,軟件包的名字都是 testcloud 。用以下命令安裝:
$ sudo dnf install testcloud -y
一旦安裝完成,將你所需要的用戶添加到 testcloud 用戶組,這有助于 Testcloud 自動完成設(shè)置過程的剩余部分。執(zhí)行這兩個命令,添加你的用戶到 testcloud 用戶組,并通過提升組權(quán)限重啟會話:
$ sudo usermod -a -G testcloud $USER
$ su - $USER
添加用戶到 testcloud 組
像老手一樣玩轉(zhuǎn)云鏡像
一旦你的用戶獲得了所需的組權(quán)限,創(chuàng)建一個實例:
$ testcloud instance create <instance name> -u <url for qcow2 image>
或者,你可以使用 fedora:latest/fedora:XX(XX 是你的 Fedora 發(fā)行版本)來代替 完整的 URL 地址:
$ testcloud instance create -u fedora:latest
這將返回你的虛擬機的 IP 地址:
$ testcloud instance create testcloud272593 -u https://download.fedoraproject.org/pub/fedora/linux/releases/33/Cloud/x86_64/images/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
[ ]
INFO:Successfully booted instance testcloud272593
The IP of vm testcloud272593: 192.168.122.202
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@192.168.122.202
你可以用默認用戶 fedora 登錄,密碼是 passw0rd(注意是零)。你可以使用 ssh、virt-manager 或者支持連接到 libvirt 虛擬機方式來連接到它。
另一種創(chuàng)建 Fedora 云的方式是:
$ testcloud instance create testcloud193 -u fedora:33
WARNING:Not proceeding with backingstore cleanup because there are some testcloud instances running.
You can fix this by following command(s):
testcloud instance stop testcloud272593
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
DEBUG:Creating instance directories
DEBUG:creating seed image /var/lib/testcloud/instances/testcloud193/testcloud193-seed.img
INFO:Seed image generated successfully
INFO:Successfully booted instance testcloud193
The IP of vm testcloud193: 192.168.122.225
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@192.168.122.225
------------------------------------------------------------
玩轉(zhuǎn)實例
Testcloud 可以用來管理實例。這包括像列出鏡像或者停止和啟動一個實例等活動。
要列出實例,使用 list 子命令:
$ testcloud instance list
Name IP State
------------------------------------------------------------
testcloud272593 192.168.122.202 running
testcloud193 192.168.122.225 running
testcloud252793 192.168.122.146 shutoff
testcloud93 192.168.122.152 shutoff
要停止一個運行的實例:
$ testcloud instance stop testcloud193
DEBUG:stop instance: testcloud193
DEBUG:stopping instance testcloud193.
要刪除一個實例:
$ testcloud instance destroy testcloud193
DEBUG:remove instance: testcloud193
DEBUG:removing instance testcloud193 from libvirt.
DEBUG:Unregistering instance from libvirt.
DEBUG:removing instance /var/lib/testcloud/instances/testcloud193 from disk
要重啟一個運行中的實例:
$ testcloud instance reboot testcloud93
DEBUG:stop instance: testcloud93
[ ]
INFO:Successfully booted instance testcloud93
The IP of vm testcloud93: 192.168.122.152
usage: testcloud [-h] {instance,image}